コード例 #1
0
ファイル: UserFacade.java プロジェクト: robertjulius/mama
  public User addNewUser(
      String login,
      String name,
      String password,
      List<Role> roles,
      boolean disabled,
      boolean deleted,
      Session session)
      throws UserException, AppException {

    if (DBUtils.getInstance().isExists("login", login, User.class, session)) {
      throw new UserException("User dengan Login ID " + login + " sudah pernah didaftarkan");
    }

    User user = new User();
    user.setLogin(login);
    user.setName(name);
    user.setPassword(SecurityUtils.hash(password));
    user.setDisabled(disabled);
    user.setDeleted(deleted);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);

    updateUserRoleLink(user.getId(), roles, session);

    return user;
  }
コード例 #2
0
ファイル: UserFacade.java プロジェクト: robertjulius/mama
  public User updateExistingUser(
      String login,
      String name,
      String password,
      List<Role> roles,
      boolean disabled,
      boolean deleted,
      Session session)
      throws UserException, AppException {

    User user = getDetail(login, session);
    user.setName(name);
    if (password != null && !password.trim().equals("")) {
      user.setPassword(SecurityUtils.hash(password));
    }
    if (deleted) {
      if (!disabled) {
        throw new UserException("Tidak dapat menghapus User yang masih dalam kondisi aktif");
      }
    }
    user.setDisabled(disabled);
    user.setDeleted(deleted);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);

    updateUserRoleLink(user.getId(), roles, session);

    return user;
  }
コード例 #3
0
ファイル: UserFacade.java プロジェクト: robertjulius/mama
  public User changePassword(int userId, String oldPassword, String newPassword, Session session)
      throws AppException, UserException {

    User user = getDetail(userId, session);
    boolean oldPasswordValid =
        LoginFacade.getInstance().validatePassword(oldPassword, user.getPassword());

    if (!oldPasswordValid) {
      throw new UserException("Password Lama tidak sesuai");
    }

    String hashedPassword = SecurityUtils.hash(newPassword);
    user.setPassword(hashedPassword);
    user.setLastUpdatedBy(Main.getUserLogin().getId());
    user.setLastUpdatedTimestamp(CommonUtils.getCurrentTimestamp());

    session.saveOrUpdate(user);
    return user;
  }