source: src/main/java/com/example/eatys_app/controller/RegisterController.java

Last change on this file was b3f2adb, checked in by Aleksandar Siljanoski <acewow3@…>, 14 months ago

Adding project to repo

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[b3f2adb]1package com.example.eatys_app.controller;
2
3
4import com.example.eatys_app.model.exceptions.InvalidArgumentsException;
5import com.example.eatys_app.model.exceptions.PasswordsDoNotMatchException;
6import com.example.eatys_app.service.AuthService;
7import com.example.eatys_app.service.KorisnikService;
8import org.springframework.stereotype.Controller;
9import org.springframework.ui.Model;
10import org.springframework.web.bind.annotation.GetMapping;
11import org.springframework.web.bind.annotation.PostMapping;
12import org.springframework.web.bind.annotation.RequestMapping;
13import org.springframework.web.bind.annotation.RequestParam;
14
15@Controller
16@RequestMapping("/register")
17public class RegisterController {
18
19 private final AuthService authService;
20 private final KorisnikService korisnikService;
21
22 public RegisterController(AuthService authService, KorisnikService korisnikService) {
23 this.authService = authService;
24 this.korisnikService = korisnikService;
25 }
26
27
28 @GetMapping
29 public String getRegisterPage(@RequestParam(required = false) String error, Model model) {
30 if (error != null && !error.isEmpty()) {
31 model.addAttribute("hasError", true);
32 model.addAttribute("error", error);
33 }
34
35 return "register.html";
36 }
37
38
39 @PostMapping
40 public String register(@RequestParam String ime,
41 @RequestParam String prezime,
42 @RequestParam String password,
43 @RequestParam String repeatedPassword) {
44 try {
45 this.korisnikService.register(ime, prezime, password, repeatedPassword);
46 return "redirect:/login";
47 } catch (InvalidArgumentsException | PasswordsDoNotMatchException exception) {
48 return "redirect:/register?error=" + exception.getMessage();
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.