User service added login and returning token
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.plannaplan.abstracts.EventWatcher;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.repositories.UserRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -15,4 +19,22 @@ public class UserService extends EventWatcher {
|
||||
super();
|
||||
}
|
||||
|
||||
public String login(String authority) throws UserNotFoundException {
|
||||
User user = this.repo.getByAuthority(authority);
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException("Can not find user with given authority");
|
||||
}
|
||||
String token = UUID.randomUUID().toString();
|
||||
user.setToken(token);
|
||||
return token;
|
||||
}
|
||||
|
||||
public void save(User user) {
|
||||
this.repo.save(user);
|
||||
}
|
||||
|
||||
public User getUserByEmail(String email) {
|
||||
return this.repo.getByAuthority(email);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user