Changed token response in controller

This commit is contained in:
Filip Izydorczyk
2020-12-07 21:46:47 +01:00
parent 3061fb1edf
commit f9baed5df7
7 changed files with 52 additions and 52 deletions

View File

@ -13,7 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of UserService which can get(By Email), login, save user.
* Service of UserService which can get(By Email), login, save user.
*/
@Service
public class UserService {
@ -26,37 +26,33 @@ public class UserService {
public User checkForUser(String email, String usosId) {
if (usosId == null) {
Optional <User> user = this.repo.getByAuthority(email.replace("\n", "").trim());
if (user.isPresent()){
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);
} else {
final User newUser = new User(null, null, email.replace("\n", "").trim(), UserRoles.STUDENT);
return this.repo.save(newUser);
}
}
else {
Optional <User> user = this.repo.getByUsosId(usosId.replace("\n", "").trim());
if (user.isPresent()){
} 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);
} else {
final User newUser = new User(null, null, email.replace("\n", "").trim(), usosId, UserRoles.STUDENT);
return this.repo.save(newUser);
}
}
}
public String login(User authority) throws UserNotFoundException {
public User login(User authority) throws UserNotFoundException {
final String token = UUID.randomUUID().toString();
try{
try {
authority.setToken(token);
this.repo.save(authority);
}
catch (Exception e){
} catch (Exception e) {
throw new UserNotFoundException(e.getMessage());
}
return token;
return authority;
}
public User save(User user) {