mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-24 17:45:56 +00:00
feat:增加前台会员登录验证码开关配置项
This commit is contained in:
parent
f9ba167a55
commit
b1ec15a521
@ -39,6 +39,8 @@ class User extends Frontend
|
|||||||
], $this->auth::LOGIN_RESPONSE_CODE);
|
], $this->auth::LOGIN_RESPONSE_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$userLoginCaptchaSwitch = Config::get('buildadmin.user_login_captcha');
|
||||||
|
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$params = $this->request->post(['tab', 'email', 'mobile', 'username', 'password', 'keep', 'captcha', 'captchaId', 'captchaInfo', 'registerType']);
|
$params = $this->request->post(['tab', 'email', 'mobile', 'username', 'password', 'keep', 'captcha', 'captchaId', 'captchaInfo', 'registerType']);
|
||||||
if (!in_array($params['tab'], ['login', 'register'])) {
|
if (!in_array($params['tab'], ['login', 'register'])) {
|
||||||
@ -53,9 +55,11 @@ class User extends Frontend
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($params['tab'] == 'login') {
|
if ($params['tab'] == 'login') {
|
||||||
$captchaObj = new ClickCaptcha();
|
if ($userLoginCaptchaSwitch) {
|
||||||
if (!$captchaObj->check($params['captchaId'], $params['captchaInfo'])) {
|
$captchaObj = new ClickCaptcha();
|
||||||
$this->error(__('Captcha error'));
|
if (!$captchaObj->check($params['captchaId'], $params['captchaInfo'])) {
|
||||||
|
$this->error(__('Captcha error'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$res = $this->auth->login($params['username'], $params['password'], (bool)$params['keep']);
|
$res = $this->auth->login($params['username'], $params['password'], (bool)$params['keep']);
|
||||||
} elseif ($params['tab'] == 'register') {
|
} elseif ($params['tab'] == 'register') {
|
||||||
@ -79,6 +83,7 @@ class User extends Frontend
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->success('', [
|
$this->success('', [
|
||||||
|
'userLoginCaptchaSwitch' => $userLoginCaptchaSwitch,
|
||||||
'accountVerificationType' => get_account_verification_type()
|
'accountVerificationType' => get_account_verification_type()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace app\api\validate;
|
namespace app\api\validate;
|
||||||
|
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
use think\facade\Config;
|
||||||
|
|
||||||
class User extends Validate
|
class User extends Validate
|
||||||
{
|
{
|
||||||
@ -13,7 +14,9 @@ class User extends Validate
|
|||||||
'email' => 'email|unique:user',
|
'email' => 'email|unique:user',
|
||||||
'mobile' => 'mobile|unique:user',
|
'mobile' => 'mobile|unique:user',
|
||||||
'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
|
'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
|
||||||
|
// 注册邮箱或手机验证码
|
||||||
'captcha' => 'require',
|
'captcha' => 'require',
|
||||||
|
// 登录点选验证码
|
||||||
'captchaId' => 'require',
|
'captchaId' => 'require',
|
||||||
'captchaInfo' => 'require',
|
'captchaInfo' => 'require',
|
||||||
];
|
];
|
||||||
@ -22,10 +25,26 @@ class User extends Validate
|
|||||||
* 验证场景
|
* 验证场景
|
||||||
*/
|
*/
|
||||||
protected $scene = [
|
protected $scene = [
|
||||||
'login' => ['password', 'captchaId', 'captchaInfo'],
|
'register' => ['username', 'password', 'email', 'mobile', 'captcha'],
|
||||||
'register' => ['email', 'username', 'password', 'mobile', 'captcha'],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录验证场景
|
||||||
|
*/
|
||||||
|
public function sceneLogin(): User
|
||||||
|
{
|
||||||
|
$fields = ['username', 'password'];
|
||||||
|
|
||||||
|
// 根据系统配置的登录验证码开关调整验证场景的字段
|
||||||
|
$userLoginCaptchaSwitch = Config::get('buildadmin.user_login_captcha');
|
||||||
|
if ($userLoginCaptchaSwitch) {
|
||||||
|
$fields[] = 'captchaId';
|
||||||
|
$fields[] = 'captchaInfo';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->only($fields)->remove('username', ['regex', 'unique']);
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->field = [
|
$this->field = [
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
return [
|
return [
|
||||||
// 允许跨域访问的域名
|
// 允许跨域访问的域名
|
||||||
'cors_request_domain' => 'localhost,127.0.0.1',
|
'cors_request_domain' => 'localhost,127.0.0.1',
|
||||||
|
// 是否开启会员登录验证码
|
||||||
|
'user_login_captcha' => true,
|
||||||
// 是否开启管理员登录验证码
|
// 是否开启管理员登录验证码
|
||||||
'admin_login_captcha' => true,
|
'admin_login_captcha' => true,
|
||||||
// 会员登录失败可重试次数,false则无限
|
// 会员登录失败可重试次数,false则无限
|
||||||
|
@ -316,6 +316,7 @@ interface State {
|
|||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
dialogWidth: number
|
dialogWidth: number
|
||||||
|
userLoginCaptchaSwitch: boolean
|
||||||
accountVerificationType: string[]
|
accountVerificationType: string[]
|
||||||
codeSendCountdown: number
|
codeSendCountdown: number
|
||||||
submitRetrieveLoading: boolean
|
submitRetrieveLoading: boolean
|
||||||
@ -345,6 +346,7 @@ const state: State = reactive({
|
|||||||
password: '',
|
password: '',
|
||||||
},
|
},
|
||||||
dialogWidth: 36,
|
dialogWidth: 36,
|
||||||
|
userLoginCaptchaSwitch: true,
|
||||||
accountVerificationType: [],
|
accountVerificationType: [],
|
||||||
codeSendCountdown: 0,
|
codeSendCountdown: 0,
|
||||||
submitRetrieveLoading: false,
|
submitRetrieveLoading: false,
|
||||||
@ -398,7 +400,7 @@ const resize = () => {
|
|||||||
const onSubmitPre = () => {
|
const onSubmitPre = () => {
|
||||||
formRef.value?.validate((valid) => {
|
formRef.value?.validate((valid) => {
|
||||||
if (!valid) return
|
if (!valid) return
|
||||||
if (state.form.tab == 'login') {
|
if (state.form.tab == 'login' && state.userLoginCaptchaSwitch) {
|
||||||
clickCaptcha(state.form.captchaId, (captchaInfo: string) => onSubmit(captchaInfo))
|
clickCaptcha(state.form.captchaId, (captchaInfo: string) => onSubmit(captchaInfo))
|
||||||
} else {
|
} else {
|
||||||
onSubmit()
|
onSubmit()
|
||||||
@ -510,6 +512,7 @@ onMounted(async () => {
|
|||||||
useEventListener(window, 'resize', resize)
|
useEventListener(window, 'resize', resize)
|
||||||
|
|
||||||
checkIn('get').then((res) => {
|
checkIn('get').then((res) => {
|
||||||
|
state.userLoginCaptchaSwitch = res.data.userLoginCaptchaSwitch
|
||||||
state.accountVerificationType = res.data.accountVerificationType
|
state.accountVerificationType = res.data.accountVerificationType
|
||||||
state.retrievePasswordForm.type = res.data.accountVerificationType.length > 0 ? res.data.accountVerificationType[0] : ''
|
state.retrievePasswordForm.type = res.data.accountVerificationType.length > 0 ? res.data.accountVerificationType[0] : ''
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user