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

Last change on this file 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 
1package com.example.task.controller;
2
3
4import com.example.task.service.StudentService;
5import lombok.AllArgsConstructor;
6import org.springframework.stereotype.Controller;
7import org.springframework.ui.Model;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11
12@Controller
13@AllArgsConstructor
14public 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.