@Override public boolean isRegistered(String email) { try { User user = userDao.findByEmail(email); if (user != null) { return true; } } catch (DatabaseException e) { LOG.error("Checking register failed", e); } return false; }
@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 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; }
@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; }