Browse Source

feat: 验证码输入判断逻辑修改 (#842)

pull/854/head
ssongliu 2 years ago committed by GitHub
parent
commit
09d462b829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      backend/app/api/v1/auth.go
  2. 11
      backend/app/dto/auth.go
  3. 3
      cmd/server/docs/docs.go
  4. 3
      cmd/server/docs/swagger.json
  5. 2
      cmd/server/docs/swagger.yaml
  6. 1
      frontend/src/api/interface/auth.ts
  7. 1
      frontend/src/store/index.ts
  8. 1
      frontend/src/store/interface/index.ts
  9. 8
      frontend/src/views/login/components/login-form.vue

2
backend/app/api/v1/auth.go

@ -26,7 +26,7 @@ func (b *BaseApi) Login(c *gin.Context) {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return return
} }
if req.AuthMethod != "jwt" { if req.AuthMethod != "jwt" && !req.IgnoreCaptcha {
if err := captcha.VerifyCode(req.CaptchaID, req.Captcha); err != nil { if err := captcha.VerifyCode(req.CaptchaID, req.Captcha); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return return

11
backend/app/dto/auth.go

@ -17,11 +17,12 @@ type MfaCredential struct {
} }
type Login struct { type Login struct {
Name string `json:"name"` Name string `json:"name"`
Password string `json:"password"` Password string `json:"password"`
Captcha string `json:"captcha"` IgnoreCaptcha bool `json:"ignoreCaptcha"`
CaptchaID string `json:"captchaID"` Captcha string `json:"captcha"`
AuthMethod string `json:"authMethod"` CaptchaID string `json:"captchaID"`
AuthMethod string `json:"authMethod"`
} }
type MFALogin struct { type MFALogin struct {

3
cmd/server/docs/docs.go

@ -11111,6 +11111,9 @@ var doc = `{
"captchaID": { "captchaID": {
"type": "string" "type": "string"
}, },
"ignoreCaptcha": {
"type": "boolean"
},
"name": { "name": {
"type": "string" "type": "string"
}, },

3
cmd/server/docs/swagger.json

@ -11097,6 +11097,9 @@
"captchaID": { "captchaID": {
"type": "string" "type": "string"
}, },
"ignoreCaptcha": {
"type": "boolean"
},
"name": { "name": {
"type": "string" "type": "string"
}, },

2
cmd/server/docs/swagger.yaml

@ -929,6 +929,8 @@ definitions:
type: string type: string
captchaID: captchaID:
type: string type: string
ignoreCaptcha:
type: boolean
name: name:
type: string type: string
password: password:

1
frontend/src/api/interface/auth.ts

@ -2,6 +2,7 @@ export namespace Login {
export interface ReqLoginForm { export interface ReqLoginForm {
name: string; name: string;
password: string; password: string;
ignoreCaptcha: boolean;
captcha: string; captcha: string;
captchaID: string; captchaID: string;
authMethod: string; authMethod: string;

1
frontend/src/store/index.ts

@ -23,6 +23,7 @@ export const GlobalStore = defineStore({
isFullScreen: false, isFullScreen: false,
agreeLicense: false, agreeLicense: false,
hasNewVersion: false, hasNewVersion: false,
ignoreCaptcha: true,
}), }),
getters: {}, getters: {},
actions: { actions: {

1
frontend/src/store/interface/index.ts

@ -19,6 +19,7 @@ export interface GlobalState {
isFullScreen: boolean; isFullScreen: boolean;
agreeLicense: boolean; agreeLicense: boolean;
hasNewVersion: boolean; hasNewVersion: boolean;
ignoreCaptcha: boolean;
} }
export interface MenuState { export interface MenuState {

8
frontend/src/views/login/components/login-form.vue

@ -140,7 +140,7 @@
{{ $t('commons.login.errorAuthInfo') }} {{ $t('commons.login.errorAuthInfo') }}
</span> </span>
</el-form-item> </el-form-item>
<el-form-item prop="captcha" class="login-captcha"> <el-form-item v-if="!globalStore.ignoreCaptcha" prop="captcha" class="login-captcha">
<el-input v-model.trim="loginForm.captcha" :placeholder="$t('commons.login.captchaHelper')"> <el-input v-model.trim="loginForm.captcha" :placeholder="$t('commons.login.captchaHelper')">
<template #prefix> <template #prefix>
<svg-icon style="font-size: 7px" iconName="p-yanzhengma1"></svg-icon> <svg-icon style="font-size: 7px" iconName="p-yanzhengma1"></svg-icon>
@ -239,6 +239,7 @@ const loginFormRef = ref<FormInstance>();
const loginForm = reactive({ const loginForm = reactive({
name: '', name: '',
password: '', password: '',
ignoreCaptcha: true,
captcha: '', captcha: '',
captchaID: '', captchaID: '',
authMethod: '', authMethod: '',
@ -286,11 +287,12 @@ const login = (formEl: FormInstance | undefined) => {
let requestLoginForm = { let requestLoginForm = {
name: loginForm.name, name: loginForm.name,
password: loginForm.password, password: loginForm.password,
ignoreCaptcha: globalStore.ignoreCaptcha,
captcha: loginForm.captcha, captcha: loginForm.captcha,
captchaID: captcha.captchaID, captchaID: captcha.captchaID,
authMethod: '', authMethod: '',
}; };
if (requestLoginForm.captcha == '') { if (!globalStore.ignoreCaptcha && requestLoginForm.captcha == '') {
errCaptcha.value = true; errCaptcha.value = true;
return; return;
} }
@ -308,12 +310,14 @@ const login = (formEl: FormInstance | undefined) => {
errAuthInfo.value = false; errAuthInfo.value = false;
} }
if (res.message === 'ErrAuth') { if (res.message === 'ErrAuth') {
globalStore.ignoreCaptcha = false;
errCaptcha.value = false; errCaptcha.value = false;
errAuthInfo.value = true; errAuthInfo.value = true;
} }
loginVerify(); loginVerify();
return; return;
} }
globalStore.ignoreCaptcha = true;
if (res.data.mfaStatus === 'enable') { if (res.data.mfaStatus === 'enable') {
mfaShow.value = true; mfaShow.value = true;
errMfaInfo.value = false; errMfaInfo.value = false;

Loading…
Cancel
Save