mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 19:47:07 +09:00
Partially backport #39686
This commit is contained in:
1 parent
6064554b8d
commit
33aaf0cfa3
4 files changed
+54
-11
No files matched your search
@@ -77,9 +77,9 @@ func prepareCommonAuthPageData(ctx *context.Context, opt CommonAuthOptions) {
|
||||
|
||||
// autoSignIn reads cookie and try to auto-login.
|
||||
func autoSignIn(ctx *context.Context) (bool, error) {
|
||||
isSucceed := false
|
||||
keepRememberCookie := false
|
||||
defer func() {
|
||||
if !isSucceed {
|
||||
if !keepRememberCookie {
|
||||
ctx.DeleteSiteCookie(setting.CookieRememberName)
|
||||
}
|
||||
}()
|
||||
@@ -112,14 +112,20 @@ func autoSignIn(ctx *context.Context) (bool, error) {
|
||||
return false, fmt.Errorf("HasTwoFactorOrWebAuthn: %w", err)
|
||||
}
|
||||
|
||||
isSucceed = true
|
||||
|
||||
nt, token, err := auth_service.RegenerateAuthToken(ctx, t)
|
||||
if errors.Is(err, auth_service.ErrAuthTokenRotationConflict) {
|
||||
keepRememberCookie = true // A late response must not clear the winner's cookie.
|
||||
return false, nil
|
||||
}
|
||||
if errors.Is(err, auth_service.ErrAuthTokenExpired) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
ctx.SetSiteCookie(setting.CookieRememberName, nt.ID+":"+token, setting.LogInRememberDays*timeutil.Day)
|
||||
keepRememberCookie = true
|
||||
|
||||
if err := regenerateSession(ctx, map[string]any{
|
||||
session.KeyUID: u.ID,
|
||||
|
||||
Reference in new issue
Block a user