@Override
  public BindIDCardResponse bindIDCardForUser(String iDCard, User user) {
    BindIDCardResponse bindIDCardResponse = new BindIDCardResponse();
    ReturnStatus succStatus =
        statusRepository.getSystemStatusBySystemKey(SystemStatusKeyNames.BindIDCard.SUCC);
    ReturnStatus failStatus =
        statusRepository.getSystemStatusBySystemKey(SystemStatusKeyNames.BindIDCard.FAIL);
    bindIDCardResponse.setReturnStatus(failStatus);
    try {
      if (null != user && StringUtils.isNotBlank(iDCard)) {
        if (userService.idNumberBindToUser(iDCard)) {
          ReturnStatus idNumberIsBindToUserStatus =
              statusRepository.getSystemStatusBySystemKey(
                  SystemStatusKeyNames.BindIDCard.ID_CARD_HAVE_BINDED);
          bindIDCardResponse.setReturnStatus(idNumberIsBindToUserStatus);
        } else {
          com.xhcms.lottery.commons.data.User user4Update =
              userService.getUser(Long.parseLong(user.getId()));
          if (StringUtils.isBlank(user4Update.getIdNumber())) {
            user4Update.setIdNumber(iDCard);
            userManager.updateIDNumber(user4Update);
            bindIDCardResponse.setReturnStatus(succStatus);
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      logger.error("绑定身份证时出现异常:{}", e.getMessage());
      bindIDCardResponse.setReturnStatus(failStatus);
    }
    return bindIDCardResponse;
  }
Beispiel #2
0
  @Override
  public String execute() {
    if (isPost()) {

      if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {

        addActionError("用户名或者密码错误!");
        return LOGIN;
      }

      // if user is not exists
      User user = userServiceCache.getUserByUsername(username);
      if (null == user) {
        addActionError("用户不存在");
        return LOGIN;
      }
      // 默认类型为用户名登录
      if (null == loginType) {
        loginType = EnumLoginType.USERNAME.getValue();
      }

      String pwd = Text.MD5Encode(password);
      // 判断用户密码 和 登录状态
      if (pwd.equals(user.getPassword())
          && user.getStatus() != EnumLoginStatus.STATUS_DISABLE.getValue()) {

        request.getSession().setAttribute(Constant.USER_KEY, user);
        request.getSession().setAttribute(Constant.USER_LASTLOGINTIME, user.getLastLoginTime());

        String usernameCookieValue;
        String pwdCookieValue;
        try {
          usernameCookieValue =
              CryptoUitls.encrypt(user.getUsername(), CryptoUitls.USERNAME_SIGNATURE);
          userNameCookieGenerator.addCookie(request, response, usernameCookieValue);
          pwdCookieValue = CryptoUitls.encrypt(password, CryptoUitls.PASSWORD_SIGNATURE);
          pwdCookieGenerator.addCookie(request, response, pwdCookieValue);

        } catch (Exception e) {
          log.error(e.getMessage());
          return LOGIN;
        }

        if (StringUtils.isNotEmpty(referer) && referer.startsWith("http://")) {
          return "referer";
        }
        return SUCCESS;
      } else {
        addActionError("用户名或密码错误!");
      }
    } else {

      String encryptUserName = userNameCookieGenerator.getCookieValue(request);
      String encryptPassword = pwdCookieGenerator.getCookieValue(request);
      if (StringUtils.isNotBlank(encryptUserName) && StringUtils.isNotBlank(encryptPassword)) {
        try {
          username = CryptoUitls.decrypt(encryptUserName, CryptoUitls.USERNAME_SIGNATURE);
          password = CryptoUitls.decrypt(encryptPassword, CryptoUitls.PASSWORD_SIGNATURE);
        } catch (Exception e) {
          // do nothing   如果有异常,就不自动填充用户名和密码
        }
      }
    }
    if (request.getSession().getAttribute(Constant.USER_KEY) != null) {
      // 如果已登录,则跳转到index.do
      return SUCCESS;
    }
    return LOGIN;
  }