示例#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;
   }
 }
示例#2
0
 /** 删除 */
 @RequestMapping(value = "/delete", method = RequestMethod.POST)
 public @ResponseBody Message delete(Long[] ids) {
   if (ids != null) {
     for (Long id : ids) {
       Member member = memberService.find(id);
       if (member != null && member.getBalance().compareTo(new BigDecimal(0)) > 0) {
         return Message.error("admin.member.deleteExistDepositNotAllowed", member.getUsername());
       }
     }
     memberService.delete(ids);
   }
   return SUCCESS_MESSAGE;
 }
示例#3
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";
 }
示例#4
0
 /** 列表 */
 @RequestMapping(value = "/list", method = RequestMethod.GET)
 public String list(Pageable pageable, ModelMap model) {
   model.addAttribute("memberRanks", memberRankService.findAll());
   model.addAttribute("memberAttributes", memberAttributeService.findAll());
   model.addAttribute("page", memberService.findPage(pageable));
   return "/admin/member/list";
 }
示例#5
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;
   }
 }
示例#6
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";
  }
示例#7
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";
 }