0

My application provides 2 ways to login into website (same page). First is username & password and other is username & emergency password. I have backend.py as

class PersonAuthenticationBackend(object):
  def authenticate(self, username=None, password=None):
    try:
      person = User.objects.get(username=username)
      if person.check_password(password):
        return person
      else:
        try:
          db_ecode=person.get_profile().u_emergency_code
          if password==db_ecode:
            print "EMERGENCY LOGIN"
            return person
          else :
            return None
        except:
          return None
    except User.DoesNotExist:
            pass
    return None

    def get_user(self, user_id):
      try:
          return User.objects.get(pk=user_id)
      except User.DoesNotExist:
          return None

Now how do I know if user has logged in using emergency login ??

2
  • Look for "EMERGENCY LOGIN" line in the output. :-) What task are you trying to solve? Commented Feb 9, 2012 at 10:50
  • the question is where in the code do you need to know that? you already know that when you print "EMERGENCY LOGIN" string. Commented Feb 9, 2012 at 10:51

4 Answers 4

1

This is python, you can dynamically add attributes to objects:

if person.check_password(password):
    person.loged_normally = True
    return person

and

if password==db_ecode:
    print "EMERGENCY LOGIN"
    person.loged_normally = False
    return person

If you want to have the information not only during one request but during entire session, then you have to save it to the session engine and/or database.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a very bad idea. Code like this is very hard to maintain and test.
0

Send a signal. Make a log record. Or you are looking for somethig else?

Comments

0

You could always add a sessions which you can use later?

Comments

0
person.a = lambda: None
setattr(person.a, 'login', True)

and then, retrive using

print "person.a %s"%person.a.login

and then store it in session.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.