Beispiel #1
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());
  }
Beispiel #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));
  }
  /**
   * Save past race
   *
   * @return
   */
  public static Result save() {
    Form<PastRaceForm> form = form(PastRaceForm.class).bindFromRequest();
    // Is this an update or a creation?
    PastRace pastRace = null;
    boolean isnew = false;
    String raceId = form.field("id").value();
    if (!StringUtils.isEmpty(raceId)) {
      try {
        pastRace = PastRace.find.byId(Long.valueOf(raceId));
      } catch (NumberFormatException n) {
      }
      if (pastRace == null || !pastRace.user.equals(getConnectedUser())) {
        Logger.error("Past race save forbidden");
        return forbidden();
      }
    } else {
      isnew = true;
      pastRace = new PastRace();
      pastRace.dateCreation = new Date();
    }

    // Check date format
    Date date = null;
    if (form.error("date") == null) {
      DateFormat df = new SimpleDateFormat(Messages.get("general.dateformat"));
      try {
        date = df.parse(form.field("date").value());
      } catch (ParseException p) {
        form.reject("date", "general.error.dateformat");
      }
    }

    // Check time
    String hours = form.field("hours").value();
    String minutes = form.field("minutes").value();
    String seconds = form.field("seconds").value();
    if (StringUtils.isEmpty(hours)
        || StringUtils.isEmpty(minutes)
        || StringUtils.isEmpty(seconds)) {
      form.reject("time", "general.error.multiple");
    }

    int timeInSeconds = 0;
    try {
      timeInSeconds += Integer.parseInt(hours) * 3600;
      timeInSeconds += Integer.parseInt(minutes) * 60;
      timeInSeconds += Integer.parseInt(seconds);
    } catch (NumberFormatException n) {
      form.reject("time", "pastrace.error.time");
    }

    if (form.hasErrors()) {
      return badRequest(views.html.user.pastRace.render(form, isnew));
    } else {
      // Save past race
      pastRace.name = form.field("name").value();
      pastRace.date = date;
      pastRace.user = Application.getConnectedUser();
      pastRace.distance = form.field("distance").value();
      pastRace.time = timeInSeconds;
      Ebean.save(pastRace);

      // Redirect to user homepage
      return redirect(
          controllers.user.routes.UserController.index(Application.getConnectedUser().username));
    }
  }