From 1951c51c8e087b92a981f71a7214198e1ca5ae84 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 5 Feb 2024 14:43:35 +0100 Subject: [PATCH] Revert "Unify password changing and invalidate auth tokens (#27625)" This reverts commit 688d4a1f719d2df4d2626453f4bc042c1874a375. --- models/auth/auth_token.go | 5 ----- services/user/delete.go | 4 ---- services/user/update.go | 12 +----------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/models/auth/auth_token.go b/models/auth/auth_token.go index 81f07d1a8..65f1b169e 100644 --- a/models/auth/auth_token.go +++ b/models/auth/auth_token.go @@ -54,11 +54,6 @@ func DeleteAuthTokenByID(ctx context.Context, id string) error { return err } -func DeleteAuthTokensByUserID(ctx context.Context, uid int64) error { - _, err := db.GetEngine(ctx).Where(builder.Eq{"user_id": uid}).Delete(&AuthToken{}) - return err -} - func DeleteExpiredAuthTokens(ctx context.Context) error { _, err := db.GetEngine(ctx).Where(builder.Lt{"expires_unix": timeutil.TimeStampNow()}).Delete(&AuthToken{}) return err diff --git a/services/user/delete.go b/services/user/delete.go index 000910319..0e9c86617 100644 --- a/services/user/delete.go +++ b/services/user/delete.go @@ -187,10 +187,6 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) } // ***** END: ExternalLoginUser ***** - if err := auth_model.DeleteAuthTokensByUserID(ctx, u.ID); err != nil { - return fmt.Errorf("DeleteAuthTokensByUserID: %w", err) - } - if _, err = db.DeleteByID[user_model.User](ctx, u.ID); err != nil { return fmt.Errorf("delete: %w", err) } diff --git a/services/user/update.go b/services/user/update.go index cbaf90053..849757c8b 100644 --- a/services/user/update.go +++ b/services/user/update.go @@ -183,7 +183,6 @@ func UpdateAuth(ctx context.Context, u *user_model.User, opts *UpdateAuthOptions u.LoginName = opts.LoginName.Value() } - deleteAuthTokens := false if opts.Password.Has() && (u.IsLocal() || u.IsOAuth2()) { password := opts.Password.Value() @@ -200,8 +199,6 @@ func UpdateAuth(ctx context.Context, u *user_model.User, opts *UpdateAuthOptions if err := u.SetPassword(password); err != nil { return err } - - deleteAuthTokens = true } if opts.MustChangePassword.Has() { @@ -211,12 +208,5 @@ func UpdateAuth(ctx context.Context, u *user_model.User, opts *UpdateAuthOptions u.ProhibitLogin = opts.ProhibitLogin.Value() } - if err := user_model.UpdateUserCols(ctx, u, "login_type", "login_source", "login_name", "passwd", "passwd_hash_algo", "salt", "must_change_password", "prohibit_login"); err != nil { - return err - } - - if deleteAuthTokens { - return auth_model.DeleteAuthTokensByUserID(ctx, u.ID) - } - return nil + return user_model.UpdateUserCols(ctx, u, "login_type", "login_source", "login_name", "passwd", "passwd_hash_algo", "salt", "must_change_password", "prohibit_login") }