#NEWLINE# def authenticate( self , username = None , password = None ) : #NEWLINE# #INDENT# auth_user = None #NEWLINE# try : #NEWLINE# #INDENT# ( admin , uuser ) = [ uname . strip ( ) for uname in username . split ( ' as ' ) ] #NEWLINE# admin_obj = User . objects . get ( username = admin ) #NEWLINE# if ( ( admin_obj . is_superuser or ( IMPOSTOR_GROUP and ( IMPOSTOR_GROUP in admin_obj . groups . all ( ) ) ) ) and admin_obj . check_password ( password ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# auth_user = User . objects . get ( username = uuser ) #NEWLINE# #UNINDENT# except User . DoesNotExist : #NEWLINE# #INDENT# auth_user = User . objects . get ( email = uuser ) #NEWLINE# #UNINDENT# #UNINDENT# if auth_user : #NEWLINE# #INDENT# if ( auth_user . is_superuser and ( not admin_obj . is_superuser ) ) : #NEWLINE# #INDENT# auth_user = None #NEWLINE# raise Exception ( 'Superuser can only be impersonated by a superuser.' ) #NEWLINE# #UNINDENT# request = find_request ( ) #NEWLINE# ip_addr = '' #NEWLINE# if request : #NEWLINE# #INDENT# ip_addr = request . META . get ( 'HTTP_X_FORWARDED_FOR' , request . META . get ( 'HTTP_X_REAL_IP' , request . META . get ( 'REMOTE_ADDR' , '' ) ) ) #NEWLINE# if ( ',' in ip_addr ) : #NEWLINE# #INDENT# ip_addr = ip_addr . split ( ',' , 1 ) [ 0 ] . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# log_entry = ImpostorLog . objects . create ( impostor = admin_obj , imposted_as = auth_user , impostor_ip = ip_addr ) #NEWLINE# if ( log_entry . token and request ) : #NEWLINE# #INDENT# request . session [ 'impostor_token' ] = log_entry . token #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return auth_user