- Timestamp:
- 02/04/23 19:28:58 (22 months ago)
- Branches:
- master
- Children:
- a554435
- Parents:
- 6032d44
- Location:
- src/main/java/com/example/moviezone
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java
r6032d44 re097c1c 4 4 import com.example.moviezone.model.User; 5 5 import com.example.moviezone.model.Worker; 6 import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException; 6 7 import com.example.moviezone.model.exceptions.UserNotFoundException; 7 8 import com.example.moviezone.repository.UserRepository; … … 39 40 40 41 @Override 41 public User register(String first_name, String last_name, String username, String email, String number, String password, String role) { 42 public User register(String first_name, String last_name, String username, String email, String number, String password,String repeatedPassword, String role) { 43 if(!password.equals(repeatedPassword)) 44 throw new PasswordsDoNotMatchException(); 45 else 42 46 if(role.equals("worker")) 43 47 { -
src/main/java/com/example/moviezone/service/UserService.java
r6032d44 re097c1c 10 10 User findByUsername(String username); 11 11 12 User register(String first_name, String last_name,String username, String email, String number, String password, String role);12 User register(String first_name, String last_name,String username, String email, String number, String password,String repeatedPassword, String role); 13 13 User login(String username,String password); 14 14 } -
src/main/java/com/example/moviezone/web/HomeController.java
r6032d44 re097c1c 2 2 3 3 4 import com.example.moviezone.model.User; 5 import com.example.moviezone.model.exceptions.UserNotFoundException; 4 6 import com.example.moviezone.service.FilmService; 7 import com.example.moviezone.service.UserService; 5 8 import org.springframework.stereotype.Controller; 6 9 import org.springframework.ui.Model; 7 10 import org.springframework.web.bind.annotation.GetMapping; 11 import org.springframework.web.bind.annotation.PostMapping; 8 12 import org.springframework.web.bind.annotation.RequestMapping; 13 import org.springframework.web.bind.annotation.RequestParam; 14 15 import javax.servlet.http.HttpSession; 9 16 10 17 @Controller … … 13 20 14 21 private final FilmService filmService; 22 private final UserService userService; 15 23 16 public HomeController(FilmService filmService ) {24 public HomeController(FilmService filmService, UserService userService) { 17 25 this.filmService = filmService; 26 this.userService = userService; 18 27 } 19 28 … … 24 33 } 25 34 26 35 @GetMapping("/login") 36 public String getLoginPage(Model model) 37 { 38 model.addAttribute("bodyContent", "login"); 39 return "master-template"; 40 } 41 42 @GetMapping("/register") 43 public String getRegisterPage(Model model) 44 { 45 model.addAttribute("bodyContent", "register"); 46 return "master-template"; 47 } 48 49 @PostMapping("/login") 50 public String login(@RequestParam String username,@RequestParam String password,Model model, HttpSession session) 51 { 52 User user = null; 53 try { 54 user=userService.login(username,password); 55 session.setAttribute("sessionUser",user); 56 model.addAttribute("user",user); 57 return "redirect:/home"; 58 59 }catch (UserNotFoundException e) 60 { 61 model.addAttribute("hasError", true); 62 model.addAttribute("error", e.getMessage()); 63 return "login"; 64 } 65 66 } 67 68 @PostMapping("register") 69 public String register(@RequestParam String username, @RequestParam String first_name, @RequestParam String last_name, 70 @RequestParam String password, @RequestParam String repeatedPassword, 71 @RequestParam String email, @RequestParam String number, 72 @RequestParam String role) 73 { 74 User user = null; 75 user=userService.register(first_name,last_name,username,email,number,password,repeatedPassword,role); 76 return "redirect:/login"; 77 } 27 78 28 79 }
Note:
See TracChangeset
for help on using the changeset viewer.