feat: 合并Gin_Vue
This commit is contained in:
32
src/lib_features/account/account.go
Normal file
32
src/lib_features/account/account.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package libfeatures
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ems.agt/lib/dborm"
|
||||
"ems.agt/lib/oauth"
|
||||
libConfig "ems.agt/restagent/config"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/redis"
|
||||
)
|
||||
|
||||
// SessionToken 设置登录会话-兼容旧登录方式
|
||||
func SessionToken(username, sourceAddr string) bool {
|
||||
token, _ := redis.Get("", "session_token")
|
||||
if token != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
token = oauth.GenRandToken("omc") // Generate new token to session ID
|
||||
affected, err := dborm.XormInsertSession(username, sourceAddr, token, libConfig.GetExpiresFromConfig(), libConfig.GetYamlConfig().Auth.Session)
|
||||
if err != nil {
|
||||
logger.Errorf("SessionToken XormInsertSession err %v", err)
|
||||
}
|
||||
if affected == 1 {
|
||||
// 过期时间单位秒 配置1800是半小时
|
||||
expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
|
||||
redis.SetByExpire("", "session_token", token, expireTime)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user