[SSM 인증번호] 로그인 인증번호

6535 단어
LoginController
    /**
     *     
     */
    @ResponseBody
    @RequestMapping("login2")
    public Map login2(UserVo userVo, Model model) {
        Map res = new HashMap();
        String code = WebUtils.getHttpSession().getAttribute("code").toString();
        if(!userVo.getCode().equals(code)){
            model.addAttribute("error", SysConstast.USER_LOGIN_ERROR_MSG);
            res.put("code", "400");
            res.put("message", "     ");
            return res;
        }
        User user = this.userService.login(userVo);
        if (null == user) {
            model.addAttribute("error", SysConstast.USER_LOGIN_ERROR_MSG);
            res.put("code", "302");
            res.put("address", "../login/toLogin.action");
            return res;
        }
        //  session
        WebUtils.getHttpSession().setAttribute("user", user);
        //        sys_login_log      
        LogInfoVo logInfoVo = new LogInfoVo();
        logInfoVo.setLogintime(new Date());
        logInfoVo.setLoginname(user.getRealname() + "-" + user.getLoginname());
        logInfoVo.setLoginip(WebUtils.getHttpServletRequest().getRemoteAddr());

        logInfoService.addLogInfo(logInfoVo);
        res.put("code", "200");
        res.put("address", "../login/mainIndex.action");
        return res;
    }

    @RequestMapping("mainIndex")
    public String mainIndex() {
        return "system/main/index";
    }

    /**
     *        
     *
     * @throws IOException
     */
    @RequestMapping("getCode")
    public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
        //            
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36, 4, 5);
        session.setAttribute("code", lineCaptcha.getCode());
        ServletOutputStream outputStream = response.getOutputStream();
        ImageIO.write(lineCaptcha.getImage(), "JPEG", outputStream);
    }

 login.jsp
    <div class="layui-form-item input-item" id="imgCode">
        <label for="code">   label>
        <input type="text" placeholder="      " autocomplete="off" name="code" id="code" class="layui-input">
        <img src="${ctx}/login/getCode.action" onclick="this.src=this.src+'?'">
    div>

좋은 웹페이지 즐겨찾기