fix login edge case
This commit is contained in:
parent
569eb44c25
commit
095342846a
3 changed files with 6 additions and 5 deletions
|
@ -33,7 +33,7 @@ urlpatterns = [
|
|||
path(
|
||||
"users/OAuth2_login/",
|
||||
RedirectView.as_view(url="/account/login/oauth", query_string=True),
|
||||
),
|
||||
), # for backward compatibility
|
||||
path(
|
||||
"auth/edit", # some apps like elk will use this url
|
||||
RedirectView.as_view(url="/account/profile", query_string=True),
|
||||
|
|
|
@ -122,6 +122,7 @@ def connect(request):
|
|||
if app.api_domain and app.api_domain != app.domain_name:
|
||||
login_domain = app.api_domain
|
||||
login_url = get_mastodon_login_url(app, login_domain, request)
|
||||
request.session["mastodon_domain"] = app.domain_name
|
||||
resp = redirect(login_url)
|
||||
resp.set_cookie("mastodon_domain", app.domain_name)
|
||||
return resp
|
||||
|
@ -139,7 +140,7 @@ def connect(request):
|
|||
# mastodon server redirect back to here
|
||||
@require_http_methods(["GET"])
|
||||
@mastodon_request_included
|
||||
def OAuth2_login(request):
|
||||
def connect_redirect_back(request):
|
||||
code = request.GET.get("code")
|
||||
if not code:
|
||||
return render(
|
||||
|
@ -147,12 +148,12 @@ def OAuth2_login(request):
|
|||
"common/error.html",
|
||||
{"msg": _("认证失败😫"), "secondary_msg": _("Mastodon服务未能返回有效认证信息")},
|
||||
)
|
||||
site = request.COOKIES.get("mastodon_domain")
|
||||
site = request.session.get("mastodon_domain")
|
||||
if not site:
|
||||
return render(
|
||||
request,
|
||||
"common/error.html",
|
||||
{"msg": _("认证失败😫"), "secondary_msg": _("无效Cookie信息")},
|
||||
{"msg": _("认证失败😫"), "secondary_msg": _("无效会话信息")},
|
||||
)
|
||||
try:
|
||||
token, refresh_token = obtain_token(site, request, code)
|
||||
|
|
|
@ -5,7 +5,7 @@ from .views import *
|
|||
app_name = "users"
|
||||
urlpatterns = [
|
||||
path("login", login, name="login"),
|
||||
path("login/oauth", OAuth2_login, name="login_oauth"),
|
||||
path("login/oauth", connect_redirect_back, name="login_oauth"),
|
||||
path("login/email", verify_email, name="login_email"),
|
||||
path("verify_email", verify_email, name="verify_email"),
|
||||
path("register_email", verify_email, name="register_email"),
|
||||
|
|
Loading…
Add table
Reference in a new issue