private Users_Dao setData(HttpServletRequest request, Users_Dao user) { user.setLogin(request.getParameter("login")); user.setPassword(request.getParameter("password")); return user; }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int result = 0; boolean validated = false; Messages message = new Messages(request); if (request.getParameter("login") != null) { Users_Dao user = new Users_Dao(); Logins_Dao login = new Logins_Dao(); user = setData(request, user); login.setAgent(request.getHeader("User-Agent")); login.setUser_ip(request.getRemoteAddr()); login.setLogin(request.getParameter("login")); login.setPassword(request.getParameter("password")); Users_Model modelObject = new Users_Model(user); Logins_Model loginObject = new Logins_Model(login); Users_Validator validatorObject = new Users_Validator(); validated = validatorObject.check(user); if (validated) { try { user = modelObject.authorize(user); loginObject.save(user); } catch (SQLException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } if (user.getId() > 0) { result = user.getId(); request.getSession().setAttribute("user_id", user.getId()); request.getSession().setAttribute("user_status", user.getStatus()); request.getSession().setAttribute("user_login", user.getLogin()); response.sendRedirect("/admin"); } else { response.sendRedirect("/" + MODULE); } } else { response.sendRedirect("/" + MODULE); } message.setMessage(MODULE, result); request = message.show(); } }