<s> import django . core . validators <EOL> from compat import get_user_model <EOL> User = get_user_model ( ) <EOL> class XAuthAuthenticationBackend ( object ) : <EOL> """<STR_LIT>""" <EOL> supports_anonymous_user = False <EOL> def authenticate ( self , x_auth_username = None , x_auth_password = None , <EOL> x_auth_mode = None ) : <EOL> """<STR_LIT>""" <EOL> if x_auth_mode != '<STR_LIT>' : <EOL> return None <EOL> try : <EOL> django . core . validators . validate_email ( x_auth_username ) <EOL> try : <EOL> user = User . objects . get ( email__iexact = x_auth_username ) <EOL> except User . DoesNotExist : <EOL> return None <EOL> except django . core . validators . ValidationError : <EOL> try : <EOL> user = User . objects . get ( username__iexact = x_auth_username ) <EOL> except User . DoesNotExist : <EOL> return None <EOL> if user . check_password ( x_auth_password ) : <EOL> return user <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>
