Esempio n. 1
0
 /** 查看 */
 @RequestMapping(value = "/view", method = RequestMethod.GET)
 public String view(Long id, ModelMap model) {
   model.addAttribute("genders", Gender.values());
   model.addAttribute("memberAttributes", memberAttributeService.findList());
   model.addAttribute("member", memberService.find(id));
   return "/admin/member/view";
 }
Esempio n. 2
0
 /** 添加 */
 @RequestMapping(value = "/add", method = RequestMethod.GET)
 public String add(ModelMap model) {
   model.addAttribute("genders", Gender.values());
   model.addAttribute("memberRanks", memberRankService.findAll());
   model.addAttribute("memberAttributes", memberAttributeService.findList());
   return "/admin/member/add";
 }
Esempio n. 3
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";
  }
Esempio n. 4
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";
 }