<s> from django . db . models import Q <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . backends import ModelBackend <EOL> class ModelBackend ( ModelBackend ) : <EOL> """<STR_LIT>""" <EOL> def authenticate ( self , username = None , password = None ) : <EOL> try : <EOL> user = User . objects . get ( Q ( username = username ) | Q ( email = username ) , is_active = True ) <EOL> if user . check_password ( password ) : <EOL> return user <EOL> except User . DoesNotExist : <EOL> return None <EOL> def get_user ( self , user_id ) : <EOL> try : <EOL> return User . objects . get ( pk = user_id ) <EOL> except User . DoesNotExist : <EOL> return None </s>
