move add permissions code

This commit is contained in:
muhammadeko 2022-05-14 16:25:07 +07:00
parent 279c50393e
commit 0fc6ed259a
No known key found for this signature in database
GPG Key ID: 51366716C10E98B1

View File

@ -18,7 +18,7 @@ public class RegisterHandler implements HttpContextHandler {
@Override
public void handle(Request request, Response response) throws IOException {
AuthResponseJson authResponse = new AuthResponseJson();
Account account = null;
try {
String requestBody = request.ctx().body();
if (requestBody.isEmpty()) {
@ -36,7 +36,7 @@ public class RegisterHandler implements HttpContextHandler {
if (registerAccount.password.length() >= 8) {
String password = Authentication.generateHash(registerAccount.password);
try{
Account account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, "");
account = Authentication.getAccountByUsernameAndPassword(registerAccount.username, "");
if (account != null) {
account.setPassword(password);
account.save();
@ -79,7 +79,13 @@ public class RegisterHandler implements HttpContextHandler {
Grasscutter.getLogger().error("[Dispatch] An error occurred while creating an account.");
e.printStackTrace();
}
if (authResponse.success) {
if (GCAuth.getConfigStatic().defaultPermissions.length > 0) {
for (String permission : GCAuth.getConfigStatic().defaultPermissions) {
account.addPermission(permission);
}
}
}
response.send(authResponse);
}
}