[3ded84d] | 1 | //package com.wediscussmovies.project.web.controller;
|
---|
| 2 | //
|
---|
| 3 | //import com.wediscussmovies.project.model.PasswordEncoder;
|
---|
| 4 | //import com.wediscussmovies.project.model.*;
|
---|
| 5 | //import com.wediscussmovies.project.model.exception.InvalidUserCredentialsException;
|
---|
| 6 | //import com.wediscussmovies.project.service.UserService;
|
---|
| 7 | //import org.springframework.stereotype.Controller;
|
---|
| 8 | //import org.springframework.ui.Model;
|
---|
| 9 | //import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 10 | //import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 11 | //import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 12 | //
|
---|
| 13 | //import javax.servlet.http.HttpServletRequest;
|
---|
| 14 | //import java.security.NoSuchAlgorithmException;
|
---|
| 15 | //import java.util.Optional;
|
---|
| 16 | //
|
---|
| 17 | //@Controller
|
---|
| 18 | //public class UsersController{
|
---|
| 19 | // private final UserService userService;
|
---|
| 20 | //
|
---|
| 21 | // public UsersController(UserService userService) {
|
---|
| 22 | // this.userService = userService;
|
---|
| 23 | // }
|
---|
| 24 | //
|
---|
| 25 | // @GetMapping("/login")
|
---|
| 26 | // public String getLoginPage(Model model){
|
---|
| 27 | // return "login";
|
---|
| 28 | // }
|
---|
| 29 | //
|
---|
| 30 | // @PostMapping("/login/confirm")
|
---|
| 31 | // public String confirmLogin(HttpServletRequest request, Model model,
|
---|
| 32 | // @RequestParam String username,
|
---|
| 33 | // @RequestParam String password){
|
---|
| 34 | // Optional<User> user;
|
---|
| 35 | // try{
|
---|
| 36 | // password = PasswordEncoder.getEncodedPasswordString(password);
|
---|
| 37 | // }
|
---|
| 38 | // catch (NoSuchAlgorithmException ex){
|
---|
| 39 | // model.addAttribute("hasError", true);
|
---|
| 40 | // model.addAttribute("error", ex.getMessage());
|
---|
| 41 | // return "login";
|
---|
| 42 | // }
|
---|
| 43 | //
|
---|
| 44 | // try{
|
---|
| 45 | // user = this.userService.login(username, password);
|
---|
| 46 | // request.getSession().setAttribute("user", user);
|
---|
| 47 | // request.getSession().setAttribute("loggedIn",true);
|
---|
| 48 | // return "redirect:/movies";
|
---|
| 49 | // }
|
---|
| 50 | // catch (InvalidUserCredentialsException ex){
|
---|
| 51 | // model.addAttribute("hasError", true);
|
---|
| 52 | // model.addAttribute("error", ex.getMessage());
|
---|
| 53 | // return "login";
|
---|
| 54 | // }
|
---|
| 55 | // }
|
---|
| 56 | //
|
---|
| 57 | // @GetMapping("/register")
|
---|
| 58 | // public String getRegisterPage(){
|
---|
| 59 | // return "register";
|
---|
| 60 | // }
|
---|
| 61 | //
|
---|
| 62 | // @PostMapping("/login/confirm")
|
---|
| 63 | // public String confirmRegister(HttpServletRequest request,
|
---|
| 64 | // @RequestParam String username,
|
---|
| 65 | // @RequestParam String email,
|
---|
| 66 | // @RequestParam String password,
|
---|
| 67 | // @RequestParam String confirmPassword,
|
---|
| 68 | // @RequestParam String name,
|
---|
| 69 | // @RequestParam String surname){
|
---|
| 70 | // Optional<User> user;
|
---|
| 71 | //
|
---|
| 72 | // try{
|
---|
| 73 | // password = PasswordEncoder.getEncodedPasswordString(password);
|
---|
| 74 | // confirmPassword = PasswordEncoder.getEncodedPasswordString(confirmPassword);
|
---|
| 75 | // }
|
---|
| 76 | // catch (NoSuchAlgorithmException ex){
|
---|
| 77 | // request.getSession().setAttribute("error", "Contact the administrators!");
|
---|
| 78 | // request.getSession().setAttribute("hasError", "true");
|
---|
| 79 | // return "redirect:/movies";
|
---|
| 80 | // }
|
---|
| 81 | //
|
---|
| 82 | // user = this.userService.register(request, email, password, confirmPassword, username, name, surname);
|
---|
| 83 | // if(user.isEmpty()){
|
---|
| 84 | // request.setAttribute("hasError", "true");
|
---|
| 85 | // }else{
|
---|
| 86 | // request.getSession().setAttribute("hasError", "false");
|
---|
| 87 | // request.getSession().setAttribute("user", user.get());
|
---|
| 88 | // request.getSession().setAttribute("loggedIn",true);
|
---|
| 89 | // }
|
---|
| 90 | // return "redirect:/movies";
|
---|
| 91 | // }
|
---|
| 92 | //
|
---|
| 93 | // @GetMapping
|
---|
| 94 | // public String logout(HttpServletRequest request){
|
---|
| 95 | // request.getSession().invalidate();
|
---|
| 96 | // return "redirect:/login";
|
---|
| 97 | // }
|
---|
| 98 | //}
|
---|