Beispiel #1
0
  /**
   * 이메일 확인
   *
   * @param id
   * @param token
   * @return
   */
  @Transactional
  public static Result confirmEmail(Long id, String token) {
    Email email = Email.find.byId(id);

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

    if (email.validate(token)) {
      addUserInfoToSession(email.user);
      return redirect(routes.UserApp.editUserInfoForm());
    } else {
      return forbidden(ErrorViews.NotFound.render());
    }
  }
Beispiel #2
0
  /**
   * 대표 메일로 설정하기
   *
   * @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());
  }
Beispiel #3
0
  /**
   * 이메일 추가
   *
   * @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());
  }
  @Override
  public final Result call(Context context) throws Throwable {
    PathParser parser = new PathParser(context);
    String ownerLoginId = parser.getOwnerLoginId();
    String projectName = parser.getProjectName();

    Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName);

    if (project == null) {
      return AccessLogger.log(
          context.request(), notFound(ErrorViews.NotFound.render("error.notfound.project")), null);
    }

    if (!AccessControl.isAllowed(UserApp.currentUser(), project.asResource(), Operation.READ)) {
      return AccessLogger.log(
          context.request(), notFound(ErrorViews.NotFound.render("error.notfound.project")), null);
    }

    return call(project, context, parser);
  }
Beispiel #5
0
  /**
   * 이메일 삭제
   *
   * @param id
   * @return
   */
  @Transactional
  public static Result deleteEmail(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.DELETE)) {
      return forbidden(ErrorViews.Forbidden.render(Messages.get("error.forbidden")));
    }

    email.delete();
    return redirect(routes.UserApp.editUserInfoForm());
  }
Beispiel #6
0
  /**
   * 보조 이메일 확인 메일 보내기
   *
   * @param id
   * @return
   */
  @Transactional
  public static Result sendValidationEmail(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")));
    }

    email.sendValidationEmail();

    flash(Constants.WARNING, "확인 메일을 전송했습니다.");
    return redirect(routes.UserApp.editUserInfoForm());
  }
Beispiel #7
0
 @Override
 public Result onHandlerNotFound(RequestHeader request) {
   AccessLogger.log(request, null, Http.Status.NOT_FOUND);
   return Results.notFound(ErrorViews.NotFound.render());
 }