Merge pull request #14 from exzork/development

default permissions
This commit is contained in:
Muhammad Eko Prasetyo 2022-05-14 16:25:26 +07:00 committed by GitHub
commit 9be7df18d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -10,7 +10,7 @@ sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
group 'me.exzork.gcauth' group 'me.exzork.gcauth'
version '2.1.5' version '2.1.6'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -5,5 +5,6 @@ import me.exzork.gcauth.utils.Authentication;
public final class Config { public final class Config {
public String Hash = "BCRYPT"; public String Hash = "BCRYPT";
public String jwtSecret = Authentication.generateRandomString(32); public String jwtSecret = Authentication.generateRandomString(32);
public String[] defaultPermissions = new String[]{""};
public String ACCESS_KEY = ""; public String ACCESS_KEY = "";
} }

View File

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