source: src/main/java/com/example/villadihovo/service/impl/loginImpl/AuthServiceImpl.java

Last change on this file was f7c05a1, checked in by Elena Shulevska <elena.shulevska@…>, 15 months ago

initial commit of the source code on origin

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package com.example.villadihovo.service.impl.loginImpl;
2
3import com.example.villadihovo.exceptions.InvalidArgumentException;
4import com.example.villadihovo.exceptions.InvalidUserCredentialsException;
5import com.example.villadihovo.exceptions.PasswordDoNotMatchException;
6import com.example.villadihovo.model.users.UserTable;
7import com.example.villadihovo.repository.users.UserRepository;
8import com.example.villadihovo.service.login.AuthService;
9import org.springframework.beans.factory.annotation.Autowired;
10import org.springframework.stereotype.Service;
11
12@Service
13public class AuthServiceImpl implements AuthService {
14
15 @Autowired
16 private UserRepository userTableRepository;
17
18 @Override
19 public UserTable login(String username, String password) {
20 if(username == null || username.isEmpty() || password == null || password.isEmpty())
21 {
22 return userTableRepository.findByUsernameAndPassword(username, password).orElseThrow(InvalidArgumentException::new);
23 } else {
24 return userTableRepository.findByUsernameAndPassword(username, password).orElseThrow(InvalidUserCredentialsException::new);
25 }
26 }
27
28
29 @Override
30 public UserTable register(String embg, String address, String email, String username, String password, String repeatPassword, String full_name, String phone_number) {
31 if(username == null || username.isEmpty() || password == null || password.isEmpty())
32 {
33 throw new InvalidArgumentException();
34 }
35 if(!password.equals(repeatPassword))
36 {
37 throw new PasswordDoNotMatchException();
38 }
39 UserTable userTable = new UserTable(embg, address, email, password, username, full_name, phone_number);
40 return userTableRepository.save(userTable);
41 }
42}
Note: See TracBrowser for help on using the repository browser.