mirror of https://github.com/1Panel-dev/1Panel
fix: 删除初始化用户界面及接口 (#874)
parent
3ac64d65b6
commit
1c06b7b608
|
@ -106,40 +106,6 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) {
|
|||
helper.SuccessWithData(c, authService.CheckIsSafety(code))
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Check is First login
|
||||
// @Description 判断是否为首次登录
|
||||
// @Success 200
|
||||
// @Router /auth/isfirst [get]
|
||||
func (b *BaseApi) CheckIsFirstLogin(c *gin.Context) {
|
||||
helper.SuccessWithData(c, authService.CheckIsFirst())
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Init user
|
||||
// @Description 初始化用户
|
||||
// @Accept json
|
||||
// @Param request body dto.InitUser true "request"
|
||||
// @Success 200
|
||||
// @Router /auth/init [post]
|
||||
func (b *BaseApi) InitUserInfo(c *gin.Context) {
|
||||
var req dto.InitUser
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
if err := global.VALID.Struct(req); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := authService.InitUser(c, req); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, nil)
|
||||
}
|
||||
|
||||
// @Tags Auth
|
||||
// @Summary Check System isDemo
|
||||
// @Description 判断是否为demo环境
|
||||
|
|
|
@ -31,8 +31,3 @@ type MFALogin struct {
|
|||
Code string `json:"code"`
|
||||
AuthMethod string `json:"authMethod"`
|
||||
}
|
||||
|
||||
type InitUser struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@ package service
|
|||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
|
||||
|
@ -20,8 +18,6 @@ type AuthService struct{}
|
|||
|
||||
type IAuthService interface {
|
||||
CheckIsSafety(code string) bool
|
||||
CheckIsFirst() bool
|
||||
InitUser(c *gin.Context, req dto.InitUser) error
|
||||
VerifyCode(code string) (bool, error)
|
||||
Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, error)
|
||||
LogOut(c *gin.Context) error
|
||||
|
@ -157,39 +153,3 @@ func (u *AuthService) CheckIsSafety(code string) bool {
|
|||
}
|
||||
return status.Value == code
|
||||
}
|
||||
|
||||
func (u *AuthService) CheckIsFirst() bool {
|
||||
user, _ := settingRepo.Get(settingRepo.WithByKey("UserName"))
|
||||
pass, _ := settingRepo.Get(settingRepo.WithByKey("Password"))
|
||||
return len(user.Value) == 0 || len(pass.Value) == 0
|
||||
}
|
||||
|
||||
func (u *AuthService) InitUser(c *gin.Context, req dto.InitUser) error {
|
||||
user, _ := settingRepo.Get(settingRepo.WithByKey("UserName"))
|
||||
pass, _ := settingRepo.Get(settingRepo.WithByKey("Password"))
|
||||
if len(user.Value) == 0 || len(pass.Value) == 0 {
|
||||
newPass, err := encrypt.StringEncrypt(req.Password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := settingRepo.Update("UserName", req.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := settingRepo.Update("Password", newPass); err != nil {
|
||||
return err
|
||||
}
|
||||
expiredSetting, err := settingRepo.Get(settingRepo.WithByKey("ExpirationDays"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
timeout, _ := strconv.Atoi(expiredSetting.Value)
|
||||
if timeout != 0 {
|
||||
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return buserr.New(constant.ErrInitUser)
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) {
|
|||
baseRouter.GET("/captcha", baseApi.Captcha)
|
||||
baseRouter.POST("/mfalogin", baseApi.MFALogin)
|
||||
baseRouter.POST("/login", baseApi.Login)
|
||||
baseRouter.GET("/isfirst", baseApi.CheckIsFirstLogin)
|
||||
baseRouter.GET("/issafety", baseApi.CheckIsSafety)
|
||||
baseRouter.POST("/init", baseApi.InitUserInfo)
|
||||
baseRouter.POST("/logout", baseApi.LogOut)
|
||||
baseRouter.GET("/demo", baseApi.CheckIsDemo)
|
||||
}
|
||||
|
|
|
@ -799,48 +799,6 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/auth/init": {
|
||||
"post": {
|
||||
"description": "初始化用户",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Init user",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.InitUser"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/isfirst": {
|
||||
"get": {
|
||||
"description": "判断是否为首次登录",
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Check is First login",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/issafety": {
|
||||
"get": {
|
||||
"description": "获取系统安全登录状态",
|
||||
|
@ -11073,21 +11031,6 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"dto.InitUser": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"password"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.InspectReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -11987,7 +11930,8 @@ var doc = `{
|
|||
],
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
|
@ -12006,7 +11950,8 @@ var doc = `{
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"from": {
|
||||
"type": "string"
|
||||
|
@ -12043,7 +11988,8 @@ var doc = `{
|
|||
],
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
|
|
|
@ -785,48 +785,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/auth/init": {
|
||||
"post": {
|
||||
"description": "初始化用户",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Init user",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.InitUser"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/isfirst": {
|
||||
"get": {
|
||||
"description": "判断是否为首次登录",
|
||||
"tags": [
|
||||
"Auth"
|
||||
],
|
||||
"summary": "Check is First login",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/auth/issafety": {
|
||||
"get": {
|
||||
"description": "获取系统安全登录状态",
|
||||
|
@ -11059,21 +11017,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"dto.InitUser": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"password"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.InspectReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -11973,7 +11916,8 @@
|
|||
],
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
|
@ -11992,7 +11936,8 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"from": {
|
||||
"type": "string"
|
||||
|
@ -12029,7 +11974,8 @@
|
|||
],
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"maxLength": 256
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
|
|
|
@ -904,16 +904,6 @@ definitions:
|
|||
- sourceID
|
||||
- targetName
|
||||
type: object
|
||||
dto.InitUser:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
- password
|
||||
type: object
|
||||
dto.InspectReq:
|
||||
properties:
|
||||
id:
|
||||
|
@ -1510,6 +1500,7 @@ definitions:
|
|||
dto.SnapshotCreate:
|
||||
properties:
|
||||
description:
|
||||
maxLength: 256
|
||||
type: string
|
||||
from:
|
||||
enum:
|
||||
|
@ -1526,6 +1517,7 @@ definitions:
|
|||
dto.SnapshotImport:
|
||||
properties:
|
||||
description:
|
||||
maxLength: 256
|
||||
type: string
|
||||
from:
|
||||
type: string
|
||||
|
@ -1548,6 +1540,7 @@ definitions:
|
|||
dto.UpdateDescription:
|
||||
properties:
|
||||
description:
|
||||
maxLength: 256
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
|
@ -3553,33 +3546,6 @@ paths:
|
|||
summary: Check System isDemo
|
||||
tags:
|
||||
- Auth
|
||||
/auth/init:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 初始化用户
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.InitUser'
|
||||
responses:
|
||||
"200":
|
||||
description: ""
|
||||
summary: Init user
|
||||
tags:
|
||||
- Auth
|
||||
/auth/isfirst:
|
||||
get:
|
||||
description: 判断是否为首次登录
|
||||
responses:
|
||||
"200":
|
||||
description: ""
|
||||
summary: Check is First login
|
||||
tags:
|
||||
- Auth
|
||||
/auth/issafety:
|
||||
get:
|
||||
description: 获取系统安全登录状态
|
||||
|
|
|
@ -18,10 +18,6 @@ export namespace Login {
|
|||
token: string;
|
||||
mfaStatus: string;
|
||||
}
|
||||
export interface InitUser {
|
||||
name: string;
|
||||
password: string;
|
||||
}
|
||||
export interface ResCaptcha {
|
||||
imagePath: string;
|
||||
captchaID: string;
|
||||
|
|
|
@ -25,18 +25,10 @@ export const loginStatus = () => {
|
|||
return http.get<any>('/info');
|
||||
};
|
||||
|
||||
export const checkIsFirst = () => {
|
||||
return http.get<boolean>('/auth/isfirst');
|
||||
};
|
||||
|
||||
export const checkIsSafety = (code: string) => {
|
||||
return http.get<boolean>(`/auth/issafety?code=${code}`);
|
||||
};
|
||||
|
||||
export const initUser = (params: Login.InitUser) => {
|
||||
return http.post(`/auth/init`, params);
|
||||
};
|
||||
|
||||
export const checkIsDemo = () => {
|
||||
return http.get<boolean>('/auth/demo');
|
||||
};
|
||||
|
|
|
@ -105,10 +105,8 @@ const message = {
|
|||
comfimNoNull: 'Make sure the value {0} is not empty',
|
||||
},
|
||||
login: {
|
||||
firstLogin: 'First login, please create an initial administrator user!',
|
||||
username: 'UserName',
|
||||
password: 'Password',
|
||||
rePassword: 'Confirm Password',
|
||||
welcome: 'Welcome back, please enter your username and password to log in!',
|
||||
errorAuthInfo: 'The user name or password you entered is incorrect, please re-enter!',
|
||||
errorMfaInfo: 'Incorrect authentication information, please try again!',
|
||||
|
|
|
@ -109,10 +109,8 @@ const message = {
|
|||
comfimNoNull: '请确认 {0} 值不为空',
|
||||
},
|
||||
login: {
|
||||
firstLogin: '首次登录,请创建初始管理员用户!',
|
||||
username: '用户名',
|
||||
password: '密码',
|
||||
rePassword: '确认密码',
|
||||
welcome: '欢迎回来,请输入用户名和密码登录!',
|
||||
errorAuthInfo: '您输入的用户名或密码不正确,请重新输入!',
|
||||
errorMfaInfo: '错误的验证信息,请重试!',
|
||||
|
|
|
@ -1,74 +1,6 @@
|
|||
<template>
|
||||
<div v-loading="loading">
|
||||
<div v-if="isFirst">
|
||||
<div class="login-form">
|
||||
<el-form ref="registerFormRef" :model="registerForm" size="default" :rules="registerRules">
|
||||
<div class="login-title">{{ $t('commons.button.init') }}</div>
|
||||
<input type="text" class="hide" id="name" />
|
||||
<input type="password" class="hide" id="password" />
|
||||
<el-form-item prop="name" class="no-border">
|
||||
<el-input
|
||||
v-model.trim="registerForm.name"
|
||||
:placeholder="$t('commons.login.username')"
|
||||
autocomplete="off"
|
||||
type="text"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon">
|
||||
<user />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password" class="no-border">
|
||||
<el-input
|
||||
type="password"
|
||||
clearable
|
||||
v-model.trim="registerForm.password"
|
||||
show-password
|
||||
:placeholder="$t('commons.login.password')"
|
||||
name="passwod"
|
||||
autocomplete="new-password"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon">
|
||||
<lock />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="rePassword" class="no-border">
|
||||
<el-input
|
||||
type="password"
|
||||
clearable
|
||||
v-model.trim="registerForm.rePassword"
|
||||
show-password
|
||||
:placeholder="$t('commons.login.rePassword')"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon">
|
||||
<lock />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
@focus="registerButtonFocused = true"
|
||||
@blur="registerButtonFocused = false"
|
||||
@click="register(registerFormRef)"
|
||||
class="login-button"
|
||||
type="primary"
|
||||
size="default"
|
||||
round
|
||||
>
|
||||
{{ $t('commons.button.init') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="mfaShow">
|
||||
<div v-if="mfaShow">
|
||||
<div class="login-form">
|
||||
<el-form @submit.prevent>
|
||||
<div class="login-title">{{ $t('commons.login.mfaTitle') }}</div>
|
||||
|
@ -201,11 +133,10 @@
|
|||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type { ElForm } from 'element-plus';
|
||||
import { loginApi, getCaptcha, mfaLoginApi, checkIsFirst, initUser, checkIsDemo } from '@/api/modules/auth';
|
||||
import { loginApi, getCaptcha, mfaLoginApi, checkIsDemo } from '@/api/modules/auth';
|
||||
import { GlobalStore } from '@/store';
|
||||
import { MenuStore } from '@/store/modules/menu';
|
||||
import i18n from '@/lang';
|
||||
import { Rules } from '@/global/form-rules';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
|
||||
const globalStore = GlobalStore();
|
||||
|
@ -217,23 +148,8 @@ const errMfaInfo = ref(false);
|
|||
const isDemo = ref(false);
|
||||
const errAgree = ref(false);
|
||||
|
||||
const isFirst = ref();
|
||||
|
||||
type FormInstance = InstanceType<typeof ElForm>;
|
||||
|
||||
const registerButtonFocused = ref(false);
|
||||
const registerFormRef = ref<FormInstance>();
|
||||
const registerForm = reactive({
|
||||
name: '',
|
||||
password: '',
|
||||
rePassword: '',
|
||||
});
|
||||
const registerRules = reactive({
|
||||
name: [Rules.requiredInput, Rules.userName],
|
||||
password: [Rules.requiredInput, Rules.password],
|
||||
rePassword: [Rules.requiredInput, { validator: checkPassword, trigger: 'blur' }],
|
||||
});
|
||||
|
||||
const loginButtonFocused = ref();
|
||||
const loginFormRef = ref<FormInstance>();
|
||||
const loginForm = reactive({
|
||||
|
@ -270,16 +186,6 @@ const mfaShow = ref<boolean>(false);
|
|||
|
||||
const router = useRouter();
|
||||
|
||||
const register = (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
formEl.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
await initUser(registerForm);
|
||||
checkStatus();
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
});
|
||||
};
|
||||
|
||||
const login = (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
formEl.validate(async (valid) => {
|
||||
|
@ -358,39 +264,20 @@ const loginVerify = async () => {
|
|||
captcha.captchaLength = res.data.captchaLength ? res.data.captchaLength : 0;
|
||||
};
|
||||
|
||||
const checkStatus = async () => {
|
||||
const res = await checkIsFirst();
|
||||
isFirst.value = res.data;
|
||||
if (!isFirst.value) {
|
||||
loginVerify();
|
||||
}
|
||||
};
|
||||
|
||||
const checkIsSystemDemo = async () => {
|
||||
const res = await checkIsDemo();
|
||||
isDemo.value = res.data;
|
||||
};
|
||||
|
||||
function checkPassword(rule: any, value: any, callback: any) {
|
||||
if (registerForm.password !== registerForm.rePassword) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.rePassword')));
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.title = globalStore.themeConfig.panelName;
|
||||
loginForm.agreeLicense = globalStore.agreeLicense;
|
||||
checkStatus();
|
||||
checkIsSystemDemo();
|
||||
document.onkeydown = (e: any) => {
|
||||
e = window.event || e;
|
||||
if (e.keyCode === 13) {
|
||||
if (!mfaShow.value) {
|
||||
if (isFirst.value && !registerButtonFocused.value) {
|
||||
register(registerFormRef.value);
|
||||
}
|
||||
if (!isFirst.value && !loginButtonFocused.value) {
|
||||
if (!loginButtonFocused.value) {
|
||||
login(loginFormRef.value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue