Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
7b894da4
提交
7b894da4
authored
7月 13, 2021
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
参数管理支持配置验证码开关
上级
c8b66f9b
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
77 行增加
和
17 行删除
+77
-17
CaptchaController.java
...va/com/ruoyi/web/controller/common/CaptchaController.java
+12
-2
SysLoginService.java
...java/com/ruoyi/framework/web/service/SysLoginService.java
+33
-11
ISysConfigService.java
...main/java/com/ruoyi/system/service/ISysConfigService.java
+7
-0
SysConfigServiceImpl.java
...a/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+15
-0
login.vue
ruoyi-ui/src/views/login.vue
+10
-4
ry_20210713.sql
sql/ry_20210713.sql
+0
-0
没有找到文件。
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
浏览文件 @
7b894da4
...
@@ -17,6 +17,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
...
@@ -17,6 +17,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
import
com.ruoyi.common.core.redis.RedisCache
;
import
com.ruoyi.common.core.redis.RedisCache
;
import
com.ruoyi.common.utils.sign.Base64
;
import
com.ruoyi.common.utils.sign.Base64
;
import
com.ruoyi.common.utils.uuid.IdUtils
;
import
com.ruoyi.common.utils.uuid.IdUtils
;
import
com.ruoyi.system.service.ISysConfigService
;
/**
/**
* 验证码操作处理
* 验证码操作处理
...
@@ -38,13 +39,23 @@ public class CaptchaController
...
@@ -38,13 +39,23 @@ public class CaptchaController
// 验证码类型
// 验证码类型
@Value
(
"${ruoyi.captchaType}"
)
@Value
(
"${ruoyi.captchaType}"
)
private
String
captchaType
;
private
String
captchaType
;
@Autowired
private
ISysConfigService
configService
;
/**
/**
* 生成验证码
* 生成验证码
*/
*/
@GetMapping
(
"/captchaImage"
)
@GetMapping
(
"/captchaImage"
)
public
AjaxResult
getCode
(
HttpServletResponse
response
)
throws
IOException
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
uuid
=
IdUtils
.
simpleUUID
();
String
verifyKey
=
Constants
.
CAPTCHA_CODE_KEY
+
uuid
;
String
verifyKey
=
Constants
.
CAPTCHA_CODE_KEY
+
uuid
;
...
@@ -78,7 +89,6 @@ public class CaptchaController
...
@@ -78,7 +89,6 @@ public class CaptchaController
return
AjaxResult
.
error
(
e
.
getMessage
());
return
AjaxResult
.
error
(
e
.
getMessage
());
}
}
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"uuid"
,
uuid
);
ajax
.
put
(
"uuid"
,
uuid
);
ajax
.
put
(
"img"
,
Base64
.
encode
(
os
.
toByteArray
()));
ajax
.
put
(
"img"
,
Base64
.
encode
(
os
.
toByteArray
()));
return
ajax
;
return
ajax
;
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
浏览文件 @
7b894da4
...
@@ -21,6 +21,7 @@ import com.ruoyi.common.utils.ServletUtils;
...
@@ -21,6 +21,7 @@ import com.ruoyi.common.utils.ServletUtils;
import
com.ruoyi.common.utils.ip.IpUtils
;
import
com.ruoyi.common.utils.ip.IpUtils
;
import
com.ruoyi.framework.manager.AsyncManager
;
import
com.ruoyi.framework.manager.AsyncManager
;
import
com.ruoyi.framework.manager.factory.AsyncFactory
;
import
com.ruoyi.framework.manager.factory.AsyncFactory
;
import
com.ruoyi.system.service.ISysConfigService
;
import
com.ruoyi.system.service.ISysUserService
;
import
com.ruoyi.system.service.ISysUserService
;
/**
/**
...
@@ -43,6 +44,9 @@ public class SysLoginService
...
@@ -43,6 +44,9 @@ public class SysLoginService
@Autowired
@Autowired
private
ISysUserService
userService
;
private
ISysUserService
userService
;
@Autowired
private
ISysConfigService
configService
;
/**
/**
* 登录验证
* 登录验证
*
*
...
@@ -54,18 +58,11 @@ public class SysLoginService
...
@@ -54,18 +58,11 @@ public class SysLoginService
*/
*/
public
String
login
(
String
username
,
String
password
,
String
code
,
String
uuid
)
public
String
login
(
String
username
,
String
password
,
String
code
,
String
uuid
)
{
{
String
verifyKey
=
Constants
.
CAPTCHA_CODE_KEY
+
uuid
;
boolean
captchaOnOff
=
configService
.
selectCaptchaOnOff
();
String
captcha
=
redisCache
.
getCacheObject
(
verifyKey
);
// 验证码开关
redisCache
.
deleteObject
(
verifyKey
);
if
(
captchaOnOff
)
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"
)));
validateCapcha
(
username
,
code
,
uuid
);
throw
new
CaptchaException
();
}
}
// 用户验证
// 用户验证
Authentication
authentication
=
null
;
Authentication
authentication
=
null
;
...
@@ -95,6 +92,31 @@ public class SysLoginService
...
@@ -95,6 +92,31 @@ public class SysLoginService
return
tokenService
.
createToken
(
loginUser
);
return
tokenService
.
createToken
(
loginUser
);
}
}
/**
* 校验验证码
*
* @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
();
}
}
/**
/**
* 记录登录信息
* 记录登录信息
*/
*/
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
浏览文件 @
7b894da4
...
@@ -26,6 +26,13 @@ public interface ISysConfigService
...
@@ -26,6 +26,13 @@ public interface ISysConfigService
*/
*/
public
String
selectConfigByKey
(
String
configKey
);
public
String
selectConfigByKey
(
String
configKey
);
/**
* 获取验证码开关
*
* @return true开启,false关闭
*/
public
boolean
selectCaptchaOnOff
();
/**
/**
* 查询参数配置列表
* 查询参数配置列表
*
*
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
浏览文件 @
7b894da4
...
@@ -80,6 +80,21 @@ public class SysConfigServiceImpl implements ISysConfigService
...
@@ -80,6 +80,21 @@ public class SysConfigServiceImpl implements ISysConfigService
return
StringUtils
.
EMPTY
;
return
StringUtils
.
EMPTY
;
}
}
/**
* 获取验证码开关
*
* @return true开启,false关闭
*/
public
boolean
selectCaptchaOnOff
()
{
String
captchaOnOff
=
selectConfigByKey
(
"sys.account.captchaOnOff"
);
if
(
StringUtils
.
isEmpty
(
captchaOnOff
))
{
return
true
;
}
return
Convert
.
toBool
(
captchaOnOff
);
}
/**
/**
* 查询参数配置列表
* 查询参数配置列表
*
*
...
...
ruoyi-ui/src/views/login.vue
浏览文件 @
7b894da4
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
<svg-icon
slot=
"prefix"
icon-class=
"password"
class=
"el-input__icon input-icon"
/>
<svg-icon
slot=
"prefix"
icon-class=
"password"
class=
"el-input__icon input-icon"
/>
</el-input>
</el-input>
</el-form-item>
</el-form-item>
<el-form-item
prop=
"code"
>
<el-form-item
prop=
"code"
v-if=
"captchaOnOff"
>
<el-input
<el-input
v-model=
"loginForm.code"
v-model=
"loginForm.code"
auto-complete=
"off"
auto-complete=
"off"
...
@@ -81,6 +81,7 @@ export default {
...
@@ -81,6 +81,7 @@ export default {
code
:
[{
required
:
true
,
trigger
:
"change"
,
message
:
"验证码不能为空"
}]
code
:
[{
required
:
true
,
trigger
:
"change"
,
message
:
"验证码不能为空"
}]
},
},
loading
:
false
,
loading
:
false
,
captchaOnOff
:
true
,
redirect
:
undefined
redirect
:
undefined
};
};
},
},
...
@@ -99,8 +100,11 @@ export default {
...
@@ -99,8 +100,11 @@ export default {
methods
:
{
methods
:
{
getCode
()
{
getCode
()
{
getCodeImg
().
then
(
res
=>
{
getCodeImg
().
then
(
res
=>
{
this
.
codeUrl
=
"data:image/gif;base64,"
+
res
.
img
;
this
.
captchaOnOff
=
res
.
captchaOnOff
===
undefined
?
true
:
res
.
captchaOnOff
;
this
.
loginForm
.
uuid
=
res
.
uuid
;
if
(
this
.
captchaOnOff
)
{
this
.
codeUrl
=
"data:image/gif;base64,"
+
res
.
img
;
this
.
loginForm
.
uuid
=
res
.
uuid
;
}
});
});
},
},
getCookie
()
{
getCookie
()
{
...
@@ -130,7 +134,9 @@ export default {
...
@@ -130,7 +134,9 @@ export default {
this
.
$router
.
push
({
path
:
this
.
redirect
||
"/"
}).
catch
(()
=>
{});
this
.
$router
.
push
({
path
:
this
.
redirect
||
"/"
}).
catch
(()
=>
{});
}).
catch
(()
=>
{
}).
catch
(()
=>
{
this
.
loading
=
false
;
this
.
loading
=
false
;
this
.
getCode
();
if
(
this
.
captchaOnOff
)
{
this
.
getCode
();
}
});
});
}
}
});
});
...
...
sql/ry_20210
210
.sql
→
sql/ry_20210
713
.sql
浏览文件 @
7b894da4
This source diff could not be displayed because it is too large. You can
view the blob
instead.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论