Exemplo n.º 1
0
  /** @Description: 用户端登录 @Created Time: 2013-3-29 上午11:29:36 @Author lys */
  public void teacherLogin() {
    try {
      ServiceResult result = new ServiceResult(false);
      String captchaID = request.getSession().getId();
      String challengeResponse =
          StringUtils.upperCase(request.getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME));

      if (StringUtils.isEmpty(challengeResponse)
          || captchaService.validateResponseForID(captchaID, challengeResponse) == false) {
        result.setMessage("验证码错误");
        ajaxJson(result.toJSON());
        return;
      }
      // 根据用户名和密码判断是否允许登录
      Teacher loginTeacher = teacherService.login(userCode, MD5Util.getMD5(userPwd));
      if (null == loginTeacher) {
        result.setMessage("用户名或密码错误!!");
      } else {
        setSession(Teacher.LOGIN_TEACHERID, loginTeacher.getTeacherId());
        setSession(Teacher.LOGIN_TEACHERName, loginTeacher.getTeacherName());
        setSession(LoginType.LOGINTYPE, LoginType.TEACHER);
        result.setIsSuccess(true);
      }
      String ajaxString = result.toJSON();
      ajaxJson(ajaxString);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /** @Description: 学生登陆 @Created Time: 2013-5-9 下午4:08:03 @Author lys */
  public void studentLogin() {
    try {
      ServiceResult result = new ServiceResult(false);
      String captchaID = request.getSession().getId();
      String challengeResponse =
          StringUtils.upperCase(request.getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME));

      if (StringUtils.isEmpty(challengeResponse)
          || captchaService.validateResponseForID(captchaID, challengeResponse) == false) {
        result.setMessage("验证码错误");
        ajaxJson(result.toJSON());
        return;
      }
      // 根据用户名和密码判断是否允许登录
      Student loginStudent = studentService.login(userCode, MD5Util.getMD5(userPwd));
      if (null == loginStudent) {
        result.setMessage("用户名或密码错误或未注册激活!!");
      } else {
        setSession(Student.LOGIN_ID, loginStudent.getStudentId());
        setSession(Student.LOGIN_NAME, loginStudent.getStudentName());
        setSession(LoginType.LOGINTYPE, LoginType.STUDENT);
        result.addData("studentId", loginStudent.getStudentId());
        result.addData("studentName", loginStudent.getStudentName());
        result.setIsSuccess(true);
      }
      String ajaxString = result.toJSON();
      ajaxJson(ajaxString);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  /**
   * 根据HttpServletRequest校验验证码
   *
   * @param parameterName 参数名称
   * @return 是否验证通过
   */
  public static boolean validateCaptchaByRequest(HttpServletRequest request, String parameterName) {
    String captchaID = request.getSession().getId();
    String challengeResponse = StringUtils.upperCase(request.getParameter(parameterName));

    if (StringUtils.isEmpty(captchaID) || StringUtils.isEmpty(challengeResponse)) {
      return false;
    }

    CaptchaService captchaService = (CaptchaService) SpringUtil.getBean(CAPTCHA_SERVICE_BEAN_NAME);
    try {
      if (captchaService.validateResponseForID(captchaID, challengeResponse)) {
        return true;
      }
    } catch (Exception e) {
    }
    return false;
  }
Exemplo n.º 4
0
  protected boolean validateCaptchaChallenge(final HttpServletRequest request) {
    try {
      String captchaID = request.getSession().getId();
      String challengeResponse = request.getParameter(captchaParamterName);

      return captchaService.validateResponseForID(captchaID, challengeResponse);
    } catch (Exception e) {
      return false;
    }
  }
Exemplo n.º 5
0
  private boolean validateCaptchaChallenge(final HttpServletRequest request) {
    try {
      String captchaID = request.getSession().getId();
      String challengeResponse = request.getParameter(captchaParamterName);

      if (autoPassValue != null && autoPassValue.equals(challengeResponse)) {
        return true;
      }
      return captchaService.validateResponseForID(captchaID, challengeResponse);
    } catch (CaptchaServiceException e) {
      logger.error(e.getMessage(), e);
      return false;
    }
  }
Exemplo n.º 6
0
  private void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    ServletOutputStream out = response.getOutputStream();
    try {
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      ImageIO.write(challenge, "jpg", out);
      out.flush();
    } catch (CaptchaServiceException e) {
      logger.error(e.getMessage(), e);
    } finally {
      out.close();
    }
  }
Exemplo n.º 7
0
  protected void genernateCaptchaImage(
      final HttpServletRequest request, final HttpServletResponse response) {

    ServletUtils.setDisableCacheHeader(response);
    response.setContentType("image/png");
    ServletOutputStream out = null;
    try {
      out = response.getOutputStream();
      String captchaId = request.getSession(true).getId();
      BufferedImage challenge =
          (BufferedImage) captchaService.getChallengeForID(captchaId, request.getLocale());
      // String writerNames[] = ImageIO.getWriterFormatNames();
      ImageIO.write(challenge, "png", out);
      out.flush();
    } catch (IOException | CaptchaServiceException e) {
      log.error("生成验证码出错", e);
    } finally {
      try {
        out.close();
      } catch (IOException e) {
        log.error("生成验证码出错", e);
      }
    }
  }