[FEATURE] Автоматическая регистрация при первом входе

This commit is contained in:
Gravit 2019-07-01 15:36:51 +07:00
parent 4bb5993ef0
commit 2d887c86a9
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 14 additions and 0 deletions

View file

@ -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");

View file

@ -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);
}