Fix the existing users can't register

This commit is contained in:
xtaodada 2022-05-04 14:41:25 +08:00
parent a2a9765bca
commit 061f70c376
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -30,15 +30,25 @@ public class RegisterHandler implements HttpContextHandler {
if (registerAccount.password.equals(registerAccount.password_confirmation)) {
if (registerAccount.password.length() >= 8) {
String password = Authentication.generateHash(registerAccount.password);
Account account = DatabaseHelper.createAccountWithPassword(registerAccount.username, password);
if (account == null) {
authResponse.success = false;
authResponse.message = "USERNAME_TAKEN"; // ENG = "Username has already been taken by another user."
authResponse.jwt = "";
} else {
Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, "");
if (account != null) {
String newPassword = Authentication.generateHash(password);
account.setPassword(newPassword);
account.save();
authResponse.success = true;
authResponse.message = "";
authResponse.jwt = "";
} else {
account = DatabaseHelper.createAccountWithPassword(registerAccount.username, password);
if (account == null) {
authResponse.success = false;
authResponse.message = "USERNAME_TAKEN"; // ENG = "Username has already been taken by another user."
authResponse.jwt = "";
} else {
authResponse.success = true;
authResponse.message = "";
authResponse.jwt = "";
}
}
} else {
authResponse.success = false;