@Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String page = null; User user = null; HttpSession session = request.getSession(false); UserDAO userDao = DaoFactory.getUserDao(); String name = request.getParameter(userDao.NAME); String lastName = request.getParameter(userDao.LAST_NAME); String email = request.getParameter(userDao.EMAIL); String birthday = request.getParameter(userDao.BIRTHDAY); String password = request.getParameter("oldPassword"); String newPassword = request.getParameter("newPassword"); String rPassword = request.getParameter("repeatPassword"); String active = request.getParameter(userDao.ACTIVE); if (session != null) { user = userDao.findById((Integer) session.getAttribute("id")); if (birthday != null) { user.setBirthday(Date.valueOf(birthday)); } if (email != null) { user.setEmail(email); } if (lastName != null) { user.setLastName(lastName); } if (name != null) { user.setName(name); } if (password != null && password.equals(user.getPassword()) && newPassword != null && newPassword.equals(rPassword)) { user.setPassword(newPassword); } if (active != null) { user.setActive(Boolean.parseBoolean(active)); } userDao.update(user); page = Config.getInstance().getProperty(Config.PROFILE); } else { page = Config.getInstance().getProperty(Config.LOGIN); } request.setAttribute("user", user); return page; }
@Override public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UserDAO userDao = DaoFactory.getUserDao(); HttpSession session = request.getSession(false); String page = null; User user = null; if (session == null) { page = Config.getInstance().getProperty(Config.LOGIN); } else { user = userDao.findById((Integer) session.getAttribute("id")); request.setAttribute("user", user); page = Config.getInstance().getProperty(Config.CHANGE_PROFILE); } return page; }