Skip to content

Commit 8c2bb23

Browse files
feat(system): Optimize the logic of the login page (#7828)
1 parent 3682034 commit 8c2bb23

File tree

16 files changed

+9492
-3614
lines changed

16 files changed

+9492
-3614
lines changed

core/app/api/v2/app_launcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (b *BaseApi) SearchAppLauncher(c *gin.Context) {
1818
// @Tags App Launcher
1919
// @Summary Update app Launcher
2020
// @Accept json
21-
// @Param request body dto.ChangeShow true "request"
21+
// @Param request body dto.SettingUpdate true "request"
2222
// @Success 200
2323
// @Security ApiKeyAuth
2424
// @Security Timestamp

core/app/api/v2/auth.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/1Panel-dev/1Panel/core/app/dto"
77
"github.com/1Panel-dev/1Panel/core/app/model"
88
"github.com/1Panel-dev/1Panel/core/constant"
9-
"github.com/1Panel-dev/1Panel/core/global"
109
"github.com/1Panel-dev/1Panel/core/utils/captcha"
1110
"github.com/gin-gonic/gin"
1211
)
@@ -119,24 +118,16 @@ func (b *BaseApi) GetResponsePage(c *gin.Context) {
119118
}
120119

121120
// @Tags Auth
122-
// @Summary Check System isDemo
123-
// @Success 200 {boolean} demo
124-
// @Router /core/auth/demo [get]
125-
func (b *BaseApi) CheckIsDemo(c *gin.Context) {
126-
helper.SuccessWithData(c, global.CONF.Base.IsDemo)
127-
}
128-
129-
// @Tags Auth
130-
// @Summary Load System Language
131-
// @Success 200 {string} language
132-
// @Router /core/auth/language [get]
133-
func (b *BaseApi) GetLanguage(c *gin.Context) {
121+
// @Summary Get Setting For Login
122+
// @Success 200 {object} dto.SystemSetting
123+
// @Router /core/auth/setting [get]
124+
func (b *BaseApi) GetLoginSetting(c *gin.Context) {
134125
settingInfo, err := settingService.GetSettingInfo()
135126
if err != nil {
136127
helper.InternalServer(c, err)
137128
return
138129
}
139-
helper.SuccessWithData(c, settingInfo.Language)
130+
helper.SuccessWithData(c, settingInfo)
140131
}
141132

142133
func saveLoginLogs(c *gin.Context, err error) {
@@ -151,11 +142,3 @@ func saveLoginLogs(c *gin.Context, err error) {
151142
logs.Agent = c.GetHeader("User-Agent")
152143
_ = logService.CreateLoginLog(logs)
153144
}
154-
155-
// @Tags Auth
156-
// @Summary Check System IsIntl
157-
// @Success 200 {string} intl
158-
// @Router /auth/intl [get]
159-
func (b *BaseApi) CheckIsIntl(c *gin.Context) {
160-
helper.SuccessWithData(c, global.CONF.Base.IsIntl)
161-
}

core/app/api/v2/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (b *BaseApi) ListBuckets(c *gin.Context) {
7575
// @Tags Backup Account
7676
// @Summary Load backup account base info
7777
// @Accept json
78-
// @Success 200 {object} dto.OneDriveInfo
78+
// @Success 200 {object} dto.BackupClientInfo
7979
// @Security ApiKeyAuth
8080
// @Security Timestamp
8181
// @Router /core/backups/client/:clientType [get]

core/app/dto/auth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ type MFALogin struct {
3838
Code string `json:"code" validate:"required"`
3939
AuthMethod string `json:"authMethod"`
4040
}
41+
42+
type SystemSetting struct {
43+
IsDemo bool `json:"isDemo"`
44+
Language string `json:"language"`
45+
IsIntl bool `json:"isIntl"`
46+
}

core/app/service/auth.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
type AuthService struct{}
1919

2020
type IAuthService interface {
21-
CheckIsSafety(code string) (string, error)
2221
GetResponsePage() (string, error)
2322
VerifyCode(code string) (bool, error)
2423
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) {
169168
return hmac.Equal([]byte(setting.Value), []byte(code)), nil
170169
}
171170

172-
func (u *AuthService) CheckIsSafety(code string) (string, error) {
173-
status, err := settingRepo.Get(repo.WithByKey("SecurityEntrance"))
174-
if err != nil {
175-
return "", err
176-
}
177-
if len(status.Value) == 0 {
178-
return "disable", nil
179-
}
180-
if status.Value == code {
181-
return "pass", nil
182-
}
183-
return "unpass", nil
184-
}
185-
186171
func (u *AuthService) GetResponsePage() (string, error) {
187172
pageCode, err := settingRepo.Get(repo.WithByKey("NoAuthSetting"))
188173
if err != nil {

core/app/service/setting.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ type ISettingService interface {
4747
UpdateTerminal(req dto.TerminalInfo) error
4848

4949
UpdateSystemSSL() error
50-
5150
GenerateRSAKey() error
51+
52+
GetLoginSetting() (*dto.SystemSetting, error)
5253
}
5354

5455
func NewISettingService() ISettingService {
@@ -527,3 +528,16 @@ func (u *SettingService) GenerateRSAKey() error {
527528
}
528529
return nil
529530
}
531+
532+
func (u *SettingService) GetLoginSetting() (*dto.SystemSetting, error) {
533+
settingInfo, err := u.GetSettingInfo()
534+
if err != nil {
535+
return nil, err
536+
}
537+
res := &dto.SystemSetting{
538+
Language: settingInfo.Language,
539+
IsDemo: global.CONF.Base.IsDemo,
540+
IsIntl: global.CONF.Base.IsIntl,
541+
}
542+
return res, nil
543+
}

0 commit comments

Comments
 (0)