Legend:
- Unmodified
- Added
- Removed
-
src/main/java/project/fmo/app/projcetfmo/Web/RegisterController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class RegisterController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.GetMapping; 6 import org.springframework.web.bind.annotation.PostMapping; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RequestParam; 9 import project.fmo.app.projcetfmo.Service.KorisnikService; 10 11 @Controller 12 @RequestMapping("/register") 13 public class RegisterController { 14 15 private final KorisnikService korisnikService; 16 17 18 public RegisterController(KorisnikService korisnikService) { 19 this.korisnikService = korisnikService; 20 } 21 22 23 @GetMapping 24 public String getRegisterPage(@RequestParam(required = false) String error, Model model) { 25 if(error != null && !error.isEmpty()) { 26 model.addAttribute("hasError", true); 27 model.addAttribute("error", error); 28 } 29 model.addAttribute("bodyContent","register"); 30 return "master_template"; 31 } 32 33 @PostMapping 34 public String register(@RequestParam String name_surname, 35 @RequestParam String password, 36 @RequestParam String repeatedPassword, 37 @RequestParam String mail, 38 @RequestParam String number) { 39 try{ 40 if(korisnikService.findbyImePrezime(name_surname) != null) throw new RuntimeException(); 41 this.korisnikService.register(name_surname, password, repeatedPassword, mail, number); 42 return "redirect:/home"; 43 } catch (RuntimeException r) { 44 return "redirect:/register?error=InvalidRegistration"; 45 } 46 } 47 48 49 2 50 }
Note:
See TracChangeset
for help on using the changeset viewer.