예제 #1
0
 public void isLockFlag(UserVO userVO) {
   /*
    * PAN-Z-G
    * 当active_flag为锁定状态时(0),将锁定标识修改为1为锁定
    * */
   if (userVO != null && userVO.getActiveFlag() == 0) {
     userVO.setLockFlag(1);
   } else if (userVO != null && userVO.getActiveFlag() == 1) {
     userVO.setLockFlag(0);
   }
 }
예제 #2
0
  /**
   * 修改用户锁定标识
   *
   * @return
   */
  @Action(
      value = "updateLockFlag",
      results = {
        @Result(
            type = "json",
            params = {"root", "entityMap", "contentType", "text/html"})
      })
  public String updateLockFlag() {
    try {
      entityMap = new HashMap<String, Object>();
      // 多个id以逗号分隔
      String Ids = request.getParameter("userId");
      logger.info("update user's id: " + Ids);
      String[] deleteIds = Ids.split(",");
      if (0 <= Arrays.binarySearch(deleteIds, "" + users.getId())) {
        // 如果修改的包含自己,将自己的id从修改列表里清除
        List<String> list = new ArrayList<String>();
        for (String dId : deleteIds) list.add(dId);
        list.remove("" + users.getId());
        deleteIds = (String[]) list.toArray(new String[list.size()]);
      }
      Long[] deleteIdLongs = ConvertUtil.arrStringToLong(deleteIds);
      for (Long id : deleteIdLongs) {
        System.out.println("update sql -->" + id);
        UserVO userVO = new UserVO();
        userVO.setId(id);
        userVO.setLockFlag(0);
        userVO.setActiveFlag(1);
        userService.update(userVO);
      }
      entityMap.put("message", "解锁成功!");

    } catch (Exception e) {
      logger.error("update user error", e);
    }
    return SUCCESS;
  }
예제 #3
0
  /**
   * 新增用户
   *
   * @return
   * @throws Exception
   */
  @Action(
      value = "adduser",
      results = {
        @Result(
            type = "json",
            params = {"root", "entityMap", "contentType", "text/html"})
      })
  public String adduser() {
    try {
      logger.info("add user: 	"******"V_P_" + portalUser.getProvince());
          merchant.setGroupCode(String.valueOf(merchantPin));
          merchant.setPlatform(ApSmsConstants.MERCHANT_PROVINCE_VIRTUAL_TYPE);
          merchant.setCreateTime(new Date());
          boolean result = MbnMerchantVipIService.insertMerchant(merchant);
          logger.info(
              "Province ["
                  + portalUser.getProvince()
                  + "] add virtual merchant ["
                  + merchantPin
                  + "] result:"
                  + result);
        } else {
          merchantPin = vProvinceMerchant.getMerchantPin();
        }
      } else if (userType == ApSmsConstants.USER_TYPE_PROVINCE_ADMIN) {
        // 省管理员创建市管理员
        portalUser.setUserType(ApSmsConstants.USER_TYPE_CITY_ADMIN);
        MbnMerchantVip vCityMerchant =
            MbnMerchantVipIService.loadVirtualProvinceMerchant(
                portalUser.getCity(), ApSmsConstants.MERCHANT_CITY_VIRTUAL_TYPE);
        // 判断地市虚拟企业是否存在,不存在增加
        if (vCityMerchant == null) {
          MbnMerchantVip merchant = new MbnMerchantVip();
          merchantPin = PinGen.getMerchantPin();
          merchant.setProvince(portalUser.getProvince());
          merchant.setCity(portalUser.getCity());
          merchant.setMerchantPin(merchantPin);
          merchant.setName("V_C_" + portalUser.getCity());
          merchant.setGroupCode(String.valueOf(merchantPin));
          merchant.setPlatform(ApSmsConstants.MERCHANT_CITY_VIRTUAL_TYPE);
          merchant.setCreateTime(new Date());
          boolean result = MbnMerchantVipIService.insertMerchant(merchant);
          logger.info(
              "Province ["
                  + portalUser.getProvince()
                  + "] City ["
                  + portalUser.getCity()
                  + "] "
                  + "add virtual merchant ["
                  + merchantPin
                  + "] result:"
                  + result);
        } else {
          merchantPin = vCityMerchant.getMerchantPin();
        }
      } else if (userType == ApSmsConstants.USER_TYPE_CITY_ADMIN) {
        // 市管理员创建企业管理员
        portalUser.setUserType(ApSmsConstants.USER_TYPE_ENTERPRISE_ADMIN);
        merchantPin = portalUser.getMerchantPin();
      } else if (userType == ApSmsConstants.USER_TYPE_ENTERPRISE_ADMIN) {
        // 企业管理员创建企业用户
        portalUser.setUserType(ApSmsConstants.USER_TYPE_ENTERPRISE_NORMAL);
      } else {
        // 默认企业用户
        portalUser.setUserType(ApSmsConstants.USER_TYPE_ENTERPRISE_NORMAL);
      }
      portalUser.setCreateBy(users.getId());
      // 设定是否为托管mas处理方式
      if (WebUtils.isHostMas()) {
        // 20130427 为用户随机生成zxtUserId
        String zxtUserId = getZxtUserId();
        portalUser.setZxtUserId(zxtUserId);
        portalUser.setMerchantPin(merchantPin);
      }
      Users existUser = userService.validateUser(portalUser);
      if (existUser != null) {
        entityMap.put("flag", "用户账号已存在,请重新填写");
        return SUCCESS;
      }
      // add wangyu
      portalUser.setMerchantPin(merchantPin);
      // 地市管理员创建用户分配角色硬编码
      Set<RoleVO> rSet = new HashSet<RoleVO>();
      if (userType == ApSmsConstants.USER_TYPE_CITY_ADMIN) {
        RoleVO roleVO = new RoleVO();
        roleVO.setId(ApSmsConstants.UNION_CORP_ADMIN_ROLEID);
        roleVO.setCreateBy(users.getId());
        rSet.add(roleVO);
      } else {
        String[] roles = multiUserRoles.split(", ");
        RoleVO roleVO = null;
        for (String _role : roles) {
          roleVO = new RoleVO();
          roleVO.setId(Long.parseLong(_role));
          roleVO.setCreateBy(users.getId());
          rSet.add(roleVO);
        }
      }
      portalUser.setRoles(rSet);
      // 添加解锁~加锁
      isLockFlag(portalUser);
      portalUser.setFirstLoginFlag(0);
      if (!org.apache.commons.lang3.StringUtils.isBlank(
          WebUtils.getPropertyByName(com.leadtone.mas.admin.common.ApSmsConstants.TUNNELALL))) {
        String tunnelAll =
            WebUtils.getPropertyByName(com.leadtone.mas.admin.common.ApSmsConstants.TUNNELALL);
        if ("true".equalsIgnoreCase(tunnelAll)) {
          Integer corpId = MbnMerchantVipIService.getCorpZXTId(merchantPin);
          int userId =
              ZXTUserTool.addUser(
                  portalUser.getAccount(),
                  portalUser.getPassword(),
                  corpId.toString(),
                  portalUser.getZxtUserId());
          portalUser.setZxtId(userId);
          portalUser.setZxtLoginAcount(portalUser.getAccount());
          portalUser.setZxtPwd(portalUser.getPassword());
        }
      }
      portalUser.setId(PinGen.getSerialPin());
      if (StringUtil.isEmpty(portalUser.getZxtUserId())) {
        // TODO
        portalUser.setZxtUserId(portalUser.getId().toString());
      }
      userService.addUser(portalUser);
      // 增加扩展信息
      portalUserExt.setId(portalUser.getId());
      portalUserExtService.save(portalUserExt);

      // 地市管理员创建企业管理员,需要同步至业务节点 20130926
      if (userType == ApSmsConstants.USER_TYPE_CITY_ADMIN) {
        try {
          addUserToNode(portalUser, portalUserExt);
        } catch (Exception e) {
          logger.error("Add user to node faile", e);
        }
      }

      entityMap.put("flag", SUCCESS);
      logger.info("add user success");
    } catch (Exception exception) {
      entityMap = new HashMap<String, Object>();
      entityMap.put("flag", ERROR);
      logger.error("add user error: ", exception);
      return ERROR;
    }
    return SUCCESS;
  }
예제 #4
0
  /**
   * 先根据用户输入的用户名获取用户信息,然后再决定是否允许用户登录
   *
   * @return
   */
  @Override
  @Action(
      value = "login",
      results = {
        @Result(name = SUCCESS, location = "/smsmain.jsp"),
        @Result(name = ERROR, location = "/smslogin.jsp")
      })
  public String execute() {
    UserVO users = userService.getUserByAccount(this.account);

    /*
     * if (!StringUtils.endsWithIgnoreCase(this.getVerifyCode(), (String)
     * ActionContext.getContext().getSession().get("verifyCode"))) {
     * this.getRequest().setAttribute("message", "验证码错误!"); return ERROR; }
     */
    // 登录次数限制及验证
    if (users == null) {
      this.getRequest().setAttribute("message", "用户名或密码错误!");
      return ERROR;
    } else if (!MasPasswordTool.getDesString(users.getPassword(), users.getAccount())
        .equals(this.getLoginPwd())) {
      String message = "用户名或密码错误!";
      if (LoginCheckUtil.isAccountlock(getSession(), users)) {
        UserVO uvo = users;
        uvo.setLockFlag(1);
        uvo.setActiveFlag(0);
        uvo.setPassword(MasPasswordTool.getDesString(users.getPassword(), users.getAccount()));
        userService.updateUser(uvo);
        message = "用户已被锁定,请联系管理员!";
      }
      this.getRequest().setAttribute("message", message);
      return ERROR;
    } else if (users.getLockFlag() == 1) {
      this.getRequest().setAttribute("message", "用户已被锁定,请联系管理员!");
      return ERROR;
    }
    // 当此用户的鉴权方式为用户名或密码时,将不在验证手机号、/
    if (users.getLoginType() != 1)
      // 手机验证码
      if (!StringUtils.endsWithIgnoreCase(
          getMobileChecking(),
          (String)
              ActionContext.getContext()
                  .getSession()
                  .get(ApSmsConstants.SESSION_SMS_CHECKING_NUMBER))) {
        this.getRequest().setAttribute("message", "手机验证码错误!");
        return ERROR;
      } else {
        // 清空手机验证码
        ActionContext.getContext().getSession().remove(ApSmsConstants.SESSION_SMS_CHECKING_NUMBER);
      }
    // 获取用户菜单
    super.getSession().setAttribute(ApSmsConstants.SESSION_USER_INFO, users);
    Set<RoleVO> roleVOs = users.getRoles();
    Set<Resources> tempResources = null;
    for (RoleVO roleVO : roleVOs) {
      Set<Resources> parentResources = roleVO.getResources();
      if (tempResources == null) {
        tempResources = parentResources;
      } else {
        tempResources.addAll(parentResources);
        for (Resources resource : tempResources) {
          for (Resources undoResource : parentResources) {
            if (resource.getId() == undoResource.getId()) {
              resource.getSubResources().addAll(undoResource.getSubResources());
            }
          }
        }
      }
    }
    if (tempResources == null || tempResources.isEmpty()) {
      this.getRequest().setAttribute("message", "对不起,用户未被赋予访问系统权限!");
      return ERROR;
    }

    List<Resources> resList = new ArrayList<Resources>();
    ResourcesComparator comparator = new ResourcesComparator();
    // 排序二级菜单
    List<Resources> tempList = new ArrayList<Resources>(tempResources);
    for (Resources res : tempList) {
      // 只保留一级菜单 非管理功能菜单
      if (res.getParentId() > 0 || res.getIsManagementFun() == 1) {
        continue;
      }
      if (res.getSubResources() != null) {
        List<Resources> subList = new ArrayList<Resources>(res.getSubResources());
        Collections.sort(subList, comparator);
        res.setSortedSubRes(subList);
        resList.add(res);
      }
    }
    // 排序主菜单
    Collections.sort(resList, comparator);
    ActionContext.getContext().getSession().put("resources", resList);
    return "success";
  }