Skip to content

Commit 67c1fbd

Browse files
authored
fix: 优化登陆页面特征信息 (#7027)
Refs #7000
1 parent 5c7fab8 commit 67c1fbd

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

backend/app/api/v1/auth.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1
22

33
import (
44
"encoding/base64"
5+
"net/http"
56

67
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
78
"github.com/1Panel-dev/1Panel/backend/app/dto"
@@ -120,12 +121,13 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) {
120121
return
121122
}
122123
if status == "disable" && len(code) != 0 {
123-
helper.ErrorWithDetail(c, constant.CodeErrNotFound, constant.ErrTypeInternalServer, err)
124+
helper.ErrResponse(c, http.StatusNotFound)
124125
return
125126
}
126127
if status == "unpass" {
127-
if middleware.LoadErrCode("err-entrance") != 200 {
128-
helper.ErrResponse(c, middleware.LoadErrCode("err-entrance"))
128+
code := middleware.LoadErrCode()
129+
if code != 200 {
130+
helper.ErrResponse(c, code)
129131
return
130132
}
131133
helper.ErrorWithDetail(c, constant.CodeErrEntrance, constant.ErrTypeInternalServer, nil)

backend/middleware/bind_domain.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ func BindDomain() gin.HandlerFunc {
2929
}
3030

3131
if domains != status.Value {
32-
if LoadErrCode("err-domain") != 200 {
33-
helper.ErrResponse(c, LoadErrCode("err-domain"))
32+
code := LoadErrCode()
33+
if code != 200 {
34+
helper.ErrResponse(c, code)
3435
return
3536
}
3637
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed"))

backend/middleware/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/1Panel-dev/1Panel/backend/app/repo"
77
)
88

9-
func LoadErrCode(errInfo string) int {
9+
func LoadErrCode() int {
1010
settingRepo := repo.NewISettingRepo()
1111
codeVal, err := settingRepo.Get(settingRepo.WithByKey("NoAuthSetting"))
1212
if err != nil {

backend/middleware/ip_limit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ func WhiteAllow() gin.HandlerFunc {
3535
return
3636
}
3737
}
38-
if LoadErrCode("err-ip") != 200 {
39-
helper.ErrResponse(c, LoadErrCode("err-ip"))
38+
code := LoadErrCode()
39+
if code != 200 {
40+
helper.ErrResponse(c, code)
4041
return
4142
}
4243
helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed"))

frontend/src/api/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ class RequestHttp {
132132
);
133133
return;
134134
default:
135+
globalStore.isLogin = false;
135136
globalStore.errStatus = 'code-' + response.status;
136137
router.push({
137138
name: 'entrance',
138139
params: { code: globalStore.entrance },
139140
});
140-
return;
141+
return Promise.reject(error);
141142
}
142143
}
143144
if (!window.navigator.onLine) router.replace({ path: '/500' });

frontend/src/components/error-message/error_code.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,3 @@ const loadErrInfo = () => {
3333
}
3434
};
3535
</script>
36-
37-
<style scoped lang="scss">
38-
.container {
39-
margin-left: 40%;
40-
}
41-
</style>

frontend/src/views/login/entrance/index.vue

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<template>
22
<div>
3-
<div v-if="!loading">
4-
<div class="login-background" v-if="errStatus === ''">
5-
<div class="login-wrapper">
6-
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
7-
<div class="login-title">
8-
<span>{{ globalStore.themeConfig.title || $t('setting.description') }}</span>
3+
<div v-if="init">
4+
<div v-if="errStatus === ''">
5+
<div class="login-background">
6+
<div class="login-wrapper">
7+
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
8+
<div class="login-title">
9+
<span>{{ globalStore.themeConfig.title || $t('setting.description') }}</span>
10+
</div>
11+
<img src="@/assets/images/1panel-login.png" alt="" v-if="screenWidth > 1110" />
912
</div>
10-
<img src="@/assets/images/1panel-login.png" alt="" v-if="screenWidth > 1110" />
11-
</div>
12-
<div :class="screenWidth > 1110 ? 'right inline-block' : ''">
13-
<div class="login-container">
14-
<LoginForm ref="loginRef"></LoginForm>
13+
<div :class="screenWidth > 1110 ? 'right inline-block' : ''">
14+
<div class="login-container">
15+
<LoginForm ref="loginRef"></LoginForm>
16+
</div>
1517
</div>
1618
</div>
1719
</div>
@@ -46,45 +48,40 @@ import ErrIP from '@/components/error-message/err_ip.vue';
4648
import ErrCode from '@/components/error-message/error_code.vue';
4749
import ErrDomain from '@/components/error-message/err_domain.vue';
4850
import ErrFound from '@/components/error-message/404.vue';
49-
import { ref, onMounted, watch } from 'vue';
51+
import { ref, onMounted } from 'vue';
5052
import { GlobalStore } from '@/store';
5153
import { getXpackSettingForTheme } from '@/utils/xpack';
5254
const globalStore = GlobalStore();
5355
5456
const screenWidth = ref(null);
55-
const errStatus = ref('');
56-
const loading = ref();
57+
const errStatus = ref('x');
58+
const init = ref(false);
5759
5860
const mySafetyCode = defineProps({
5961
code: {
6062
type: String,
6163
default: '',
6264
},
6365
});
64-
watch(
65-
() => globalStore.errStatus,
66-
(newVal) => {
67-
if (newVal?.startsWith('err-') || newVal?.startsWith('code-')) {
68-
errStatus.value = newVal;
69-
}
70-
},
71-
);
66+
7267
const getStatus = async () => {
73-
let info = globalStore.errStatus;
74-
if (info?.startsWith('err-') || info?.startsWith('code-')) {
75-
errStatus.value = info;
76-
return;
77-
}
7868
let code = mySafetyCode.code;
7969
globalStore.entrance = code;
80-
loading.value = true;
8170
await checkIsSafety(code)
8271
.then(() => {
83-
loading.value = false;
72+
let info = globalStore.errStatus;
73+
if (info?.startsWith('err-') || info?.startsWith('code-')) {
74+
errStatus.value = info;
75+
init.value = true;
76+
return;
77+
}
78+
errStatus.value = '';
79+
init.value = true;
8480
getXpackSettingForTheme();
8581
})
86-
.catch(() => {
87-
loading.value = false;
82+
.catch((err) => {
83+
errStatus.value = 'code-' + err.status;
84+
init.value = true;
8885
});
8986
};
9087

0 commit comments

Comments
 (0)