Example #1
0
 /*
  * 신규 가입 사용자 생성
  */
 private static User createNewUser(User user) {
   RandomNumberGenerator rng = new SecureRandomNumberGenerator();
   user.passwordSalt = Arrays.toString(rng.nextBytes().getBytes());
   user.password = hashedPassword(user.password, user.passwordSalt);
   User.create(user);
   if (isUseSignUpConfirm()) {
     user.changeState(UserState.LOCKED);
   } else {
     user.changeState(UserState.ACTIVE);
   }
   Email.deleteOtherInvalidEmails(user.email);
   return user;
 }
Example #2
0
  /**
   * 사용자 정보 수정
   *
   * @return
   */
  @With(AnonymousCheckAction.class)
  @Transactional
  public static Result editUserInfo() {
    Form<User> userForm = new Form<>(User.class).bindFromRequest("name", "email");
    String newEmail = userForm.data().get("email");
    String newName = userForm.data().get("name");
    User user = UserApp.currentUser();

    if (StringUtils.isEmpty(newEmail)) {
      userForm.reject("email", "user.wrongEmail.alert");
    } else {
      if (!StringUtils.equals(user.email, newEmail) && User.isEmailExist(newEmail)) {
        userForm.reject("email", "user.email.duplicate");
      }
    }

    if (userForm.error("email") != null) {
      flash(Constants.WARNING, userForm.error("email").message());
      return badRequest(edit.render(userForm, user));
    }
    user.email = newEmail;
    user.name = newName;

    try {
      Long avatarId = Long.valueOf(userForm.data().get("avatarId"));
      if (avatarId != null) {
        Attachment attachment = Attachment.find.byId(avatarId);
        String primary = attachment.mimeType.split("/")[0].toLowerCase();

        if (attachment.size > AVATAR_FILE_LIMIT_SIZE) {
          userForm.reject("avatarId", "user.avatar.fileSizeAlert");
        }

        if (primary.equals("image")) {
          Attachment.deleteAll(currentUser().avatarAsResource());
          attachment.moveTo(currentUser().avatarAsResource());
        }
      }
    } catch (NumberFormatException ignored) {
    }

    Email.deleteOtherInvalidEmails(user.email);
    user.update();
    return redirect(
        routes.UserApp.userInfo(user.loginId, DEFAULT_GROUP, DAYS_AGO, DEFAULT_SELECTED_TAB));
  }