<s> from django import forms <EOL> from django . contrib . auth import authenticate <EOL> from django . contrib . auth . forms import AuthenticationForm <EOL> from django . contrib . auth . models import User <EOL> from django . utils . translation import ugettext_lazy , ugettext as _ <EOL> ERROR_MESSAGE = ugettext_lazy ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class AdminAuthenticationForm ( AuthenticationForm ) : <EOL> """<STR_LIT>""" <EOL> this_is_the_login_form = forms . BooleanField ( widget = forms . HiddenInput , initial = <NUM_LIT:1> , <EOL> error_messages = { '<STR_LIT>' : ugettext_lazy ( "<STR_LIT>" ) } ) <EOL> def clean ( self ) : <EOL> username = self . cleaned_data . get ( '<STR_LIT:username>' ) <EOL> password = self . cleaned_data . get ( '<STR_LIT:password>' ) <EOL> message = ERROR_MESSAGE <EOL> if username and password : <EOL> self . user_cache = authenticate ( username = username , password = password ) <EOL> if self . user_cache is None : <EOL> if u'<STR_LIT:@>' in username : <EOL> try : <EOL> user = User . objects . get ( email = username ) <EOL> except ( User . DoesNotExist , User . MultipleObjectsReturned ) : <EOL> pass <EOL> else : <EOL> if user . check_password ( password ) : <EOL> message = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % user . username <EOL> raise forms . ValidationError ( message ) <EOL> elif not self . user_cache . is_active or not self . user_cache . is_staff : <EOL> raise forms . ValidationError ( message ) <EOL> self . check_for_test_cookie ( ) <EOL> return self . cleaned_data </s>
