Java Code Examples for com.wf.captcha.utils.CaptchaUtil#ver()
The following examples show how to use
com.wf.captcha.utils.CaptchaUtil#ver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainController.java From easyweb-shiro with MIT License | 6 votes |
/** * 登录 */ @ResponseBody @PostMapping("/login") public JsonResult doLogin(String username, String password, String code, HttpServletRequest request) { if (StringUtil.isBlank(username, password)) { return JsonResult.error("账号密码不能为空"); } if (!CaptchaUtil.ver(code, request)) { CaptchaUtil.clear(request); return JsonResult.error("验证码不正确"); } try { UsernamePasswordToken token = new UsernamePasswordToken(username, password); SecurityUtils.getSubject().login(token); addLoginRecord(getLoginUserId(), request); return JsonResult.ok("登录成功"); } catch (IncorrectCredentialsException ice) { return JsonResult.error("密码错误"); } catch (UnknownAccountException uae) { return JsonResult.error("账号不存在"); } catch (LockedAccountException e) { return JsonResult.error("账号被锁定"); } catch (ExcessiveAttemptsException eae) { return JsonResult.error("操作频繁,请稍后再试"); } }
Example 2
Source File: UserController.java From MOOC with MIT License | 6 votes |
@RequestMapping(value = "quickregist") // 快速注册 public ModelAndView insertUser(String varcode, User user, HttpSession session, HttpServletRequest req, ModelAndView mav) { String id = DateUtil.getId(); String username = user.getUsername(); mav.setViewName("redirect:course"); if (varcode == null) { return mav; } if (userBiz.selectUser(username) == 1 || !CaptchaUtil.ver(varcode, req)) { return mav; } user.setId(id); user.setMission(null); user.setBuycase(null); user.setMycase(null); user.setVip(null); userBiz.insertSelective(user); session.setAttribute("loginUser", user); setlog(user, req.getRemoteAddr(), "快速注册"); return mav; }
Example 3
Source File: UserController.java From MOOC with MIT License | 6 votes |
@RequestMapping(value = "regist") // 注册 public ModelAndView regist(ModelAndView mav, String varcode, User user, HttpSession session, HttpServletRequest req) { String id = DateUtil.getId(); String username = user.getUsername(); mav.setViewName("redirect:course"); if (varcode == null) { return mav; } if (userBiz.selectUser(username) == 1 || !CaptchaUtil.ver(varcode, req)) { return mav; } user.setId(id); user.setMission(null); user.setBuycase(null); user.setMycase(null); user.setVip(null); userBiz.insertSelective(user); setlog(user, req.getRemoteAddr(), "普通注册"); return mav; }
Example 4
Source File: LoginController.java From kvf-admin with MIT License | 5 votes |
@Log("登录") @PostMapping(value = "login") public R login(@RequestParam("username") String username, @RequestParam("password") String password, boolean rememberMe, String vercode) { // 只有开启了验证码功能才需要验证。可在yml配置kvf.login.authcode.enable来开启或关闭 if (needAuthCode) { // 验证码校验 HttpServletRequest request = HttpServletContextKit.getHttpServletRequest(); if (!CaptchaUtil.ver(vercode, request)) { CaptchaUtil.clear(request); // 清除session中的验证码 return R.fail("验证码不正确"); } } try { Subject subject = ShiroKit.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe); subject.login(token); ShiroKit.setSessionAttribute("user", username); } catch (Exception e) { LOGGER.error(e.getMessage(), e); return R.fail(e.getMessage()); } return R.ok(); }
Example 5
Source File: MainController.java From MOOC with MIT License | 5 votes |
@RequestMapping(value = "varcodecheck")//验证码验证 public void varcodecheck(String varcode,HttpServletRequest req,HttpServletResponse res) throws IOException { res.setCharacterEncoding("utf-8"); PrintWriter pw = res.getWriter(); /*String var = (String) session.getAttribute("varcodenumber");*/ if(!CaptchaUtil.ver(varcode, req)){ pw.write("0"); } }
Example 6
Source File: LoginControll.java From rebuild with GNU General Public License v3.0 | 5 votes |
@RequestMapping("user-login") public void userLogin(HttpServletRequest request, HttpServletResponse response) { String vcode = getParameter(request, "vcode"); Boolean needVcode = (Boolean) ServletUtils.getSessionAttribute(request, NEED_VCODE); if (needVcode != null && needVcode && (StringUtils.isBlank(vcode) || !CaptchaUtil.ver(vcode, request))) { writeFailure(response, lang("InputWrong", "Captcha")); return; } final String user = getParameterNotNull(request, "user"); final String password = ServletUtils.getRequestString(request); int retry = getLoginRetryTimes(user, 1); if (retry > 3 && StringUtils.isBlank(vcode)) { ServletUtils.setSessionAttribute(request, NEED_VCODE, true); writeFailure(response, "VCODE"); return; } String hasError = LoginToken.checkUser(user, password); if (hasError != null) { writeFailure(response, hasError); return; } User loginUser = Application.getUserStore().getUser(user); loginSuccessed(request, response, loginUser.getId(), getBoolParameter(request, "autoLogin", false)); // 清理 getLoginRetryTimes(user, -1); ServletUtils.setSessionAttribute(request, NEED_VCODE, null); writeSuccess(response); }