- Timestamp:
- 02/06/23 17:05:56 (22 months ago)
- Branches:
- master
- Children:
- a69d48c
- Parents:
- 43a1688
- Location:
- src/main
- Files:
-
- 1 added
- 5 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 -
src/main/java/com/example/moviezone/service/UserService.java
r43a1688 rf9cc555 1 1 package com.example.moviezone.service; 2 2 3 import com.example.moviezone.model.Role; 3 4 import com.example.moviezone.model.User; 4 5 … … 10 11 User findByUsername(String username); 11 12 12 User register(String first_name, String last_name,String username, String email, String number, String password,String repeatedPassword, Stringrole);13 User register(String first_name, String last_name,String username, String email, String number, String password,String repeatedPassword, Role role); 13 14 User login(String username,String password); 14 15 } -
src/main/java/com/example/moviezone/web/HomeController.java
r43a1688 rf9cc555 4 4 import com.example.moviezone.model.Customer; 5 5 import com.example.moviezone.model.Film; 6 import com.example.moviezone.model.Role; 6 7 import com.example.moviezone.model.User; 8 import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException; 7 9 import com.example.moviezone.model.exceptions.UserNotFoundException; 8 10 import com.example.moviezone.service.*; … … 93 95 } 94 96 95 @PostMapping("register") 96 public String register(@RequestParam String username, @RequestParam String first_name, @RequestParam String last_name, 97 @RequestParam String password, @RequestParam String repeatedPassword, 98 @RequestParam String email, @RequestParam String number, 99 @RequestParam String role) 100 { 101 User user = null; 102 user=userService.register(first_name,last_name,username,email,number,password,repeatedPassword,role); 97 @PostMapping() 98 public String register(@RequestParam String username, 99 @RequestParam String first_name, 100 @RequestParam String last_name, 101 @RequestParam String password, 102 @RequestParam String repeatedPassword, 103 @RequestParam String email, 104 @RequestParam String number, 105 @RequestParam Role role) 106 { 107 try { 108 User user=userService.register(first_name,last_name,username,email,number,password,repeatedPassword,role); 103 109 return "redirect:/login"; 110 }catch (PasswordsDoNotMatchException exception) 111 { 112 return "redirect:/register?error=" + exception.getMessage(); 113 } 114 104 115 } 105 116 -
src/main/resources/templates/fragments/header.html
r43a1688 rf9cc555 68 68 </ul> 69 69 <ul class="menu-right"> 70 <li class="reg"><a href=" #!">Најава</a></li>71 <li class="reg"><a href=" #!">Регистрација</a></li>70 <li class="reg"><a href="/login">Најава</a></li> 71 <li class="reg"><a href="/register">Регистрација</a></li> 72 72 </ul> 73 73 </nav></div> -
src/main/resources/templates/register.html
r43a1688 rf9cc555 30 30 </p> 31 31 <p> 32 <label for="number" class="sr-only">Phone Number</label> 33 <input type="text" id="number" name="number" class="form-control" placeholder="Enter Number" required="" 34 autofocus=""> 35 </p> 36 <p> 32 37 <div class="form-check form-check-inline"> 33 38 <input class="form-check-input" name="role" type="radio" id="ROLE_ADMIN" value="ROLE_ADMIN">
Note:
See TracChangeset
for help on using the changeset viewer.