source: Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/LoginController.java@ f0232fb

main
Last change on this file since f0232fb was f0232fb, checked in by trajchevaM <118018439+trajchevaM@…>, 17 months ago

login and home

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package finki.paw5.web.controllers;
2
3import finki.paw5.model.entities.User;
4import finki.paw5.model.exceptions.NonExistingArgumentsException;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PostMapping;
9import org.springframework.web.bind.annotation.RequestMapping;
10
11import finki.paw5.service.AuthService;
12import jakarta.servlet.http.HttpServletRequest;
13import org.springframework.web.bind.annotation.RequestParam;
14
15import java.util.Objects;
16
17@Controller
18@RequestMapping("/login")
19public class LoginController {
20
21 private final AuthService authService;
22
23 public LoginController(AuthService authService) {
24 this.authService = authService;
25 }
26
27 @GetMapping
28 public String register(){
29 return "/login";
30 }
31 @PostMapping
32 public String register(@RequestParam String email, @RequestParam String password, HttpServletRequest request, Model model) throws NonExistingArgumentsException {
33
34 if(email==null || email.equals("") || Objects.equals(password, "") || password==null){
35 throw new NonExistingArgumentsException();
36 }
37 User user = authService.login(email,password);
38
39 if(user!=null){
40 request.getSession().setAttribute("user",user); //go smestuvam korisnikot vo sesija
41 return "redirect:/home";
42 }
43 else{
44 return "redirect:/login";
45 }
46
47
48 }
49}
Note: See TracBrowser for help on using the repository browser.