Last change
on this file since fdfbdde was fdfbdde, checked in by Stojilkova Sara <sara.stojilkova.students.finki.ukim.mk>, 9 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | package com.example.task.controller;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.task.service.StudentService;
|
---|
5 | import lombok.AllArgsConstructor;
|
---|
6 | import org.springframework.stereotype.Controller;
|
---|
7 | import org.springframework.ui.Model;
|
---|
8 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
10 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
11 |
|
---|
12 | @Controller
|
---|
13 | @AllArgsConstructor
|
---|
14 | public class RegisterController {
|
---|
15 |
|
---|
16 | private final StudentService studentService;
|
---|
17 |
|
---|
18 | @GetMapping("/login")
|
---|
19 | public String getLoginPage() {
|
---|
20 | return "login";
|
---|
21 | }
|
---|
22 |
|
---|
23 | @GetMapping("/register")
|
---|
24 | public String getRegisterPage() {
|
---|
25 | return "register";
|
---|
26 | }
|
---|
27 |
|
---|
28 | @PostMapping("/register")
|
---|
29 | public String registerNewUser(@RequestParam(name = "firstName") String firstName,
|
---|
30 | @RequestParam(name = "lastName") String lastName,
|
---|
31 | @RequestParam(name = "username") String username,
|
---|
32 | @RequestParam(name = "password") String password,
|
---|
33 | Model model) {
|
---|
34 | try {
|
---|
35 | studentService.registerNewStudent(firstName, lastName, username, password);
|
---|
36 | } catch (Exception e) {
|
---|
37 | model.addAttribute("message", e.getMessage());
|
---|
38 | return "register";
|
---|
39 | }
|
---|
40 | return "redirect:/login";
|
---|
41 | }
|
---|
42 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.