检查session是否存在返回信息
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"ems.agt/features/sys_role/model"
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
"ems.agt/lib/oauth"
|
"ems.agt/lib/oauth"
|
||||||
|
|
||||||
@@ -681,6 +682,9 @@ type User struct {
|
|||||||
Phone string `json:"phone" xorm:"phone"`
|
Phone string `json:"phone" xorm:"phone"`
|
||||||
CreateTime string `json:"createTime" xorm:"create_time"`
|
CreateTime string `json:"createTime" xorm:"create_time"`
|
||||||
UpdateTime string `json:"updateTime" xorm:"update_time"`
|
UpdateTime string `json:"updateTime" xorm:"update_time"`
|
||||||
|
|
||||||
|
// 角色对象组
|
||||||
|
Roles []model.SysRole `json:"roles" xorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录密码登录错误次数
|
// 记录密码登录错误次数
|
||||||
@@ -1006,7 +1010,7 @@ func XormInsertSession(name, host, token string, expires uint32, sessionFlag str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XormUpdateSession update session
|
// XormUpdateSession update session
|
||||||
func XormLogoutUpdateSession(token string) (int64, error) {
|
func XormLogoutUpdateSession(token string) (Session, error) {
|
||||||
log.Info("XormLogoutUpdateSession processing... ")
|
log.Info("XormLogoutUpdateSession processing... ")
|
||||||
|
|
||||||
session := Session{Status: "offline", AccessToken: token}
|
session := Session{Status: "offline", AccessToken: token}
|
||||||
@@ -1015,13 +1019,19 @@ func XormLogoutUpdateSession(token string) (int64, error) {
|
|||||||
|
|
||||||
xSession := xEngine.NewSession()
|
xSession := xEngine.NewSession()
|
||||||
defer xSession.Close()
|
defer xSession.Close()
|
||||||
affected, err := xSession.Table("session").Where("access_token = ?", token).Update(session)
|
_, err := xSession.Table("session").Where("access_token = ?", token).Update(session)
|
||||||
xSession.Commit()
|
xSession.Commit()
|
||||||
return affected, err
|
// 查询记录返回
|
||||||
|
if err == nil {
|
||||||
|
session := Session{}
|
||||||
|
_, err = xSession.Table("session").Where("access_token = ?", token).Get(&session)
|
||||||
|
return session, err
|
||||||
|
}
|
||||||
|
return session, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// XormUpdateSessionShakeTime create session
|
// XormUpdateSessionShakeTime create session
|
||||||
func XormUpdateSessionShakeTime(token string) (int64, error) {
|
func XormUpdateSessionShakeTime(token string) (Session, error) {
|
||||||
log.Debug("XormUpdateSessionShakeTime processing... ")
|
log.Debug("XormUpdateSessionShakeTime processing... ")
|
||||||
|
|
||||||
session := Session{AccessToken: token}
|
session := Session{AccessToken: token}
|
||||||
@@ -1029,9 +1039,15 @@ func XormUpdateSessionShakeTime(token string) (int64, error) {
|
|||||||
session.ShakeTime.Time = time.Now()
|
session.ShakeTime.Time = time.Now()
|
||||||
xSession := xEngine.NewSession()
|
xSession := xEngine.NewSession()
|
||||||
defer xSession.Close()
|
defer xSession.Close()
|
||||||
affected, err := xSession.Table("session").Where("access_token = ?", token).Update(session)
|
_, err := xSession.Table("session").Where("access_token = ?", token).Update(session)
|
||||||
xSession.Commit()
|
xSession.Commit()
|
||||||
return affected, err
|
// 查询记录返回
|
||||||
|
if err == nil {
|
||||||
|
session := Session{}
|
||||||
|
_, err = xSession.Table("session").Where("access_token = ?", token).Get(&session)
|
||||||
|
return session, err
|
||||||
|
}
|
||||||
|
return session, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func XormExistValidToken(token string, expires uint32) bool {
|
func XormExistValidToken(token string, expires uint32) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user