Skip to content

Commit bf0b860

Browse files
committed
fix: avoid license required before login
1 parent af175f4 commit bf0b860

15 files changed

Lines changed: 140 additions & 62 deletions

File tree

core/app/api/v2/auth.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,28 @@ func (b *BaseApi) UpdateCurrentUser(c *gin.Context) {
461461
helper.Success(c)
462462
}
463463

464+
// @Tags Auth
465+
// @Summary Reset system password expired
466+
// @Accept json
467+
// @Param request body dto.PasswordUpdate true "request"
468+
// @Success 200
469+
// @Security ApiKeyAuth
470+
// @Security Timestamp
471+
// @Router /core/auth/expired/reset [post]
472+
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"重置过期密码","formatEN":"reset an expired Password"}
473+
func (b *BaseApi) ResetPassword(c *gin.Context) {
474+
var req dto.PasswordUpdate
475+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
476+
return
477+
}
478+
479+
if err := xpack.AuthProvider.HandlePasswordExpired(c, req.OldPassword, req.NewPassword); err != nil {
480+
helper.InternalServer(c, err)
481+
return
482+
}
483+
helper.Success(c)
484+
}
485+
464486
func saveLoginLogs(c *gin.Context, err error) {
465487
var logs model.LoginLog
466488
if err != nil {

core/app/api/v2/setting.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/1Panel-dev/1Panel/core/constant"
1818
"github.com/1Panel-dev/1Panel/core/global"
1919
"github.com/1Panel-dev/1Panel/core/utils/common"
20-
"github.com/1Panel-dev/1Panel/core/utils/xpack"
2120
"github.com/gin-gonic/gin"
2221
)
2322

@@ -338,28 +337,6 @@ func (b *BaseApi) UpdatePort(c *gin.Context) {
338337
helper.Success(c)
339338
}
340339

341-
// @Tags System Setting
342-
// @Summary Reset system password expired
343-
// @Accept json
344-
// @Param request body dto.PasswordUpdate true "request"
345-
// @Success 200
346-
// @Security ApiKeyAuth
347-
// @Security Timestamp
348-
// @Router /core/settings/expired/handle [post]
349-
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"重置过期密码","formatEN":"reset an expired Password"}
350-
func (b *BaseApi) HandlePasswordExpired(c *gin.Context) {
351-
var req dto.PasswordUpdate
352-
if err := helper.CheckBindAndValidate(&req, c); err != nil {
353-
return
354-
}
355-
356-
if err := xpack.AuthProvider.HandlePasswordExpired(c, req.OldPassword, req.NewPassword); err != nil {
357-
helper.InternalServer(c, err)
358-
return
359-
}
360-
helper.Success(c)
361-
}
362-
363340
func (b *BaseApi) ReloadSSL(c *gin.Context) {
364341
clientIP := c.ClientIP()
365342
if clientIP != "127.0.0.1" {

core/app/service/logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"net/http"
7+
"os"
78

89
"github.com/1Panel-dev/1Panel/core/buserr"
910
"github.com/1Panel-dev/1Panel/core/constant"
@@ -126,7 +127,7 @@ func runRemoteShellScript(url string, args ...string) error {
126127
if statusCode < http.StatusOK || statusCode >= http.StatusMultipleChoices {
127128
return fmt.Errorf("download script failed, status code: %d", statusCode)
128129
}
129-
_, err = cmd.NewCommandMgr().RunPipe(cmd.PipeCommand{
130+
_, err = cmd.NewCommandMgr(cmd.WithOutputFile(os.DevNull)).RunPipe(cmd.PipeCommand{
130131
Name: "sh",
131132
Args: append([]string{"-s"}, args...),
132133
Stdin: bytes.NewReader(script),

core/middleware/password_expired.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
func PasswordExpired() gin.HandlerFunc {
1717
return func(c *gin.Context) {
1818
if strings.HasPrefix(c.Request.URL.Path, "/api/v2/core/auth") ||
19-
c.Request.URL.Path == "/api/v2/core/settings/expired/handle" ||
2019
c.Request.URL.Path == "/api/v2/core/settings/search" ||
21-
c.Request.URL.Path == "/api/v2/core/settings/search/base" {
20+
c.Request.URL.Path == "/api/v2/core/settings/search/base" ||
21+
c.Request.URL.Path == "/api/v2/core/xpackee/licenses/info" ||
22+
c.Request.URL.Path == "/api/v2/core/xpackee/licenses/status" ||
23+
c.Request.URL.Path == "/api/v2/core/xpackee/licenses/upload" {
2224
c.Next()
2325
return
2426
}

core/router/ro_base.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ func (s *BaseRouter) InitRouter(Router *gin.RouterGroup) {
2626

2727
authRouter.POST("/mfa", baseApi.LoadMFA)
2828
authRouter.POST("/mfa/bind", baseApi.MFABind)
29+
2930
authRouter.POST("/passkey/register/begin", baseApi.PasskeyRegisterBegin)
3031
authRouter.POST("/passkey/register/finish", baseApi.PasskeyRegisterFinish)
3132
authRouter.GET("/passkey/list", baseApi.PasskeyList)
3233
authRouter.POST("/passkey/del", baseApi.PasskeyDelete)
34+
3335
authRouter.POST("/api/generate", baseApi.GenerateApiKey)
3436
authRouter.POST("/api/update", baseApi.UpdateApiConfig)
3537

3638
authRouter.GET("/current", baseApi.GetCurrentUser)
3739
authRouter.POST("/current/update", baseApi.UpdateCurrentUser)
40+
authRouter.POST("/expired/reset", baseApi.ResetPassword)
3841
}
3942
}

core/router/ro_setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
1818
noAuthRouter := Router.Group("settings")
1919
baseApi := v2.ApiGroupApp.BaseApi
2020
{
21-
router.POST("/search", baseApi.GetSettingInfo)
2221
router.POST("/search/base", baseApi.GetSettingBaseInfo)
2322

2423
settingRouter.POST("/by", baseApi.GetSettingByKey)
24+
settingRouter.POST("/search", baseApi.GetSettingInfo)
2525
settingRouter.POST("/terminal/search", baseApi.GetTerminalSettingInfo)
2626
settingRouter.GET("/search/available", baseApi.GetSystemAvailable)
2727
settingRouter.POST("/update", baseApi.UpdateSetting)

frontend/src/api/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ class RequestHttp {
9494
}
9595
if (data.code == ResultEnum.ERRXPACKEE) {
9696
globalStore.isXpackEELicensed = false;
97-
router.push({ name: 'XpackEELicenseRequired' });
97+
const routeName = router.currentRoute.value.name;
98+
if (globalStore.isLogin && routeName !== 'entrance' && routeName !== 'login') {
99+
router.push({ name: 'XpackEELicenseRequired' });
100+
}
98101
return Promise.reject(data);
99102
}
100103
if (data.code == ResultEnum.NodeUnBind) {

frontend/src/api/interface/auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ export namespace Login {
9090
ipWhiteList: string;
9191
apiKeyValidityTime: string;
9292
}
93+
export interface PasswordUpdate {
94+
oldPassword: string;
95+
newPassword: string;
96+
}
9397
}

frontend/src/api/interface/setting.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ export namespace Setting {
152152
key: string;
153153
sslID: number;
154154
}
155-
export interface PasswordUpdate {
156-
oldPassword: string;
157-
newPassword: string;
158-
}
159155
export interface PortUpdate {
160156
serverPort: number;
161157
}

frontend/src/api/modules/auth.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export const getWelcomePage = () => {
3838
export const getUserInfo = () => {
3939
return http.get<Login.AuthInfo>('/core/auth/current');
4040
};
41+
export const updateUserInfo = (params: Login.AuthInfoUpdate) => {
42+
let request = deepCopy(params) as Login.AuthInfoUpdate;
43+
if (request.oldPassword) {
44+
request.oldPassword = Base64.encode(request.oldPassword);
45+
}
46+
if (request.password) {
47+
request.password = Base64.encode(request.password);
48+
}
49+
return http.post<any>('/core/auth/current/update', request);
50+
};
51+
4152
export const loadMFA = (params: Login.MFARequest) => {
4253
return http.post<Login.MFAInfo>(`/core/auth/mfa`, params);
4354
};
@@ -66,13 +77,6 @@ export const passkeyDelete = (id: string) => {
6677
return http.post(`/core/auth/passkey/del`, { id });
6778
};
6879

69-
export const updateUserInfo = (params: Login.AuthInfoUpdate) => {
70-
let request = deepCopy(params) as Login.AuthInfoUpdate;
71-
if (request.oldPassword) {
72-
request.oldPassword = Base64.encode(request.oldPassword);
73-
}
74-
if (request.password) {
75-
request.password = Base64.encode(request.password);
76-
}
77-
return http.post<any>('/core/auth/current/update', request);
80+
export const handleExpired = (param: Login.PasswordUpdate) => {
81+
return http.post(`/core/auth/expired/reset`, param);
7882
};

0 commit comments

Comments
 (0)