Skip to content

Commit

Permalink
feat(memberships): added smart after-login router
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 11, 2023
1 parent 601dbc9 commit ae88909
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 2 additions & 0 deletions fiesta/apps/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.urls import path
from django.views.generic import RedirectView

from apps.accounts.views.index import AfterLoginRedirectView
from apps.accounts.views.membership import MyMembershipsView, NewSectionMembershipFormView
from apps.accounts.views.profile import MyProfileDetailView, MyProfileUpdateView, ProfileFinishFormView

Expand All @@ -21,4 +22,5 @@
path("membership", MyMembershipsView.as_view(), name="membership"),
# path("", TemplateView.as_view(template_name="accounts/index.html")),
# path("login", LoginViewNotInSectionSpace.as_view(), name="login"),
path("after-login", AfterLoginRedirectView.as_view(), name="after-login"),
]
32 changes: 22 additions & 10 deletions fiesta/apps/accounts/views/index.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from __future__ import annotations

# class BuddySystemEntrance(EnsureInSectionSpaceViewMixin, PluginConfigurationViewMixin, TemplateView):
# def get(self, request, *args, **kwargs):
# if self.request.membership.is_international:
# return HttpResponseRedirect(reverse("buddy_system:new-request"))
#
# c: BuddySystemConfiguration = self.configuration
# if c.matching_policy_instance.can_member_match:
# return HttpResponseRedirect(reverse("buddy_system:matching-requests"))
#
# return HttpResponseRedirect(reverse("buddy_system:index"))
from django.urls import reverse
from django.views.generic import RedirectView

from apps.accounts.templatetags.memberships import section_membership_activation_url
from apps.plugins.views import PluginConfigurationViewMixin
from apps.sections.models import SectionMembership
from apps.sections.views.mixins.section_space import EnsureNotInSectionSpaceViewMixin


class AfterLoginRedirectView(
EnsureNotInSectionSpaceViewMixin,
PluginConfigurationViewMixin,
RedirectView,
):
def get_redirect_url(self):
active_memberships = self.request.all_memberships.filter(state=SectionMembership.State.ACTIVE)
if active_memberships.count() == 1:
m: SectionMembership = active_memberships.first()

return section_membership_activation_url(dict(request=self.request), m)

return reverse("accounts:membership")
4 changes: 1 addition & 3 deletions fiesta/fiesta/settings/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class AuthConfigMixin:
SOCIALACCOUNT_ADAPTER = "apps.accounts.adapters.SocialAccountAdapter"
# general django urls
LOGIN_URL = "/auth/login"
# TODO: do redirect to special url with smart router, which redirects to section
# (if user has only one section)
LOGIN_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/accounts/after-login"

# fixme: verify it
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True # False by default
Expand Down

0 comments on commit ae88909

Please sign in to comment.