@ -24,6 +24,31 @@ public class UserService {
|
||||
super();
|
||||
}
|
||||
|
||||
public User checkForUser(String email, String usosId) {
|
||||
if (usosId == null) {
|
||||
Optional <User> user = this.repo.getByAuthority(email.replace("\n", "").trim());
|
||||
if (user.isPresent()){
|
||||
return user.get();
|
||||
}
|
||||
else {
|
||||
final User newUser = new User(null,null,email.replace("\n", "").trim(),UserRoles.STUDENT);
|
||||
this.repo.save(newUser);
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Optional <User> user = this.repo.getByUsosId(usosId.replace("\n", "").trim());
|
||||
if (user.isPresent()){
|
||||
return user.get();
|
||||
}
|
||||
else {
|
||||
final User newUser = new User(null,null,email.replace("\n", "").trim(),usosId,UserRoles.STUDENT);
|
||||
this.repo.save(newUser);
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String login(String authority) throws UserNotFoundException {
|
||||
User user = this.repo.getByAuthority(authority.replace("\n", "").trim())
|
||||
.orElseThrow(() -> new UserNotFoundException("Can not find user with given authority"));
|
||||
|
Reference in New Issue
Block a user