/* * 사용자 가입 입력 폼 유효성 체크 */ private static void validate(Form<User> newUserForm) { // loginId가 빈 값이 들어오면 안된다. if (newUserForm.field("loginId").value().trim().isEmpty()) { newUserForm.reject("loginId", "user.wrongloginId.alert"); } if (newUserForm.field("loginId").value().contains(" ")) { newUserForm.reject("loginId", "user.wrongloginId.alert"); } // password가 빈 값이 들어오면 안된다. if (newUserForm.field("password").value().trim().isEmpty()) { newUserForm.reject("password", "user.wrongPassword.alert"); } // 중복된 loginId로 가입할 수 없다. if (User.isLoginIdExist(newUserForm.field("loginId").value())) { newUserForm.reject("loginId", "user.loginId.duplicate"); } // 중복된 email로 가입할 수 없다. if (User.isEmailExist(newUserForm.field("email").value())) { newUserForm.reject("email", "user.email.duplicate"); } }
/** * 이메일 추가 * * @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()); }
/** * 사용자 정보 수정 * * @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)); }
/** * 이메일 존재 여부 * * @param email 이메일 * @return */ @BodyParser.Of(BodyParser.Json.class) public static Result isEmailExist(String email) { ObjectNode result = Json.newObject(); result.put("isExist", User.isEmailExist(email)); return ok(result); }