Advertisement
Mr_Max

Untitled

May 26th, 2022
511
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     @Override
  2.     public String execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
  3.         HttpSession session = request.getSession();
  4.         String email = request.getParameter("email");
  5.         String password = request.getParameter("password");
  6.         UserDto userDto;
  7.         try {
  8.              userDto = userService.login(email, password);
  9.         } catch (IllegalArgumentException exception) {
  10.             session.setAttribute("errorMsg", exception.getMessage());
  11.             session.setAttribute("email", email);
  12.             return PagesConstant.LOGIN_PAGE;
  13.         }
  14.         session.setAttribute("user", userDto);
  15.  
  16.         return PagesConstant.HOME_PAGE;
  17.     }
  18.  
  19.   @Override
  20.     public UserDto login(String email, String password) {
  21.         UserDto user = findByEmail(email);
  22.         if (emailValidation(email)) {
  23.             throw new IllegalArgumentException("Email not correct");
  24.         }
  25.         if (email.equals(user.getEmail()) && password.equals(user.getPassword())) {
  26.             user.setPassword(StringUtils.EMPTY);
  27.             return user;
  28.         } else {
  29.             throw new IllegalArgumentException("Email or Password is not correct");
  30.         }
  31.     }
  32.  
  33.     private boolean emailValidation(String email) {
  34.         String regExp = "^([a-z0-9_-]+\\.)*[a-z0-9_-]+@[a-z0-9_-]+(\\.[a-z0-9_-]+)*\\.[a-z]{2,6}$";
  35.         return !email.matches(regExp);
  36.     }
Advertisement
RAW Paste Data Copied
Advertisement