コード例 #1
0
  /** 推广注册2 */
  @RequestMapping(
      value = "/registMemberInfoCollectJson",
      produces = {"text/plain;charset=UTF-8"})
  @ResponseBody
  public String registMemberInfoCollectJson(
      Member member,
      HttpServletRequest request,
      HttpSession session,
      HttpServletResponse response) {
    member.setUsername(CharacterEncoder.decodeURL(member.getUsername(), "UTF-8"));

    MessageBox box = null;

    if (StringUtils.isEmpty(member.getUsername())) {
      box = MessageBox.build("0", "用户名不能为空");
    } else if (verifyUserNameLength(member)) {
      box = MessageBox.build("0", "用户名称长度应该位于2~16位之间");
    } else if (!VerifyContainSpecialChar.isContainSpecialChars(member.getUsername())) {
      box = MessageBox.build("0", "用户名包含特殊字符串");
    } else if (memberRegisterService.existsContainSensitiveForUserName(
        member.getUsername().replaceAll(" ", ""))) {
      box = MessageBox.build("0", "注册用户名包含敏感词");
    } else {
      box = registMemberInfo(member, request, session, response);
    }

    return JsonUtils.bean2Json(box);
  }
コード例 #2
0
  /**
   * Description:发送邮箱验证信息<br>
   *
   * @author hujianpan
   * @version 0.1 2014年8月30日
   * @param request
   * @return String
   */
  @RequestMapping(value = "sendEmailVerifyLink")
  @ResponseBody
  public MessageBox sendEmailVerifyLink(HttpServletRequest request) {
    String destinationEmail = request.getParameter("email");
    Boolean again = Boolean.valueOf(request.getParameter("again")); //
    Member member = currentMember();
    if (null == member || StringUtils.isEmpty(member.getUsername())) {
      return MessageBox.build("0", "发送验证邮箱时出错,当前用户可能已验证,请核对。");
    }
    String result = "";
    try {
      result =
          memberRegisterService.sendEmailLinkActivateMember(
              request, destinationEmail, again, member);
    } catch (Exception e) {
      return MessageBox.build("0", e.getMessage());
    }
    if (!BusinessConstants.SUCCESS.equals(result)) {
      return MessageBox.build("0", result);
    }

    return MessageBox.build("1", "发送验证邮件成功,请去激活!");
  }
コード例 #3
0
  /**
   * Description:登录方法<br>
   *
   * @author justin.xu
   * @version 0.1 2014年5月7日
   * @param request
   * @param session
   * @param response
   * @param memberLoginCnd
   * @return String
   */
  @RequestMapping(value = "/login")
  @ValidateToken
  @ResponseBody
  public MessageBox login(
      HttpSession session, HttpServletResponse response, MemberLoginCnd memberLoginCnd)
      throws AuthenticationException {
    try {
      Object object = session.getAttribute(CSRFTokenManager.CSRF_PARAM_COUNTER);
      if (object != null && ((Integer) (object)).intValue() > 2) {
        if (memberLoginCnd.getCheckCode() == null || "".equals(memberLoginCnd.getCheckCode())) {
          return MessageBox.build("0", "请你输入验证码");
        }
        String randomCode = (String) currentSession().getAttribute("randomCode");
        if (!memberLoginCnd.getCheckCode().equals(randomCode)) {
          return MessageBox.build("0", "验证码不正确");
        }
      }

      long t1 = System.currentTimeMillis();
      logger.info(memberLoginCnd.getUsername() + " ----- login ----- begin time : " + t1);

      // shiro登录
      UsernamePasswordToken token =
          new UsernamePasswordToken(
              memberLoginCnd.getUsername(),
              MD5.toMD5(memberLoginCnd.getPasswd()),
              BusinessConstants.MEMBER_OPERATE_ON_PORTAL);
      Subject subject = SecurityUtils.getSubject();
      subject.login(token);

      long t2 = System.currentTimeMillis();
      logger.info(
          memberLoginCnd.getUsername() + " ----- login ----- shiro login cost : " + (t2 - t1));

      LoginCnd loginCnd = new LoginCnd();
      loginCnd.setUserId(currentUser().getUserId());
      loginCnd.setUserName(currentUser().getUserName());
      loginCnd.setIp(HttpTookit.getRealIpAddr(currentRequest()));
      loginCnd.setSessionId(session.getId());
      loginCnd.setPlatform(currentUser().getPlatform());
      // 调用登录逻辑
      String msg = memberService.saveLogin(loginCnd);

      long t3 = System.currentTimeMillis();
      logger.info(
          memberLoginCnd.getUsername() + " ----- login ----- save login cost : " + (t3 - t2));

      // 用于sso
      cookieRetrievingCookieGenerator.addCookie(
          currentRequest(), response, TicketCryptor.encrypt(currentUser().getSsoTicket()));

      long t4 = System.currentTimeMillis();
      logger.error(
          memberLoginCnd.getUsername() + " ----- login ----- add sso cookie cost : " + (t4 - t3));
      System.out.println(memberLoginCnd.getSaveid() + "hhe");
      // 保存cookie
      if ("1".equals(memberLoginCnd.getSaveid())) {
        CookieGenerator cookieGenerator = new CookieGenerator();
        cookieGenerator.setCookieMaxAge(2147483647);
        cookieGenerator.setCookieName(COOKIE_LOGIN_USERID);
        cookieGenerator.addCookie(response, memberLoginCnd.getCookieusername());
      } else {
        CookieGenerator cookieGenerator = new CookieGenerator();
        cookieGenerator.setCookieMaxAge(0);
        cookieGenerator.setCookieName(COOKIE_LOGIN_USERID);
        cookieGenerator.addCookie(response, memberLoginCnd.getCookieusername());
      }

      long t5 = System.currentTimeMillis();
      logger.error(
          memberLoginCnd.getUsername()
              + " ----- login ----- add username cookie cost : "
              + (t5 - t4));

      // 小红点提示状态
      RedAccount redAccount = redAccountService.queryRedDotState(currentUser().getUserId());
      if (redAccount != null) {
        currentSession().setAttribute("redDot", redAccount);
      }
      // 抽奖机会提醒
      int lotteryChanceCount =
          lotteryChanceInfoService.queryLotteryNumTotal("11", currentUser().getUserId());
      if (lotteryChanceCount > 0) {
        currentSession().setAttribute("lotteryChanceCount", lotteryChanceCount);
      }
      if (BusinessConstants.VISITOR_UNAUTHERIZED.equals(msg)) {
        return MessageBox.build("2", "请先前往认证");
      }

      if (object != null) {
        currentSession().removeAttribute(CSRFTokenManager.CSRF_PARAM_COUNTER);
      }
    } catch (UnknownAccountException e) {
      return MessageBox.build("0", "账户名不存在");
    } catch (IncorrectCredentialsException ice) {
      return MessageBox.build("0", "账户名与密码不匹配");
    } catch (LockedAccountException lae) {
      return MessageBox.build("0", "账户已经锁定");
    } catch (Exception e) {
      if (isLogin()) {
        SecurityUtils.getSubject().logout();
      }
      logger.error("登录失败", e);
      return MessageBox.buildForCounter("3", "账号与密码不匹配");
    }

    String backUrl = memberLoginCnd.getBackUrl();
    if (backUrl != null && !backUrl.trim().equals("")) {
      logger.info("******自动跳转登陆前页面=" + backUrl + "******");
      return MessageBox.build("8", backUrl);
    }

    return MessageBox.build("1", "success");
  }