cleaned the login process
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class AuthenticatorService {
|
||||
|
||||
private final TokenService tokenService;
|
||||
private final UserService userService;
|
||||
|
||||
public AuthenticatorService(TokenService tokenService, UserService userService){
|
||||
this.tokenService = tokenService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public User getUserFromToken(String token){
|
||||
return tokenService.getUserFromToken(token);
|
||||
}
|
||||
|
||||
|
||||
public String login(String identifier, String password, Date expirationDate){
|
||||
User user = userService.getUser(identifier);
|
||||
if (user == null){return null;}
|
||||
if (!userService.checkPassword(user,password)){return null;}
|
||||
String token = tokenService.generateNewToken();
|
||||
tokenService.saveToken(token,user,expirationDate);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user