diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index b737f79e..4f878b27 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -7,9 +7,14 @@ import pro.gravit.utils.helper.SecurityHelper; public class HibernateAuthProvider extends AuthProvider { + public boolean autoReg; @Override public AuthProviderResult auth(String login, String password, String ip) throws Exception { User user = srv.config.dao.userService.findUserByUsername(login); + if(user == null && autoReg) + { + user = srv.config.dao.userService.registerNewUser(login, password); + } if(user == null || !user.verifyPassword(password)) { if(user ==null) throw new AuthException("Username incorrect"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java index d2cef2a9..3379ecd2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java @@ -24,6 +24,15 @@ public User findUserByUUID(UUID uuid) { return usersDao.findByUUID(uuid); } + public User registerNewUser(String username, String password) + { + User user = new User(); + user.username = username; + user.setPassword(password); + user.uuid = UUID.randomUUID(); + return user; + } + public void saveUser(User user) { usersDao.save(user); }