source: src/main/java/mk/ukim/finki/busngo/web/RegisterController.java@ bde8b13

Last change on this file since bde8b13 was bde8b13, checked in by ppaunovski <paunovskipavel@…>, 6 months ago

All 3 main use cases implemented.

  1. Starting a commute
  2. Writing a ticket
  3. Starting an instance of a Bus Line
  • Property mode set to 100644
File size: 2.7 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Korisnik;
4import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
5import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
6import mk.ukim.finki.busngo.service.AuthService;
7import mk.ukim.finki.busngo.service.KorisnikService;
8import mk.ukim.finki.busngo.service.PatnikService;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PostMapping;
13import org.springframework.web.bind.annotation.RequestMapping;
14import org.springframework.web.bind.annotation.RequestParam;
15
16@Controller
17@RequestMapping("/register")
18public class RegisterController {
19 private final AuthService authService;
20 private final KorisnikService korisnikService;
21 private final PatnikService patnikService;
22
23 public RegisterController(AuthService authService, KorisnikService korisnikService, PatnikService patnikService) {
24 this.authService = authService;
25 this.korisnikService = korisnikService;
26 this.patnikService = patnikService;
27 }
28
29 @GetMapping
30 public String getRegisterPage(@RequestParam(required = false) String error, Model model) {
31 if(error != null && !error.isEmpty()) {
32 model.addAttribute("hasError", true);
33 model.addAttribute("error", error);
34 }
35
36 model.addAttribute("bodyContent", "register");
37 return "master-template";
38 }
39
40 @PostMapping
41 public String register(@RequestParam String name,
42 @RequestParam String email,
43 @RequestParam String password,
44 @RequestParam String confirmPassword,
45 @RequestParam String address,
46 @RequestParam String phone
47 ) {
48 try{
49 Korisnik korisnik = this.authService.registerPatnik(name, email, password, confirmPassword, address, phone);
50 this.patnikService.save(korisnik);
51 return "redirect:/login";
52 } catch (InvalidCredentialsException | UserAlreadyExistsException exception) {
53 return "redirect:/register?error=" + exception.getMessage();
54 }
55 }
56
57// @PostMapping
58// public String registerVraboten(@RequestParam String name,
59// @RequestParam String email,
60// @RequestParam String password,
61// @RequestParam String confirmPassword,
62// @RequestParam String address,
63// @RequestParam String phone){
64//
65// }
66
67}
Note: See TracBrowser for help on using the repository browser.