mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-13 03:50:07 +08:00
feat(system): Optimize the logic of the login page (#7828)
This commit is contained in:
parent
368203443f
commit
8c2bb231c6
@ -18,7 +18,7 @@ func (b *BaseApi) SearchAppLauncher(c *gin.Context) {
|
||||
// @Tags App Launcher
|
||||
// @Summary Update app Launcher
|
||||
// @Accept json
|
||||
// @Param request body dto.ChangeShow true "request"
|
||||
// @Param request body dto.SettingUpdate true "request"
|
||||
// @Success 200
|
||||
// @Security ApiKeyAuth
|
||||
// @Security Timestamp
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
||||
"github.com/1Panel-dev/1Panel/core/constant"
|
||||
"github.com/1Panel-dev/1Panel/core/global"
|
||||
"github.com/1Panel-dev/1Panel/core/utils/captcha"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -119,24 +118,16 @@ func (b *BaseApi) GetResponsePage(c *gin.Context) {
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Check System isDemo
|
||||
// @Success 200 {boolean} demo
|
||||
// @Router /core/auth/demo [get]
|
||||
func (b *BaseApi) CheckIsDemo(c *gin.Context) {
|
||||
helper.SuccessWithData(c, global.CONF.Base.IsDemo)
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Load System Language
|
||||
// @Success 200 {string} language
|
||||
// @Router /core/auth/language [get]
|
||||
func (b *BaseApi) GetLanguage(c *gin.Context) {
|
||||
// @Summary Get Setting For Login
|
||||
// @Success 200 {object} dto.SystemSetting
|
||||
// @Router /core/auth/setting [get]
|
||||
func (b *BaseApi) GetLoginSetting(c *gin.Context) {
|
||||
settingInfo, err := settingService.GetSettingInfo()
|
||||
if err != nil {
|
||||
helper.InternalServer(c, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, settingInfo.Language)
|
||||
helper.SuccessWithData(c, settingInfo)
|
||||
}
|
||||
|
||||
func saveLoginLogs(c *gin.Context, err error) {
|
||||
@ -151,11 +142,3 @@ func saveLoginLogs(c *gin.Context, err error) {
|
||||
logs.Agent = c.GetHeader("User-Agent")
|
||||
_ = logService.CreateLoginLog(logs)
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Check System IsIntl
|
||||
// @Success 200 {string} intl
|
||||
// @Router /auth/intl [get]
|
||||
func (b *BaseApi) CheckIsIntl(c *gin.Context) {
|
||||
helper.SuccessWithData(c, global.CONF.Base.IsIntl)
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func (b *BaseApi) ListBuckets(c *gin.Context) {
|
||||
// @Tags Backup Account
|
||||
// @Summary Load backup account base info
|
||||
// @Accept json
|
||||
// @Success 200 {object} dto.OneDriveInfo
|
||||
// @Success 200 {object} dto.BackupClientInfo
|
||||
// @Security ApiKeyAuth
|
||||
// @Security Timestamp
|
||||
// @Router /core/backups/client/:clientType [get]
|
||||
|
@ -38,3 +38,9 @@ type MFALogin struct {
|
||||
Code string `json:"code" validate:"required"`
|
||||
AuthMethod string `json:"authMethod"`
|
||||
}
|
||||
|
||||
type SystemSetting struct {
|
||||
IsDemo bool `json:"isDemo"`
|
||||
Language string `json:"language"`
|
||||
IsIntl bool `json:"isIntl"`
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
type AuthService struct{}
|
||||
|
||||
type IAuthService interface {
|
||||
CheckIsSafety(code string) (string, error)
|
||||
GetResponsePage() (string, error)
|
||||
VerifyCode(code string) (bool, error)
|
||||
Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, string, error)
|
||||
@ -169,20 +168,6 @@ func (u *AuthService) VerifyCode(code string) (bool, error) {
|
||||
return hmac.Equal([]byte(setting.Value), []byte(code)), nil
|
||||
}
|
||||
|
||||
func (u *AuthService) CheckIsSafety(code string) (string, error) {
|
||||
status, err := settingRepo.Get(repo.WithByKey("SecurityEntrance"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(status.Value) == 0 {
|
||||
return "disable", nil
|
||||
}
|
||||
if status.Value == code {
|
||||
return "pass", nil
|
||||
}
|
||||
return "unpass", nil
|
||||
}
|
||||
|
||||
func (u *AuthService) GetResponsePage() (string, error) {
|
||||
pageCode, err := settingRepo.Get(repo.WithByKey("NoAuthSetting"))
|
||||
if err != nil {
|
||||
|
@ -47,8 +47,9 @@ type ISettingService interface {
|
||||
UpdateTerminal(req dto.TerminalInfo) error
|
||||
|
||||
UpdateSystemSSL() error
|
||||
|
||||
GenerateRSAKey() error
|
||||
|
||||
GetLoginSetting() (*dto.SystemSetting, error)
|
||||
}
|
||||
|
||||
func NewISettingService() ISettingService {
|
||||
@ -527,3 +528,16 @@ func (u *SettingService) GenerateRSAKey() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *SettingService) GetLoginSetting() (*dto.SystemSetting, error) {
|
||||
settingInfo, err := u.GetSettingInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := &dto.SystemSetting{
|
||||
Language: settingInfo.Language,
|
||||
IsDemo: global.CONF.Base.IsDemo,
|
||||
IsIntl: global.CONF.Base.IsIntl,
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||
fmt.Printf("generate swagger doc of agent failed, std1: %v, err: %v", string(std1), err)
|
||||
return
|
||||
}
|
||||
cmd2 := exec.Command(swagBin, "init", "-o", workDir+"/cmd/server/docs/docs_core", "-d", workDir+"/core", "-g", "../cmd/server/main.go")
|
||||
cmd2 := exec.Command(swagBin, "init", "-o", workDir+"/cmd/server/docs/docs_core", "-d", workDir+"/core", "-g", "./cmd/server/main.go")
|
||||
cmd2.Dir = workDir
|
||||
std2, err := cmd2.CombinedOutput()
|
||||
if err != nil {
|
||||
@ -106,7 +106,7 @@ func TestGenerateSwaggerDoc(t *testing.T) {
|
||||
return
|
||||
}
|
||||
docTemplate := strings.ReplaceAll(loadDefaultDocs(), "const docTemplate = \"aa\"", fmt.Sprintf("const docTemplate = `%s`", string(newJson)))
|
||||
if err := os.WriteFile(workDir+"/cmd/server/docs/docs.go", []byte(docTemplate), 0640); err != nil {
|
||||
if err := os.WriteFile(workDir+"/core/cmd/server/docs/docs.go", []byte(docTemplate), 0640); err != nil {
|
||||
fmt.Printf("write new docs.go failed, err: %v", err)
|
||||
return
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,8 +15,6 @@ func (s *BaseRouter) InitRouter(Router *gin.RouterGroup) {
|
||||
baseRouter.POST("/mfalogin", baseApi.MFALogin)
|
||||
baseRouter.POST("/login", baseApi.Login)
|
||||
baseRouter.POST("/logout", baseApi.LogOut)
|
||||
baseRouter.GET("/demo", baseApi.CheckIsDemo)
|
||||
baseRouter.GET("/language", baseApi.GetLanguage)
|
||||
baseRouter.GET("/intl", baseApi.CheckIsIntl)
|
||||
baseRouter.GET("/setting", baseApi.GetLoginSetting)
|
||||
}
|
||||
}
|
||||
|
@ -26,4 +26,10 @@ export namespace Login {
|
||||
export interface ResAuthButtons {
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
export interface LoginSetting {
|
||||
isDemo: boolean;
|
||||
isIntl: boolean;
|
||||
language: string;
|
||||
}
|
||||
}
|
||||
|
@ -17,18 +17,6 @@ export const logOutApi = () => {
|
||||
return http.post<any>(`/core/auth/logout`);
|
||||
};
|
||||
|
||||
export const checkIsSafety = (code: string) => {
|
||||
return http.get<string>(`/core/auth/issafety?code=${code}`);
|
||||
};
|
||||
|
||||
export const checkIsDemo = () => {
|
||||
return http.get<boolean>('/core/auth/demo');
|
||||
};
|
||||
|
||||
export const getLanguage = () => {
|
||||
return http.get<string>(`/core/auth/language`);
|
||||
};
|
||||
|
||||
export const checkIsIntl = () => {
|
||||
return http.get<boolean>('/core/auth/intl');
|
||||
export const getLoginSetting = () => {
|
||||
return http.get<Login.LoginSetting>('/core/auth/setting');
|
||||
};
|
||||
|
@ -72,7 +72,7 @@ import Logo from './components/Logo.vue';
|
||||
import Collapse from './components/Collapse.vue';
|
||||
import SubItem from './components/SubItem.vue';
|
||||
import router, { menuList } from '@/routers/router';
|
||||
import { checkIsIntl, logOutApi } from '@/api/modules/auth';
|
||||
import { logOutApi } from '@/api/modules/auth';
|
||||
import i18n from '@/lang';
|
||||
import { DropdownInstance, ElMessageBox } from 'element-plus';
|
||||
import { GlobalStore, MenuStore } from '@/store';
|
||||
@ -222,7 +222,6 @@ function getCheckedLabels(json: Node): string[] {
|
||||
}
|
||||
|
||||
const search = async () => {
|
||||
await checkIsSystemIntl();
|
||||
let checkedLabels: any[] = [];
|
||||
const res = await getSettingInfo();
|
||||
version.value = res.data.systemVersion;
|
||||
@ -284,11 +283,6 @@ const openTask = () => {
|
||||
emit('openTask');
|
||||
};
|
||||
|
||||
const checkIsSystemIntl = async () => {
|
||||
const res = await checkIsIntl();
|
||||
globalStore.isIntl = res.data;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
menuStore.setMenuList(menuList);
|
||||
search();
|
||||
|
@ -106,7 +106,7 @@
|
||||
@click="loginVerify()"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col :span="24" class="h-1">
|
||||
<el-col :span="24" class="h-0.5">
|
||||
<span v-show="errCaptcha" class="input-error">
|
||||
{{ $t('commons.login.errorCaptcha') }}
|
||||
</span>
|
||||
@ -115,7 +115,6 @@
|
||||
</span>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-form-item>
|
||||
<el-button
|
||||
@click="login(loginFormRef)"
|
||||
@ -128,9 +127,10 @@
|
||||
{{ $t('commons.button.login') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="!isIntl">
|
||||
<el-form-item prop="agreeLicense">
|
||||
<el-text v-if="isDemo" type="danger">
|
||||
{{ $t('commons.login.username') }}:demo {{ $t('commons.login.password') }}:1panel
|
||||
</el-text>
|
||||
<el-form-item prop="agreeLicense" v-if="!isIntl">
|
||||
<el-checkbox v-model="loginForm.agreeLicense">
|
||||
<template #default>
|
||||
<span>
|
||||
@ -146,14 +146,8 @@
|
||||
</template>
|
||||
</el-checkbox>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</div>
|
||||
</el-form>
|
||||
<div class="demo">
|
||||
<span v-if="isDemo">
|
||||
{{ $t('commons.login.username') }}:demo {{ $t('commons.login.password') }}:1panel
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogPro v-model="open" center size="w-90">
|
||||
@ -184,7 +178,7 @@
|
||||
import { ref, reactive, onMounted, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type { ElForm } from 'element-plus';
|
||||
import { loginApi, getCaptcha, mfaLoginApi, checkIsDemo, getLanguage, checkIsIntl } from '@/api/modules/auth';
|
||||
import { loginApi, getCaptcha, mfaLoginApi, getLoginSetting } from '@/api/modules/auth';
|
||||
import { GlobalStore, MenuStore, TabsStore } from '@/store';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@ -270,12 +264,6 @@ const mfaShow = ref<boolean>(false);
|
||||
const router = useRouter();
|
||||
const dropdownText = ref('中文(简体)');
|
||||
|
||||
const checkIsSystemIntl = async () => {
|
||||
const res = await checkIsIntl();
|
||||
isIntl.value = res.data;
|
||||
globalStore.isIntl = isIntl.value;
|
||||
};
|
||||
|
||||
function handleCommand(command: string) {
|
||||
loginForm.language = command;
|
||||
usei18n.locale.value = command;
|
||||
@ -284,8 +272,14 @@ function handleCommand(command: string) {
|
||||
dropdownText.value = '中文(简体)';
|
||||
} else if (command === 'en') {
|
||||
dropdownText.value = 'English';
|
||||
} else if (command === 'pt-BR') {
|
||||
dropdownText.value = 'Português (Brasil)';
|
||||
} else if (command === 'tw') {
|
||||
dropdownText.value = '中文(繁體)';
|
||||
} else if (command === 'ko') {
|
||||
dropdownText.value = '한국어';
|
||||
} else if (command === 'ja') {
|
||||
dropdownText.value = '日本語';
|
||||
} else if (command === 'ru') {
|
||||
dropdownText.value = 'Русский';
|
||||
} else if (command === 'ms') {
|
||||
@ -395,19 +389,6 @@ const loginVerify = async () => {
|
||||
captcha.captchaLength = res.data.captchaLength ? res.data.captchaLength : 0;
|
||||
};
|
||||
|
||||
const checkIsSystemDemo = async () => {
|
||||
const res = await checkIsDemo();
|
||||
isDemo.value = res.data;
|
||||
};
|
||||
|
||||
const loadLanguage = async () => {
|
||||
try {
|
||||
const res = await getLanguage();
|
||||
loginForm.language = res.data;
|
||||
handleCommand(res.data);
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const loadDataFromDB = async () => {
|
||||
const res = await getSettingInfo();
|
||||
document.title = res.data.panelName;
|
||||
@ -420,14 +401,25 @@ const loadDataFromDB = async () => {
|
||||
globalStore.setThemeConfig({ ...themeConfig.value, theme: theme, panelName: res.data.panelName });
|
||||
};
|
||||
|
||||
const getSetting = async () => {
|
||||
try {
|
||||
const res = await getLoginSetting();
|
||||
isDemo.value = res.data.isDemo;
|
||||
loginForm.language = res.data.language;
|
||||
handleCommand(loginForm.language);
|
||||
isIntl.value = res.data.isIntl;
|
||||
globalStore.isIntl = isIntl.value;
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
globalStore.isOnRestart = false;
|
||||
checkIsSystemIntl();
|
||||
getSetting();
|
||||
if (!globalStore.ignoreCaptcha) {
|
||||
loginVerify();
|
||||
loadLanguage();
|
||||
}
|
||||
document.title = globalStore.themeConfig.panelName;
|
||||
loginForm.agreeLicense = globalStore.agreeLicense;
|
||||
checkIsSystemDemo();
|
||||
document.onkeydown = (e: any) => {
|
||||
e = window.event || e;
|
||||
if (e.keyCode === 13) {
|
||||
|
@ -22,15 +22,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="login">
|
||||
import { checkIsSafety } from '@/api/modules/auth';
|
||||
import LoginForm from './components/login-form.vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import router from '@/routers';
|
||||
import { GlobalStore } from '@/store';
|
||||
import { getXpackSettingForTheme } from '@/utils/xpack';
|
||||
|
||||
const gStore = GlobalStore();
|
||||
const loading = ref();
|
||||
const backgroundOpacity = ref(0.8);
|
||||
const backgroundImage = ref(new URL('', import.meta.url).href);
|
||||
const logoImage = ref(new URL('@/assets/images/1panel-login.png', import.meta.url).href);
|
||||
@ -49,19 +45,6 @@ const getStatus = async () => {
|
||||
if (code != '') {
|
||||
gStore.entrance = code;
|
||||
}
|
||||
loading.value = true;
|
||||
await checkIsSafety(gStore.entrance)
|
||||
.then((res) => {
|
||||
loading.value = false;
|
||||
if (res.data === 'unpass') {
|
||||
router.replace({ name: 'entrance', params: { code: gStore.entrance } });
|
||||
return;
|
||||
}
|
||||
getXpackSettingForTheme();
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user