Login

Login as Any Site user

Author:
madhav.bnk
Posted:
November 29, 2009
Language:
Python
Version:
1.1
Score:
0 (after 0 ratings)

If you are an admin of a django site and many times it feels to visualize or experience how a normal website user actually sees different pages of your website. So to get this done, we create a normal user (just for testing purposes) and check the same, which is good. But sometimes we need to actually login as the same person to resolve a issue or to trace a particular exception which only one user or a specific set of users are experiencing.

Usage:login_using_email(request, "[email protected]")

I have mentioned only the helper or core method which is responsible for the actual user "logging-in" simulation. Proper view permissions(remember I mentioned only admins should use this) can be wrapped around it. Any thoughts on improving it? Always invited....

Public Clone Url: git://gist.github.com/242439.git

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def login_using_email(request, email):
    '''DONT EVER USE this method for normal purposes. This is only there, for debugging specific problems related to users'''
    from django.contrib.auth import get_backends
    backend = get_backends()[0]
    from django.contrib.auth.models import User
    user = User.objects.get(email=email)
    user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
    from django.contrib.auth import login as django_login
    django_login(request, user)
    #set_any_extra_session_variables(request)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

KomarovPetr26 (on December 2, 2011):

ВИП-сваха для брака с богачом

#

Please login first before commenting.