1 | package finki.paw5.service.implementation;
|
---|
2 |
|
---|
3 | import finki.paw5.model.entities.User;
|
---|
4 | import finki.paw5.model.exceptions.NonExistingArgumentsException;
|
---|
5 | import finki.paw5.repository.UserRepository;
|
---|
6 | import finki.paw5.service.AuthService;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.time.LocalDate;
|
---|
10 | import java.util.Objects;
|
---|
11 | import java.util.Optional;
|
---|
12 |
|
---|
13 | @Service
|
---|
14 | public class AuthServiceImpl implements AuthService {
|
---|
15 |
|
---|
16 | private final UserRepository userRepository;
|
---|
17 |
|
---|
18 | public AuthServiceImpl(UserRepository userRepository) {
|
---|
19 | this.userRepository = userRepository;
|
---|
20 | }
|
---|
21 |
|
---|
22 | @Override
|
---|
23 | public User login(String email, String password) {
|
---|
24 |
|
---|
25 | if(userRepository.findByEmailAndPassword(email, password)!=null){
|
---|
26 | return userRepository.findByEmailAndPassword(email,password);
|
---|
27 | }
|
---|
28 | return null;
|
---|
29 | }
|
---|
30 |
|
---|
31 | /*
|
---|
32 | @Override
|
---|
33 | public Adopter registerAdopter(String password, String repeatPassword, String name, String email, String telephone) {
|
---|
34 | if (email == null || email.isEmpty() || password == null || password.isEmpty()) {
|
---|
35 | //throw new Exception();
|
---|
36 | }
|
---|
37 | if (!password.equals(repeatPassword)) {
|
---|
38 | //throw new Exception();
|
---|
39 | }
|
---|
40 | if (this.userRepository.findByEmail(email)!=null) {
|
---|
41 | //throw new Exception("Username exists:"+email);
|
---|
42 | }
|
---|
43 | User user = new User(LocalDate.now(), name, email, password, telephone);
|
---|
44 | return userRepository.save(user);
|
---|
45 | }
|
---|
46 | */
|
---|
47 | }
|
---|