Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/api/v2/app_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 5 additions & 22 deletions core/app/api/v2/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not contain any syntax errors nor logical issues or inefficiencies. It's quite clean and well-documented with the necessary comments for each function.

However, one suggestion could be to move some of these functions that don't have much functionality outside the base package into separate files instead of having them directly under app like GetResponsePage, thus providing more clarity on which file they belong to from other external sources.

Also moving all "helper" related codes out of the business layer to its own helper service/file would be beneficial as it can lead to better testability.

In addition, you should also consider refactoring this code snippet so that the CheckIsDemo() and/or the SetDefaultTheme() methods return an error instead of just logging the debug traceback. This will improve readability and allow users to understand what went wrong at a glance when dealing with API calls without necessarily needing additional information beyond the response code and message itself.

2 changes: 1 addition & 1 deletion core/app/api/v2/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions core/app/dto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
15 changes: 0 additions & 15 deletions core/app/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ type ISettingService interface {
UpdateTerminal(req dto.TerminalInfo) error

UpdateSystemSSL() error

GenerateRSAKey() error

GetLoginSetting() (*dto.SystemSetting, error)
}

func NewISettingService() ISettingService {
Expand Down Expand Up @@ -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
}
Loading
Loading