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

Last change on this file since e272096 was e272096, checked in by ppaunovski <paunovskipavel@…>, 4 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: 3.2 KB
Line 
1package mk.ukim.finki.busngo.web;
2
3import mk.ukim.finki.busngo.model.entities.Korisnik;
4import mk.ukim.finki.busngo.model.enums.VrabotenType;
5import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
6import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
7import mk.ukim.finki.busngo.service.AuthService;
8import mk.ukim.finki.busngo.service.KorisnikService;
9import mk.ukim.finki.busngo.service.PatnikService;
10import org.springframework.stereotype.Controller;
11import org.springframework.ui.Model;
12import org.springframework.web.bind.annotation.GetMapping;
13import org.springframework.web.bind.annotation.PostMapping;
14import org.springframework.web.bind.annotation.RequestMapping;
15import org.springframework.web.bind.annotation.RequestParam;
16
17@Controller
18@RequestMapping("/register")
19public class RegisterController {
20 private final AuthService authService;
21 private final KorisnikService korisnikService;
22 private final PatnikService patnikService;
23
24 public RegisterController(AuthService authService, KorisnikService korisnikService, PatnikService patnikService) {
25 this.authService = authService;
26 this.korisnikService = korisnikService;
27 this.patnikService = patnikService;
28 }
29
30 @GetMapping
31 public String getRegisterPage(@RequestParam(required = false) String error, Model model) {
32 if(error != null && !error.isEmpty()) {
33 model.addAttribute("hasError", true);
34 model.addAttribute("error", error);
35 }
36
37 model.addAttribute("types", VrabotenType.values());
38
39 model.addAttribute("bodyContent", "register");
40 return "master-template";
41 }
42
43 @PostMapping
44 public String register(@RequestParam String name,
45 @RequestParam String email,
46 @RequestParam String password,
47 @RequestParam String confirmPassword,
48 @RequestParam String address,
49 @RequestParam String phone,
50 @RequestParam(required = false)VrabotenType vrabotenType,
51 @RequestParam(required = false) Double salary
52 ) {
53 try{
54 Korisnik korisnik;
55 if(vrabotenType != null){
56 korisnik = this.authService.registerVraboten(name, email, password, confirmPassword, address, phone, vrabotenType, salary);
57
58 }
59 else
60 korisnik = this.authService.registerPatnik(name, email, password, confirmPassword, address, phone);
61 return "redirect:/login";
62 } catch (InvalidCredentialsException | UserAlreadyExistsException exception) {
63 return "redirect:/register?error=" + exception.getMessage();
64 }
65 }
66
67// @PostMapping
68// public String registerVraboten(@RequestParam String name,
69// @RequestParam String email,
70// @RequestParam String password,
71// @RequestParam String confirmPassword,
72// @RequestParam String address,
73// @RequestParam String phone){
74//
75// }
76
77}
Note: See TracBrowser for help on using the repository browser.