#NEWLINE# @ sensitive_post_parameters ( ) #NEWLINE# @ csrf_protect #NEWLINE# def login( request , template_name = settings . LOGIN_TEMPLATE , 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 settings . SPLUNK_WEB_INTEGRATED : #NEWLINE# #INDENT# return HttpResponseRedirect ( ( settings . LOGIN_URL + ( '?%s=%s' % ( redirect_field_name , redirect_to ) ) ) ) #NEWLINE# #UNINDENT# if ( not redirect_to ) : #NEWLINE# #INDENT# redirect_to = request . REQUEST . get ( ORIGINAL_REDIRECT_FIELD_NAME , '' ) #NEWLINE# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = authentication_form ( data = request . POST , request = request ) #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# redirectResponse = HttpResponseRedirect ( redirect_to ) #NEWLINE# user = form . get_user ( ) #NEWLINE# if user . splunkweb : #NEWLINE# #INDENT# session_id = user . splunkweb . session_id #NEWLINE# cval = user . splunkweb . cval #NEWLINE# uid = user . splunkweb . uid #NEWLINE# redirectResponse . set_cookie ( ( 'session_id_%s' % settings . SPLUNK_WEB_PORT ) , session_id ) #NEWLINE# redirectResponse . set_cookie ( 'cval' , cval ) #NEWLINE# redirectResponse . set_cookie ( 'uid' , uid ) #NEWLINE# #UNINDENT# session_token = user . service . token #NEWLINE# redirectResponse . set_cookie ( 'session_token' , aes . encrypt ( str ( session_token ) ) ) #NEWLINE# request . session . set_expiry ( 0 ) #NEWLINE# return redirectResponse #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = authentication_form ( request ) #NEWLINE# #UNINDENT# request . session . set_test_cookie ( ) #NEWLINE# context = { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# redirect_field_name : redirect_to , #NEWLINE# #UNINDENT# } #NEWLINE# if ( extra_context is not None ) : #NEWLINE# #INDENT# context . update ( extra_context ) #NEWLINE# #UNINDENT# return TemplateResponse ( request , template_name , context , current_app = current_app )