Changed token response in controller
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user