Ejemplo n.º 1
0
 /** 检查E-mail是否唯一 */
 @RequestMapping(value = "/check_email", method = RequestMethod.GET)
 public @ResponseBody boolean checkEmail(String previousEmail, String email) {
   if (StringUtils.isEmpty(email)) {
     return false;
   }
   if (memberService.emailUnique(previousEmail, email)) {
     return true;
   } else {
     return false;
   }
 }
Ejemplo n.º 2
0
  /** 更新 */
  @RequestMapping(value = "/update", method = RequestMethod.POST)
  public String update(
      Member member,
      Long memberRankId,
      Integer modifyPoint,
      BigDecimal modifyBalance,
      String depositMemo,
      HttpServletRequest request,
      RedirectAttributes redirectAttributes) {
    member.setMemberRank(memberRankService.find(memberRankId));
    if (!isValid(member)) {
      return ERROR_VIEW;
    }
    Setting setting = SettingUtils.get();
    if (member.getPassword() != null
        && (member.getPassword().length() < setting.getPasswordMinLength()
            || member.getPassword().length() > setting.getPasswordMaxLength())) {
      return ERROR_VIEW;
    }
    Member pMember = memberService.find(member.getId());
    if (pMember == null) {
      return ERROR_VIEW;
    }
    if (!setting.getIsDuplicateEmail()
        && !memberService.emailUnique(pMember.getEmail(), 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);
      }
    }
    if (StringUtils.isEmpty(member.getPassword())) {
      member.setPassword(pMember.getPassword());
    } else {
      member.setPassword(DigestUtils.md5Hex(member.getPassword()));
    }
    if (pMember.getIsLocked() && !member.getIsLocked()) {
      member.setLoginFailureCount(0);
      member.setLockedDate(null);
    } else {
      member.setIsLocked(pMember.getIsLocked());
      member.setLoginFailureCount(pMember.getLoginFailureCount());
      member.setLockedDate(pMember.getLockedDate());
    }

    BeanUtils.copyProperties(
        member,
        pMember,
        new String[] {
          "username",
          "point",
          "amount",
          "balance",
          "registerIp",
          "loginIp",
          "loginDate",
          "safeKey",
          "cart",
          "orders",
          "deposits",
          "payments",
          "couponCodes",
          "receivers",
          "reviews",
          "consultations",
          "favoriteProducts",
          "productNotifies",
          "inMessages",
          "outMessages"
        });
    memberService.update(
        pMember, modifyPoint, modifyBalance, depositMemo, adminService.getCurrent());
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:list.jhtml";
  }