mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-10-31 02:01:44 +08:00
如果登录前有历史旧信息一并删除
This commit is contained in:
@@ -18,6 +18,11 @@ func (w *WafLoginApi) LoginApi(c *gin.Context) {
|
||||
if err == nil {
|
||||
bean := wafAccountService.GetInfoByLoginApi(req)
|
||||
if bean.Id != "" {
|
||||
//如果存在旧的状态删除
|
||||
oldTokenInfo := wafTokenInfoService.GetInfoByLoginAccount(req.LoginAccount)
|
||||
if oldTokenInfo.Id != "" {
|
||||
wafTokenInfoService.DelApiByAccount(oldTokenInfo.LoginAccount)
|
||||
}
|
||||
//记录状态
|
||||
accessToken := utils.Md5String(uuid.NewV4().String())
|
||||
tokenInfo := wafTokenInfoService.AddApi(bean.LoginAccount, accessToken, c.ClientIP())
|
||||
|
||||
@@ -13,6 +13,7 @@ type WafTokenInfoService struct{}
|
||||
var WafTokenInfoServiceApp = new(WafTokenInfoService)
|
||||
|
||||
func (receiver *WafTokenInfoService) AddApi(loginAccount string, AccessToken string, LoginIp string) *model.TokenInfo {
|
||||
|
||||
var bean = &model.TokenInfo{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
@@ -51,7 +52,7 @@ func (receiver *WafTokenInfoService) ModifyApi(loginAccount string, AccessToken
|
||||
*/
|
||||
func (receiver *WafTokenInfoService) GetInfoByLoginAccount(loginAccount string) model.TokenInfo {
|
||||
var bean model.TokenInfo
|
||||
global.GWAF_LOCAL_DB.Debug().Where("login_account=? ", loginAccount).Find(&bean)
|
||||
global.GWAF_LOCAL_DB.Debug().Where("login_account=? ", loginAccount).Limit(1).Find(&bean)
|
||||
return bean
|
||||
}
|
||||
|
||||
@@ -78,3 +79,17 @@ func (receiver *WafTokenInfoService) DelApi(loginAccount string, AccessToken str
|
||||
err = global.GWAF_LOCAL_DB.Where("login_account = ? and access_token = ? ", loginAccount, AccessToken).Delete(model.TokenInfo{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
通过账号删除所有关联状态
|
||||
*/
|
||||
func (receiver *WafTokenInfoService) DelApiByAccount(loginAccount string) error {
|
||||
var bean model.TokenInfo
|
||||
err := global.GWAF_LOCAL_DB.Where("login_account = ?", loginAccount).First(&bean).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = global.GWAF_LOCAL_DB.Where("login_account = ?", loginAccount).Delete(model.TokenInfo{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user