Ejemplo n.º 1
0
 /** 检查用户名是否被禁用或已存在 */
 @RequestMapping(value = "/check_username", method = RequestMethod.GET)
 public @ResponseBody boolean checkUsername(String username) {
   if (StringUtils.isEmpty(username)) {
     return false;
   }
   if (memberService.usernameDisabled(username) || memberService.usernameExists(username)) {
     return false;
   } else {
     return true;
   }
 }
Ejemplo n.º 2
0
 /** 保存 */
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 public String save(
     Member member,
     Long memberRankId,
     HttpServletRequest request,
     RedirectAttributes redirectAttributes) {
   member.setMemberRank(memberRankService.find(memberRankId));
   if (!isValid(member, Save.class)) {
     return ERROR_VIEW;
   }
   Setting setting = SettingUtils.get();
   if (member.getUsername().length() < setting.getUsernameMinLength()
       || member.getUsername().length() > setting.getUsernameMaxLength()) {
     return ERROR_VIEW;
   }
   if (member.getPassword().length() < setting.getPasswordMinLength()
       || member.getPassword().length() > setting.getPasswordMaxLength()) {
     return ERROR_VIEW;
   }
   if (memberService.usernameDisabled(member.getUsername())
       || memberService.usernameExists(member.getUsername())) {
     return ERROR_VIEW;
   }
   if (!setting.getIsDuplicateEmail() && memberService.emailExists(member.getEmail())) {
     return ERROR_VIEW;
   }
   member.removeAttributeValue();
   for (MemberAttribute memberAttribute : memberAttributeService.findList()) {
     String parameter = request.getParameter("memberAttribute_" + memberAttribute.getId());
     if (memberAttribute.getType() == MemberAttribute.Type.name
         || memberAttribute.getType() == MemberAttribute.Type.address
         || memberAttribute.getType() == MemberAttribute.Type.zipCode
         || memberAttribute.getType() == MemberAttribute.Type.phone
         || memberAttribute.getType() == MemberAttribute.Type.mobile
         || memberAttribute.getType() == MemberAttribute.Type.text
         || memberAttribute.getType() == MemberAttribute.Type.select) {
       if (memberAttribute.getIsRequired() && StringUtils.isEmpty(parameter)) {
         return ERROR_VIEW;
       }
       member.setAttributeValue(memberAttribute, parameter);
     } else if (memberAttribute.getType() == MemberAttribute.Type.gender) {
       Gender gender = StringUtils.isNotEmpty(parameter) ? Gender.valueOf(parameter) : null;
       if (memberAttribute.getIsRequired() && gender == null) {
         return ERROR_VIEW;
       }
       member.setGender(gender);
     } else if (memberAttribute.getType() == MemberAttribute.Type.birth) {
       try {
         Date birth =
             StringUtils.isNotEmpty(parameter)
                 ? DateUtils.parseDate(parameter, CommonAttributes.DATE_PATTERNS)
                 : null;
         if (memberAttribute.getIsRequired() && birth == null) {
           return ERROR_VIEW;
         }
         member.setBirth(birth);
       } catch (ParseException e) {
         return ERROR_VIEW;
       }
     } else if (memberAttribute.getType() == MemberAttribute.Type.area) {
       Area area =
           StringUtils.isNotEmpty(parameter) ? areaService.find(Long.valueOf(parameter)) : null;
       if (area != null) {
         member.setArea(area);
       } else if (memberAttribute.getIsRequired()) {
         return ERROR_VIEW;
       }
     } else if (memberAttribute.getType() == MemberAttribute.Type.checkbox) {
       String[] parameterValues =
           request.getParameterValues("memberAttribute_" + memberAttribute.getId());
       List<String> options = parameterValues != null ? Arrays.asList(parameterValues) : null;
       if (memberAttribute.getIsRequired() && (options == null || options.isEmpty())) {
         return ERROR_VIEW;
       }
       member.setAttributeValue(memberAttribute, options);
     }
   }
   member.setUsername(member.getUsername().toLowerCase());
   member.setPassword(DigestUtils.md5Hex(member.getPassword()));
   member.setAmount(new BigDecimal(0));
   member.setIsLocked(false);
   member.setLoginFailureCount(0);
   member.setLockedDate(null);
   member.setRegisterIp(request.getRemoteAddr());
   member.setLoginIp(null);
   member.setLoginDate(null);
   member.setSafeKey(null);
   member.setCart(null);
   member.setOrders(null);
   member.setDeposits(null);
   member.setPayments(null);
   member.setCouponCodes(null);
   member.setReceivers(null);
   member.setReviews(null);
   member.setConsultations(null);
   member.setFavoriteProducts(null);
   member.setProductNotifies(null);
   member.setInMessages(null);
   member.setOutMessages(null);
   memberService.save(member, adminService.getCurrent());
   addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
   return "redirect:list.jhtml";
 }