Skip to content

Commit

Permalink
Fix ident
Browse files Browse the repository at this point in the history
  • Loading branch information
KiselevAlexander committed Feb 11, 2025
1 parent d1aa040 commit b2f42a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion web/controller/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (controller *APIController) initRouter(router *gin.RouterGroup) {
apiV1 := router.Group("/panel/api")
apiV1.Use(controller.checkLogin)

inboundsApiGroup := apiV1.Group("/inbounds")
inboundsApiGroup := apiV1.Group("/inbounds")
controller.inbounds = NewInboundController(inboundsApiGroup)

inboundRoutes := []struct {
Expand Down
18 changes: 9 additions & 9 deletions web/controller/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func I18nWeb(c *gin.Context, name string, params ...string) string {
}

func (a *BaseController) apiTokenGuard(c *gin.Context) {
bearerToken := c.Request.Header.Get("Authorization")
tokenParts := strings.Split(bearerToken, " ")
if len(tokenParts) != 2 {
bearerToken := c.Request.Header.Get("Authorization")
tokenParts := strings.Split(bearerToken, " ")
if len(tokenParts) != 2 {
pureJsonMsg(c, http.StatusUnauthorized, false, "Invalid token format")
c.Abort()
return
}
reqToken := tokenParts[1]
c.Abort()
return
}
reqToken := tokenParts[1]
token, err := a.settingService.GetApiToken()

if err != nil {
Expand All @@ -59,7 +59,7 @@ func (a *BaseController) apiTokenGuard(c *gin.Context) {
}

if reqToken != token {
pureJsonMsg(c, http.StatusUnauthorized, false, "Auth failed")
pureJsonMsg(c, http.StatusUnauthorized, false, "Auth failed")
c.Abort()
return
}
Expand All @@ -72,7 +72,7 @@ func (a *BaseController) apiTokenGuard(c *gin.Context) {

session.SetSessionUser(c, user)

c.Next()
c.Next()

session.ClearSession(c)
}
10 changes: 5 additions & 5 deletions web/controller/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ func (a *SettingController) getDefaultXrayConfig(c *gin.Context) {
}

func (a *SettingController) getApiToken(c *gin.Context) {
response := &ApiTokenResponse{}
response := &ApiTokenResponse{}
token, err := a.settingService.GetApiToken()
if err != nil {
jsonObj(c, response , err)
return
jsonObj(c, response , err)
return
}

response.Token = token

jsonObj(c, response , nil)
jsonObj(c, response , nil)
}

func (a *SettingController) generateApiToken(c *gin.Context) {
response := &ApiTokenResponse{}
response := &ApiTokenResponse{}
randomBytes := make([]byte, 32)

_, err := rand.Read(randomBytes)
Expand Down

0 comments on commit b2f42a5

Please sign in to comment.