| | |
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.sign.Base64;
|
| | | import com.ruoyi.common.utils.uuid.IdUtils;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | |
|
| | | /**
|
| | | * 验证码操作处理
|
| | |
| | | @Value("${ruoyi.captchaType}")
|
| | | private String captchaType;
|
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | | /**
|
| | | * 生成验证码
|
| | | */
|
| | | @GetMapping("/captchaImage")
|
| | | public AjaxResult getCode(HttpServletResponse response) throws IOException
|
| | | {
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | boolean captchaOnOff = configService.selectCaptchaOnOff();
|
| | | ajax.put("captchaOnOff", captchaOnOff);
|
| | | if (!captchaOnOff)
|
| | | {
|
| | | return ajax;
|
| | | }
|
| | |
|
| | | // 保存验证码信息
|
| | | String uuid = IdUtils.simpleUUID();
|
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
| | |
| | | return AjaxResult.error(e.getMessage());
|
| | | }
|
| | |
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | ajax.put("uuid", uuid);
|
| | | ajax.put("img", Base64.encode(os.toByteArray()));
|
| | | return ajax;
|
| | |
| | | import com.ruoyi.common.utils.ip.IpUtils;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | |
| | | @Autowired
|
| | | private ISysUserService userService;
|
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | /**
|
| | | * 登录验证
|
| | | *
|
| | |
| | | */
|
| | | public String login(String username, String password, String code, String uuid)
|
| | | {
|
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
| | | String captcha = redisCache.getCacheObject(verifyKey);
|
| | | redisCache.deleteObject(verifyKey);
|
| | | if (captcha == null)
|
| | | boolean captchaOnOff = configService.selectCaptchaOnOff();
|
| | | // 验证码开关
|
| | | if (captchaOnOff)
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
|
| | | throw new CaptchaExpireException();
|
| | | }
|
| | | if (!code.equalsIgnoreCase(captcha))
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
| | | throw new CaptchaException();
|
| | | validateCapcha(username, code, uuid);
|
| | | }
|
| | | // 用户验证
|
| | | Authentication authentication = null;
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 校验验证码
|
| | | * |
| | | * @param username 用户名
|
| | | * @param code 验证码
|
| | | * @param uuid 唯一标识
|
| | | * @return 结果
|
| | | */
|
| | | public void validateCapcha(String username, String code, String uuid)
|
| | | {
|
| | | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
| | | String captcha = redisCache.getCacheObject(verifyKey);
|
| | | redisCache.deleteObject(verifyKey);
|
| | | if (captcha == null)
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
|
| | | throw new CaptchaExpireException();
|
| | | }
|
| | | if (!code.equalsIgnoreCase(captcha))
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
| | | throw new CaptchaException();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 记录登录信息
|
| | | */
|
| | | public void recordLoginInfo(SysUser user)
|
| | |
| | | public String selectConfigByKey(String configKey);
|
| | |
|
| | | /**
|
| | | * 获取验证码开关
|
| | | * |
| | | * @return true开启,false关闭
|
| | | */
|
| | | public boolean selectCaptchaOnOff();
|
| | |
|
| | | /**
|
| | | * 查询参数配置列表
|
| | | *
|
| | | * @param config 参数配置信息
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 获取验证码开关
|
| | | * |
| | | * @return true开启,false关闭
|
| | | */
|
| | | public boolean selectCaptchaOnOff()
|
| | | {
|
| | | String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
|
| | | if (StringUtils.isEmpty(captchaOnOff))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return Convert.toBool(captchaOnOff);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询参数配置列表
|
| | | *
|
| | | * @param config 参数配置信息
|
| | |
| | | <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
| | | </el-input>
|
| | | </el-form-item>
|
| | | <el-form-item prop="code">
|
| | | <el-form-item prop="code" v-if="captchaOnOff">
|
| | | <el-input
|
| | | v-model="loginForm.code"
|
| | | auto-complete="off"
|
| | |
| | | code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
|
| | | },
|
| | | loading: false,
|
| | | captchaOnOff: true,
|
| | | redirect: undefined
|
| | | };
|
| | | },
|
| | |
| | | methods: {
|
| | | getCode() {
|
| | | getCodeImg().then(res => {
|
| | | this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
| | | if (this.captchaOnOff) {
|
| | | this.codeUrl = "data:image/gif;base64," + res.img;
|
| | | this.loginForm.uuid = res.uuid;
|
| | | }
|
| | | });
|
| | | },
|
| | | getCookie() {
|
| | |
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
| | | }).catch(() => {
|
| | | this.loading = false;
|
| | | if (this.captchaOnOff) {
|
| | | this.getCode();
|
| | | }
|
| | | });
|
| | | }
|
| | | });
|
文件名从 sql/ry_20210210.sql 修改 |
| | |
| | | insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
| | | insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' );
|
| | | insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
| | | insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启登录验证码功能(true开启,false关闭)'); |
| | |
|
| | |
|
| | | -- ----------------------------
|