user1003121
user1003121

Reputation: 1219

django returning multiple values

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 ??

Upvotes: 0

Views: 929

Answers (4)

user1003121
user1003121

Reputation: 1219

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.

Upvotes: 0

Matt Seymour
Matt Seymour

Reputation: 9395

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

Upvotes: 0

DrTyrsa
DrTyrsa

Reputation: 31951

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

Upvotes: 0

freakish
freakish

Reputation: 56467

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.

Upvotes: 1

Related Questions