source: src/main/java/project/fmo/app/projcetfmo/Web/RegisterController.java

main
Last change on this file was d14176d, checked in by HristijanMitic00 <hristijan.mitic.01@…>, 12 months ago

First commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package project.fmo.app.projcetfmo.Web;
2
3import org.springframework.stereotype.Controller;
4import org.springframework.ui.Model;
5import org.springframework.web.bind.annotation.GetMapping;
6import org.springframework.web.bind.annotation.PostMapping;
7import org.springframework.web.bind.annotation.RequestMapping;
8import org.springframework.web.bind.annotation.RequestParam;
9import project.fmo.app.projcetfmo.Service.KorisnikService;
10
11@Controller
12@RequestMapping("/register")
13public 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
50}
Note: See TracBrowser for help on using the repository browser.