- Timestamp:
- 02/06/23 17:05:56 (22 months ago)
- Branches:
- master
- Children:
- a69d48c
- Parents:
- 43a1688
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java
r43a1688 rf9cc555 2 2 3 3 import com.example.moviezone.model.Customer; 4 import com.example.moviezone.model.Role; 4 5 import com.example.moviezone.model.User; 5 6 import com.example.moviezone.model.Worker; 7 import com.example.moviezone.model.exceptions.InvalidUsernameOrPasswordException; 6 8 import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException; 7 9 import com.example.moviezone.model.exceptions.UserNotFoundException; 10 import com.example.moviezone.repository.CustomerRepository; 8 11 import com.example.moviezone.repository.UserRepository; 12 import com.example.moviezone.repository.WorkerRepository; 9 13 import com.example.moviezone.service.UserService; 10 14 import org.springframework.security.crypto.password.PasswordEncoder; … … 18 22 private final UserRepository userRepository; 19 23 private final PasswordEncoder passwordEncoder; 24 private final WorkerRepository workerRepository; 25 private final CustomerRepository customerRepository; 20 26 21 public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder ) {27 public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder, WorkerRepository workerRepository, CustomerRepository customerRepository) { 22 28 this.userRepository = userRepository; 23 29 this.passwordEncoder = passwordEncoder; 30 this.workerRepository = workerRepository; 31 this.customerRepository = customerRepository; 24 32 } 25 33 … … 40 48 41 49 @Override 42 public User register(String first_name, String last_name, String username, String email, String number, String password,String repeatedPassword, Stringrole) {50 public User register(String first_name, String last_name, String username, String email, String number, String password,String repeatedPassword, Role role) { 43 51 if(!password.equals(repeatedPassword)) 44 52 throw new PasswordsDoNotMatchException(); 45 else 46 if(role.equals("worker")) 53 if (username==null || username.isEmpty() || password==null || password.isEmpty()) 54 throw new InvalidUsernameOrPasswordException(); 55 56 if(role.equals(Role.ROLE_ADMIN)) 47 57 { 48 return userRepository.save(new Worker(passwordEncoder.encode(password),first_name,last_name,username,email,number)); 58 Worker worker=new Worker(passwordEncoder.encode(password),first_name,last_name,username,email,number); 59 workerRepository.save(worker); 60 return userRepository.save(worker); 49 61 } 50 62 else 51 return userRepository.save(new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number)); 63 { 64 Customer customer=new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number); 65 customerRepository.save(customer); 66 return userRepository.save(customer); 67 68 } 69 52 70 } 53 71
Note:
See TracChangeset
for help on using the changeset viewer.