Endpoint returnung token if valid data
This commit is contained in:
@ -20,12 +20,13 @@ public class UserService extends EventWatcher {
|
||||
}
|
||||
|
||||
public String login(String authority) throws UserNotFoundException {
|
||||
User user = this.repo.getByAuthority(authority);
|
||||
User user = this.repo.getByAuthority(authority.replace("\n", "").trim());
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException("Can not find user with given authority");
|
||||
}
|
||||
String token = UUID.randomUUID().toString();
|
||||
user.setToken(token);
|
||||
this.repo.save(user);
|
||||
return token;
|
||||
}
|
||||
|
||||
@ -34,7 +35,7 @@ public class UserService extends EventWatcher {
|
||||
}
|
||||
|
||||
public User getUserByEmail(String email) {
|
||||
return this.repo.getByAuthority(email);
|
||||
return this.repo.getByAuthority(email.replace("\n", "").trim());
|
||||
}
|
||||
|
||||
}
|
@ -45,6 +45,7 @@ public class UserServiceTest {
|
||||
String token = this.userService.login(TEST_USER_MAIL);
|
||||
System.out.println("Returned token: " + token);
|
||||
assertTrue(token != null);
|
||||
assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null);
|
||||
} catch (UserNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
assertTrue(false);
|
||||
|
Reference in New Issue
Block a user