Skip to content
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

Abstract out login and logout views #3

Open
vergeev opened this issue Jan 31, 2018 · 0 comments
Open

Abstract out login and logout views #3

vergeev opened this issue Jan 31, 2018 · 0 comments

Comments

@vergeev
Copy link
Contributor

vergeev commented Jan 31, 2018

Basically we want to do exactly what django.contrib.auth did with their urls.

This is how the user would create login and logout views with the current version:

url(r'^login/$', views.CustomSocialLoginView.as_view(), name='login'),
url(r'^logout/$', partial(auth_views.logout, template_name='logout.html'), name='logout'),

Instead we them to simply go

url(r'', include('django_social_pill.urls'), namespace='social_pill'),

To achieve this, we have to make the following view more generic:

class CustomSocialLoginView(TemplateView):
    template_name = 'login.html'

    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            return redirect('users:profile')
        return super().get(request, *args, **kwargs)

so that we could replace the template and the redirect url with an arbitrary one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant