#NEWLINE# @ csrf_protect #NEWLINE# @ never_cache #NEWLINE# def login( request , template_name = 'registration/login.html' , redirect_field_name = REDIRECT_FIELD_NAME , authentication_form = AuthenticationForm , current_app = None , extra_context = None ) : #NEWLINE# #INDENT# '\n    Displays the login form and handles the login action.\n    ' #NEWLINE# redirect_to = request . REQUEST . get ( redirect_field_name , '' ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = authentication_form ( data = request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# netloc = urlparse . urlparse ( redirect_to ) [ 1 ] #NEWLINE# if ( not redirect_to ) : #NEWLINE# #INDENT# redirect_to = settings . LOGIN_REDIRECT_URL #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( netloc and ( netloc != request . get_host ( ) ) ) : #NEWLINE# #INDENT# redirect_to = settings . LOGIN_REDIRECT_URL #NEWLINE# #UNINDENT# #UNINDENT# auth_login ( request , form . get_user ( ) ) #NEWLINE# if request . session . test_cookie_worked ( ) : #NEWLINE# #INDENT# request . session . delete_test_cookie ( ) #NEWLINE# #UNINDENT# return HttpResponseRedirect ( redirect_to ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = authentication_form ( request ) #NEWLINE# #UNINDENT# request . session . set_test_cookie ( ) #NEWLINE# current_site = get_current_site ( request ) #NEWLINE# context = { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# redirect_field_name : redirect_to , #NEWLINE# 'site' : current_site , #NEWLINE# 'site_name' : current_site . name , #NEWLINE# #UNINDENT# } #NEWLINE# context . update ( ( extra_context or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# return render_to_response ( template_name , context , context_instance = RequestContext ( request , current_app = current_app ) )