Skip to content

Commit

Permalink
fix: 解决Mfa认证回车报错的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 committed Jan 11, 2023
1 parent 1e9c550 commit 87e4eca
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/api/v1/mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m *Handler) MfaValidate() iris.Handler {
success := mfaUtil.ValidCode(mfa.Code, mfa.Secret)
if !success {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Values().Set("message", "code is not valid")
ctx.Values().Set("message", "code is invalid")
return
} else {
p.Mfa.Approved = true
Expand Down Expand Up @@ -89,7 +89,7 @@ func (m *Handler) MfaBind() iris.Handler {
success := mfaUtil.ValidCode(mfa.Code, mfa.Secret)
if !success {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Values().Set("message", "code is not valid")
ctx.Values().Set("message", "code is invalid")
return
} else {
session.Delete("profile")
Expand Down
3 changes: 3 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func (e *KubePiServer) setUpErrHandler() {
}

lang := ctx.Values().GetString("language")
if lang == "" {
lang = i18n.LanguageZhCN
}
var (
translateMessage string
err error
Expand Down
1 change: 1 addition & 0 deletions pkg/i18n/cn_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ var zhCNMapping = TextMapping{
"username already exists": "用户名已存在",
"email already exists": "邮箱已存在",
"unable to complete authorization": "无法完成授权,请检查用户名是否符合规范: /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/",
"no login user": "用户未登录",
}
1 change: 1 addition & 0 deletions pkg/i18n/en_us.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ var enUSMapping = TextMapping{
"username already exists": "username already exists",
"email already exists": "email already exists",
"unable to complete authorization": "Unable to complete authorization, please check whether the user name is valid: /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/",
"no login user": "no login user",
}
18 changes: 9 additions & 9 deletions web/kubepi/src/business/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@
<div>
<div>
<span>{{ $t("commons.login.mfa_login_helper") }}</span>
</div>
<div>
<span>Secret:{{ user.secret }}</span>
<br/>
</div>
</div>
<el-form>
<el-form-item class="login">
<el-input v-model="mfaCredential.code"></el-input>
</el-form-item>
</el-form>
<br/>
<el-input class="login" v-model="mfaCredential.code"></el-input>
<div>
<br/>
<el-button type="primary" class="submit" @click="mfaLogin()" size="default">
{{ $t("commons.button.login") }}
</el-button>
Expand Down Expand Up @@ -157,7 +153,11 @@ export default {
watchEnter (e) {
let keyCode = e.keyCode
if (keyCode === 13) {
this.submit("form")
if(this.mfaPage) {
this.mfaLogin()
}else {
this.submit("form")
}
}
},
submit (form) {
Expand Down
2 changes: 1 addition & 1 deletion web/kubepi/src/i18n/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const message = {
welcome: "欢迎回来,请输入用户名和密码登录",
expires: "认证信息已过期,请重新登录",
mfa_helper: "使用 MFA 验证器应用扫描以下二维码,获取6位验证码",
mfa_login_helper: "请输入MFA验证器的6位验证吗",
mfa_login_helper: "请输入MFA验证器的6位验证码",
},
},
business: {
Expand Down
18 changes: 9 additions & 9 deletions web/kubepi/src/plugins/request.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios"
import {$alert, $error} from "./message"
import store from "@/store"
import i18n, {getLanguage} from "@/i18n"
import { $error} from "./message"
// import store from "@/store"
import {getLanguage} from "@/i18n"

const instance = axios.create({
baseURL: "/kubepi", // url = base url + request url
Expand All @@ -23,12 +23,12 @@ instance.interceptors.request.use(
const checkAuth = response => {
// 请根据实际需求修改
if (response.status === 401) {
let message = i18n.t("commons.login.expires")
$alert(message, () => {
store.dispatch("user/logout").then(() => {
location.reload()
})
})
// let message = i18n.t("commons.login.expires")
// $alert(message, () => {
// store.dispatch("user/logout").then(() => {
// location.reload()
// })
// })
}
}

Expand Down

0 comments on commit 87e4eca

Please sign in to comment.