Changeset d7f5da9 for src/main/java/com
- Timestamp:
- 02/07/23 13:48:25 (23 months ago)
- Branches:
- master
- Children:
- fc448f5
- Parents:
- f7b0906
- Location:
- src/main/java/com/example/moviezone
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/model/Customer.java
rf7b0906 rd7f5da9 34 34 35 35 @Override 36 public boolean equals(Object o) { 37 if (this == o) return true; 38 if (o == null || getClass() != o.getClass()) return false; 39 Customer customer = (Customer) o; 40 return id_user!=null && Objects.equals(id_user,customer.id_user); 41 } 42 43 @Override 44 public int hashCode() { 45 return Objects.hash(); 46 } 47 48 @Override 36 49 public Collection<? extends GrantedAuthority> getAuthorities() { 37 50 return Collections.singletonList(Role.ROLE_USER); -
src/main/java/com/example/moviezone/model/Worker.java
rf7b0906 rd7f5da9 10 10 import java.util.Collection; 11 11 import java.util.Collections; 12 import java.util.Objects; 12 13 13 14 @Entity … … 32 33 } 33 34 35 @Override 36 public boolean equals(Object o) { 37 if (this == o) return true; 38 if (o == null || getClass() != o.getClass()) return false; 39 Worker worker = (Worker) o; 40 return id_user!=null && Objects.equals(id_user, worker.id_user); 41 } 42 43 @Override 44 public int hashCode() { 45 return Objects.hash(); 46 } 47 34 48 public Worker() { 35 49 -
src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java
rf7b0906 rd7f5da9 48 48 49 49 @Override 50 public User register(String first_name, String last_name, String username, String email, String number, String password,String repeatedPassword, Role role) {51 if(!password.equals(repeatedPassword))52 throw new PasswordsDoNotMatchException();53 if (username==null || username.isEmpty() || password==null || password.isEmpty())54 throw new InvalidUsernameOrPasswordException();50 public void register(String first_name, String last_name, String username, String email, String number, String password, Role role) { 51 // if(!password.equals(repeatedPassword)) 52 // throw new PasswordsDoNotMatchException(); 53 // if (username==null || username.isEmpty() || password==null || password.isEmpty()) 54 // throw new InvalidUsernameOrPasswordException(); 55 55 56 56 if(role.equals(Role.ROLE_ADMIN)) 57 57 { 58 User user= new User(passwordEncoder.encode(password),first_name,last_name,username,email,number);59 workerRepository.save((Worker) user);60 return userRepository.save(user);58 // User user= new User(passwordEncoder.encode(password),first_name,last_name,username,email,number); 59 // workerRepository.save((Worker) user); 60 userRepository.save(new Worker(password,first_name,last_name,email,number,username)); 61 61 } 62 62 else 63 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);64 // Customer customer=new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number); 65 // customerRepository.save(customer); 66 userRepository.save(new Customer(password,first_name,last_name,email,number,username)); 67 67 68 68 } -
src/main/java/com/example/moviezone/service/UserService.java
rf7b0906 rd7f5da9 11 11 User findByUsername(String username); 12 12 13 User register(String first_name, String last_name,String username, String email, String number, String password,String repeatedPassword, Role role);13 void register(String first_name, String last_name,String username, String email, String number, String password, Role role); 14 14 User login(String username,String password); 15 15 } -
src/main/java/com/example/moviezone/web/HomeController.java
rf7b0906 rd7f5da9 77 77 78 78 @PostMapping("/login") 79 public String login(@RequestParam String username,@RequestParam String password,Model model, HttpSession session) 80 { 81 User user = null; 82 try { 83 user=userService.login(username,password); 84 session.setAttribute("sessionUser",user); 85 model.addAttribute("user",user); 79 public String login(@RequestParam String username, 80 @RequestParam String password,Model model, HttpSession session) 81 { 82 // User user = null; 83 // try { 84 User user=userService.login(username,password); 85 System.out.println(user.getFirst_name()); 86 // session.setAttribute("sessionUser",user); 87 // model.addAttribute("user",user); 86 88 return "redirect:/home"; 87 88 }catch (UserNotFoundException e)89 {90 model.addAttribute("hasError", true);91 model.addAttribute("error", e.getMessage());92 return "login";93 }89 // 90 // }catch (UserNotFoundException e) 91 // { 92 // model.addAttribute("hasError", true); 93 // model.addAttribute("error", e.getMessage()); 94 // return "login"; 95 // } 94 96 95 97 } … … 106 108 { 107 109 try { 108 User user=userService.register(first_name,last_name,username,email,number,password,repeatedPassword,role);110 userService.register(first_name,last_name,username,email,number,password,role); 109 111 return "redirect:/login"; 110 112 }catch (PasswordsDoNotMatchException exception)
Note:
See TracChangeset
for help on using the changeset viewer.