File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
1515 "github.com/alist-org/alist/v3/internal/session"
1616 "github.com/alist-org/alist/v3/internal/setting"
1717 "github.com/alist-org/alist/v3/server/common"
18+ "github.com/alist-org/alist/v3/server/middlewares"
1819 "github.com/gin-gonic/gin"
1920 "github.com/pquerna/otp/totp"
2021)
@@ -82,13 +83,18 @@ func loginHash(c *gin.Context, req *LoginReq) {
8283 return
8384 }
8485 }
86+ // generate device session
87+ if ! middlewares .HandleSession (c , user ) {
88+ return
89+ }
8590 // generate token
8691 token , err := common .GenerateToken (user )
8792 if err != nil {
8893 common .ErrorResp (c , err , 400 , true )
8994 return
9095 }
91- common .SuccessResp (c , gin.H {"token" : token })
96+ key := c .GetString ("device_key" )
97+ common .SuccessResp (c , gin.H {"token" : token , "device_key" : key })
9298 loginCache .Del (ip )
9399}
94100
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ func Auth(c *gin.Context) {
2626 c .Abort ()
2727 return
2828 }
29- if ! handleSession (c , admin ) {
29+ if ! HandleSession (c , admin ) {
3030 return
3131 }
3232 log .Debugf ("use admin token: %+v" , admin )
@@ -54,7 +54,7 @@ func Auth(c *gin.Context) {
5454 }
5555 guest .RolesDetail = roles
5656 }
57- if ! handleSession (c , guest ) {
57+ if ! HandleSession (c , guest ) {
5858 return
5959 }
6060 log .Debugf ("use empty token: %+v" , guest )
@@ -93,14 +93,15 @@ func Auth(c *gin.Context) {
9393 }
9494 user .RolesDetail = roles
9595 }
96- if ! handleSession (c , user ) {
96+ if ! HandleSession (c , user ) {
9797 return
9898 }
9999 log .Debugf ("use login token: %+v" , user )
100100 c .Next ()
101101}
102102
103- func handleSession (c * gin.Context , user * model.User ) bool {
103+ // HandleSession verifies device sessions and stores context values.
104+ func HandleSession (c * gin.Context , user * model.User ) bool {
104105 clientID := c .GetHeader ("Client-Id" )
105106 if clientID == "" {
106107 clientID = c .Query ("client_id" )
You can’t perform that action at this time.
0 commit comments