Skip to content

Save last login method in a cookie #12286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion readthedocs/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import StrEnum
from enum import auto

import structlog
from allauth.account.views import LoginView as AllAuthLoginView
from allauth.account.views import LogoutView as AllAuthLogoutView
from allauth.socialaccount.providers.github.provider import GitHubProvider
Expand Down Expand Up @@ -52,8 +53,29 @@
from readthedocs.projects.utils import get_csv_file


log = structlog.get_logger(__name__)


class LoginViewBase(AllAuthLoginView):
pass
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
last_login_method = self.request.COOKIES.get("last-login-method")
context_data["last_login_method"] = last_login_method

last_login_tab = None
if last_login_method == "email":
last_login_tab = "email"
if last_login_method in ("githubapp", "github", "gitlab", "bitbucket_oauth2", "google"):
last_login_tab = "vcs"
if last_login_method == "sso":
last_login_tab = "sso"
log.debug(
"Login method.",
last_login_method=last_login_method,
last_login_tab=last_login_tab,
)
context_data["last_login_tab"] = last_login_tab
return context_data


class LoginView(SettingsOverrideObject):
Expand Down