CAS Part 1

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2020-12-03 16:23:39 +01:00
parent b6c2e43975
commit 3ebfda5316
5 changed files with 56 additions and 9 deletions

View File

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