#NEWLINE# @ secure_required #NEWLINE# def signin( request , auth_form = AuthenticationForm , template_name = 'userena/signin_form.html' , redirect_field_name = REDIRECT_FIELD_NAME , redirect_signin_function = signin_redirect , extra_context = None ) : #NEWLINE# #INDENT# '\n    Signin using email or username with password.\n\n    Signs a user in by combining email/username with password. If the\n    combination is correct and the user :func:`is_active` the\n    :func:`redirect_signin_function` is called with the arguments\n    ``REDIRECT_FIELD_NAME`` and an instance of the :class:`User` who is is\n    trying the login. The returned value of the function will be the URL that\n    is redirected to.\n\n    A user can also select to be remembered for ``USERENA_REMEMBER_DAYS``.\n\n    :param auth_form:\n        Form to use for signing the user in. Defaults to the\n        :class:`AuthenticationForm` supplied by userena.\n\n    :param template_name:\n        String defining the name of the template to use. Defaults to\n        ``userena/signin_form.html``.\n\n    :param redirect_field_name:\n        Form field name which contains the value for a redirect to the\n        succeeding page. Defaults to ``next`` and is set in\n        ``REDIRECT_FIELD_NAME`` setting.\n\n    :param redirect_signin_function:\n        Function which handles the redirect. This functions gets the value of\n        ``REDIRECT_FIELD_NAME`` and the :class:`User` who has logged in. It\n        must return a string which specifies the URI to redirect to.\n\n    :param extra_context:\n        A dictionary containing extra variables that should be passed to the\n        rendered template. The ``form`` key is always the ``auth_form``.\n\n    **Context**\n\n    ``form``\n        Form used for authentication supplied by ``auth_form``.\n\n    ' #NEWLINE# form = auth_form ( ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = auth_form ( request . POST , request . FILES ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# ( identification , password , remember_me ) = ( form . cleaned_data [ 'identification' ] , form . cleaned_data [ 'password' ] , form . cleaned_data [ 'remember_me' ] ) #NEWLINE# user = authenticate ( identification = identification , password = password ) #NEWLINE# if user . is_active : #NEWLINE# #INDENT# login ( request , user ) #NEWLINE# if remember_me : #NEWLINE# #INDENT# request . session . set_expiry ( ( userena_settings . USERENA_REMEMBER_ME_DAYS [ 1 ] * 86400 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# request . session . set_expiry ( 0 ) #NEWLINE# #UNINDENT# if userena_settings . USERENA_USE_MESSAGES : #NEWLINE# #INDENT# messages . success ( request , _ ( 'You have been signed in.' ) , fail_silently = True ) #NEWLINE# #UNINDENT# userena_signals . account_signin . send ( sender = None , user = user ) #NEWLINE# redirect_to = redirect_signin_function ( request . GET . get ( redirect_field_name , request . POST . get ( identification ) ) , user ) #NEWLINE# return HttpResponseRedirect ( redirect_to ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return redirect ( reverse ( 'userena_disabled' , kwargs = { #NEWLINE# #INDENT# 'username' : user . username , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not extra_context ) : #NEWLINE# #INDENT# extra_context = dict ( ) #NEWLINE# #UNINDENT# extra_context . update ( { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# 'next' : request . GET . get ( redirect_field_name , request . POST . get ( redirect_field_name ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ExtraContextTemplateView . as_view ( template_name = template_name , extra_context = extra_context ) ( request )