backend/buisnesslogic/src/main/java/com/plannaplan/services/UserService.java

40 lines
1.0 KiB
Java
Raw Normal View History

2020-07-25 10:38:19 +02:00
package com.plannaplan.services;
import java.util.UUID;
2020-07-27 16:44:04 +02:00
import com.plannaplan.abstracts.EventWatcher;
import com.plannaplan.entities.User;
import com.plannaplan.exceptions.UserNotFoundException;
2020-07-25 10:38:19 +02:00
import com.plannaplan.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
2020-07-27 16:44:04 +02:00
public class UserService extends EventWatcher {
2020-07-25 10:38:19 +02:00
@Autowired
2020-07-25 10:56:11 +02:00
private UserRepository repo;
2020-07-25 10:38:19 +02:00
2020-07-27 16:44:04 +02:00
public UserService() {
super();
2020-07-25 10:38:19 +02:00
}
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);
}
2020-07-25 10:38:19 +02:00
}