feature: logout when the user is invalidated (#652)

This commit is contained in:
yubo 2021-04-13 14:33:21 +08:00 committed by GitHub
parent 59366e4d3a
commit 5f1c868006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -33,6 +33,10 @@ func PostCallback(in *ssoc.CallbackOutput) error {
return defaultAuth.PostCallback(in)
}
func LogoutByUsername(username string) error {
return defaultAuth.LogoutByUsername(username)
}
func DeleteSession(sid string) error {
return defaultAuth.DeleteSession(sid)
}

View File

@ -220,6 +220,23 @@ func (p *Authenticator) PostCallback(in *ssoc.CallbackOutput) error {
return nil
}
// LogoutByUsername
func (p *Authenticator) LogoutByUsername(username string) error {
if !p.extraMode {
return nil
}
tokens := []models.Token{}
models.DB["sso"].SQL("select * from token where user_name=?", username).Find(&tokens)
for i := 0; i < len(tokens); i++ {
logger.Debugf("[logout by username] delete session by token %s %s", username, tokens[i].AccessToken)
deleteSessionByToken(&tokens[i])
}
return nil
}
// ChangePasswordRedirect check user should change password before login
// return err when need changePassword
func (p *Authenticator) changePasswordRedirect(in *ssoc.CallbackOutput, cf *models.AuthConfig) (err error) {

View File

@ -168,6 +168,9 @@ func userProfilePut(c *gin.Context) {
if target.Status == models.USER_S_ACTIVE {
target.LoginErrNum = 0
}
if target.Status == models.USER_S_INACTIVE {
auth.LogoutByUsername(target.Username)
}
}
if f.Organization != target.Organization {