コード例 #1
0
ファイル: UserApp.java プロジェクト: bluemir/hive
  /**
   * 대표 메일로 설정하기
   *
   * @param id
   * @return
   */
  @Transactional
  public static Result setAsMainEmail(Long id) {
    User currentUser = currentUser();
    Email email = Email.find.byId(id);

    if (currentUser == null || currentUser.isAnonymous() || email == null) {
      return forbidden(ErrorViews.NotFound.render());
    }

    if (!AccessControl.isAllowed(currentUser, email.user.asResource(), Operation.UPDATE)) {
      return forbidden(ErrorViews.Forbidden.render(Messages.get("error.forbidden")));
    }

    String oldMainEmail = currentUser.email;
    currentUser.email = email.email;
    currentUser.removeEmail(email);
    currentUser.update();

    Email newSubEmail = new Email();
    newSubEmail.valid = true;
    newSubEmail.email = oldMainEmail;
    newSubEmail.user = currentUser;
    currentUser.addEmail(newSubEmail);

    return redirect(routes.UserApp.editUserInfoForm());
  }
コード例 #2
0
ファイル: UserApp.java プロジェクト: bluemir/hive
  /**
   * 이메일 추가
   *
   * @return
   */
  @Transactional
  public static Result addEmail() {
    Form<Email> emailForm = form(Email.class).bindFromRequest();
    String newEmail = emailForm.data().get("email");

    if (emailForm.hasErrors()) {
      flash(Constants.WARNING, emailForm.error("email").message());
      return redirect(routes.UserApp.editUserInfoForm());
    }

    User currentUser = currentUser();
    if (currentUser == null || currentUser.isAnonymous()) {
      return forbidden(ErrorViews.NotFound.render());
    }

    if (User.isEmailExist(newEmail) || Email.exists(newEmail, true) || currentUser.has(newEmail)) {
      flash(Constants.WARNING, Messages.get("user.email.duplicate"));
      return redirect(routes.UserApp.editUserInfoForm());
    }

    Email email = new Email();
    User user = currentUser();
    email.user = user;
    email.email = newEmail;
    email.valid = false;

    user.addEmail(email);

    return redirect(routes.UserApp.editUserInfoForm());
  }