@Override public User getUser(MessageManager message, String email) throws LogicException { try { User user = userDao.findByEmail(email); if (user == null) { message.addMessage(MSG_LOGIN); throw new LogicException("Getting user failed"); } return user; } catch (DatabaseException e) { message.addMessage(MSG_LOGIN); throw new LogicException("Getting user failed", e); } }
@Override public String execute(HttpServletRequest request) { MessageManager message = new MessageManager(); IService<User> userService = null; try { userService = UserService.getInstance(); } catch (LogicException e) { LOG.error("User to edit action failed", e); return getForwardError(); } String idString = request.getParameter(PARAM_USER_ID); if (idValidator.isValid(idString)) { try { long id = Long.valueOf(idString); User user = userService.get(id, message); request.setAttribute(PARAM_USER_GET, user); } catch (LogicException e) { LOG.error("User finding failed", e); } } else { message.addMessage(idValidator.getMessage()); } setMessages(request, message); String forward = resources.getString(JSP_USER_EDIT); return forward; }
@Override public boolean checkPasswords(MessageManager message, User user, int password) { if (user.getPassword() == password) { return true; } message.addMessage(MSG_PASSWORD); return false; }
@Override public boolean checkPasswords(MessageManager message, String password, String confirmPassword) { if (password.equals(confirmPassword)) { return true; } message.addMessage(MSG_MATCH); return false; }
@Override public boolean register(MessageManager message, User user) { if (user == null) { LOG.warn("User is null"); return false; } if (isRegistered(user.getEmail())) { message.addMessage(MSG_EMAIL); return false; } try { userDao.save(user); } catch (DatabaseException e) { LOG.error("Register failed", e); message.addMessage(MSG_REGISTER); return false; } return true; }
@Override public boolean login(MessageManager message, User user) { if (user == null) { LOG.warn("User is null"); return false; } int password = user.getPassword(); try { user = userDao.findByEmail(user.getEmail()); if (user == null || user.getPassword() != password) { message.addMessage(MSG_ICORRECT); return false; } } catch (DatabaseException e) { LOG.error("Login failed", e); message.addMessage(MSG_LOGIN); return false; } return true; }
@Override public boolean edit(MessageManager message, User user) { if (user == null) { LOG.warn("User is null"); return false; } try { userDao.update(user); } catch (DatabaseException e) { LOG.error("Profile editing failed", e); message.addMessage(MSG_EDIT); return false; } return true; }