From 2d887c86a97f69b0316bd984f97eb8c70ecc2b38 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 1 Jul 2019 15:36:51 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=90=D0=B2=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B2=D1=85=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/provider/HibernateAuthProvider.java | 5 +++++ .../java/pro/gravit/launchserver/dao/UserService.java | 9 +++++++++ 2 files changed, 14 insertions(+) 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); }