Django: Adding extra logic to the login method? -


i've got django app views use @login_required decorator.

what's easiest/best way add logic login system? want add constraints such subscription site still valid. if has expired want direct them page says subscription has expired , they'll need pay again.

ideally signal great, can't find kind of post_login signal. failing suppose options write own login handler, or have kind of check_valid_user() method call inside each of views. don't favour latter since dev forget add it, , users content free.

what approach people recommend?

thanks

you can write own login view or better own authbackend(second example).

from django.contrib.auth.views import login core_login  #myapp/views.py @ratelimit_post(minutes = 1, requests = 4, key_field = 'username')  def login(request,template_name):     django.contrib.auth import authenticate     user = authenticate(username='john', password='secret')     template_name = "template_name" + "aaaaa"     return core_login(request, template_name)   #myapp/ursl.py #override default url   ...   (r'^accounts/login/$', 'myapp.views.login', {'template_name': 'profile/login.html'}),    ...    #backends/authemailbackend.py django.contrib.auth import authenticate user = authenticate(username='john', password='secret') django.contrib.auth.backends import modelbackend django.contrib.auth.models import user django.forms.fields import email_re  class emailbackend(modelbackend):     def authenticate(self, username=none, password=none):         if email_re.search(username):             try:                 user = user.objects.get(email=username)                 if user.check_password(password):                     return user             except user.doesnotexist:                 return none         return none  ~                                                                                                                                                                                      ~                             #settings.py authentication_backends = (     "myapp.backends.authemailbackend.emailbackend",     "django.contrib.auth.backends.modelbackend", ) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -