Endpoint returnung token if valid data

This commit is contained in:
Filip Izydorczyk
2020-09-14 12:55:47 +02:00
parent 11f3625684
commit 478ea27480
4 changed files with 29 additions and 20 deletions

View File

@ -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());
}
}

View File

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