Validate main PHP sessions against user IDs

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-07-13 08:03:07 +08:00
parent 683645be8e
commit 16ab2549d7
5 changed files with 58 additions and 14 deletions
+10
View File
@@ -19,3 +19,13 @@ func (ss *Session) SetAuthKey(authKey *loginmodel.AuthKey) {
return
}
}
func (ss *Session) IsAuthorizeTokenForUser(token string, userID int) (bool, error) {
if token == "" || userID <= 0 {
return false, nil
}
return ss.UserEng.Table(new(loginmodel.AuthKey)).
Where("authorize_token = ? AND user_id = ?", token, userID).
Exist()
}
+9 -6
View File
@@ -53,15 +53,18 @@ func New(ctx *gin.Context) *Session {
ss.UserEng = db.UserEng.NewSession()
ss.UserEng.Begin()
userID := ctx.GetString("userid")
if userID != "" {
ss.UserPref = ss.GetUserPref(userID)
ss.UserID = ss.UserPref.UserID
}
return ss
}
func (ss *Session) LoadUser(userID string) {
ss.UserPref = ss.GetUserPref(userID)
ss.UserID = ss.UserPref.UserID
}
func (ss *Session) Done() bool {
return ss.done
}
func Get(ctx *gin.Context) *Session {
return ctx.MustGet("session").(*Session)
}