* Create an account for a player.
*/
public AccountResult createAccount(String username, String password, String email) {
// check a minimum length for username and password.
if ((username.length() < 4) || (password.length() < 4)) {
return new AccountResult(Result.FAILED_STRING_SIZE, username);
}
DBTransaction transaction = transactionPool.beginWork();
try {
if (DAORegister.get().get(AccountDAO.class).hasPlayer(transaction, username)) {
logger.warn("Account already exist: " + username);
transactionPool.commit(transaction);
return new AccountResult(Result.FAILED_PLAYER_EXISTS, username);
}
DAORegister.get().get(AccountDAO.class).addPlayer(transaction, username, Hash.hash(password), email);
transactionPool.commit(transaction);
return new AccountResult(Result.OK_CREATED, username);
} catch (SQLException e) {
transactionPool.rollback(transaction);
return new AccountResult(Result.FAILED_EXCEPTION, username);
}
}