zoukankan      html  css  js  c++  java
  • 【SSM 验证码】登录验证码

    LoginController
        /**
         * 登陆方法
         */
        @ResponseBody
        @RequestMapping("login2")
        public Map<String, String> login2(UserVo userVo, Model model) {
            Map<String, String> 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>
  • 相关阅读:
    网络基本功(一)细说网络传输
    关于指针的理解
    百度地图定位,标注以及地图中心点问题
    ios 将彩色照片转化成黑白等几种类型
    在 iOS 应用中直接跳转到 AppStore 的方法
    ios中判断当前手机的网络状态
    NTFS 读写高手进阶 Windows 格式硬盘 Mac存文件 开启 ...(转载)
    tableviewcell 中使用autolayout自适应高度
    ios 3D Touch功能的实现
    一些牛人分享的ios技巧,保留着
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12258007.html
Copyright © 2011-2022 走看看