コード例 #1
0
  public int add(AccountAddViewModel accountAddViewModel) {
    int result = 0;
    try {
      Accounts account = new Accounts();
      account.setRole(Accounts.AccountRole.CUSTOMER);
      Timestamp current = new Timestamp((new Date()).getTime());
      account.setCreated(current);
      account.setUpdated(current);
      account.setDeleted(false);
      account.setUserName(accountAddViewModel.getUserName());
      account.setFirstName(accountAddViewModel.getFirstName());
      account.setLastName(accountAddViewModel.getLastName());
      account.setEmail(accountAddViewModel.getEmail());
      account.setPassword(accountAddViewModel.getPassword()); // todo: hash
      account.setPhoneNumber(accountAddViewModel.getPhoneNumber());
      account.setStreetName(accountAddViewModel.getStreetName());
      account.setStreetNumber(accountAddViewModel.getStreetNumber());
      account.setCity(accountAddViewModel.getCity());
      account.setTags(accountAddViewModel.getTags());

      em.persist(account);
      em.flush();
      result = account.getId();
    } catch (Exception e) {
      logger.warn(e.getMessage());
    }
    return result;
  }
コード例 #2
0
 public boolean changePassword(int id, AccountPasswordViewModel pswdViewModel) {
   boolean result = false;
   try {
     Accounts account = super.find(id);
     if (account.getPassword().equals(pswdViewModel.getOldPassword())
         && pswdViewModel.getNewPassword() != null
         && pswdViewModel.getNewPassword().length() > 0) {
       account.setPassword(pswdViewModel.getNewPassword());
       super.edit(account);
       result = true;
     }
   } catch (Exception e) {
     logger.warn(e.getMessage());
   }
   return result;
 }