Last change
on this file since 74af394 was 74af394, checked in by makyjovanovsky <mjovanovski04@…>, 17 months ago |
login/register with mail confirmation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[74af394] | 1 | package com.example.salonbella.controller.register;
|
---|
| 2 |
|
---|
| 3 | import com.example.salonbella.service.UserService;
|
---|
| 4 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 5 | import org.springframework.stereotype.Controller;
|
---|
| 6 | import org.springframework.ui.Model;
|
---|
| 7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 8 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 9 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
| 10 |
|
---|
| 11 | @Controller
|
---|
| 12 | @RequestMapping("/register")
|
---|
| 13 | public class RegisterController {
|
---|
| 14 |
|
---|
| 15 | private final UserService userService;
|
---|
| 16 |
|
---|
| 17 | @Autowired
|
---|
| 18 | public RegisterController(UserService userService) {
|
---|
| 19 | this.userService = userService;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | @GetMapping
|
---|
| 23 | public String getRegisterPage() {
|
---|
| 24 | return "register";
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | @PostMapping
|
---|
| 28 | public String registerRequest(RegisterRequest registerRequest, Model model) {
|
---|
| 29 | if (userService.checkEmailExists(registerRequest.getEmail())) {
|
---|
| 30 | model.addAttribute("email", "Email already exists");
|
---|
| 31 | return "register";
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if (userService.checkUsernameExists(registerRequest.getUsername())) {
|
---|
| 35 | model.addAttribute("username", "Username already exists");
|
---|
| 36 | return "register";
|
---|
| 37 | }
|
---|
| 38 | userService.registerNewUser(registerRequest);
|
---|
| 39 | return "redirect:/login";
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.