@never_cache
def login(request, template_name='accounts/login.html',
    redirect_field_name=REDIRECT_FIELD_NAME,
    authentication_form=ExtendedAuthenticationForm):
    """
    A copy of ``django.contrib.auth.views.login()`` that inherits an extended
    authentication form allowing the user to save their session. Its template
    contains all the different methods for authentication. However, if sent
    a POST, it will use Django's default account backend to log the user in.

    """
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL
            standard_login(request, form.get_user())
            messages.success(request, 'Welcome back! You have been logged in!')
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            if form.cleaned_data['remember']:
                request.session[settings.PERSISTENT_SESSION_KEY] = True
            else:
                request.session.set_expiry(0)
            return redirect(redirect_to)
    else:
        form = authentication_form(request)
    request.session.set_test_cookie()

    return simple.direct_to_template(request,
        template = template_name,
        extra_context = {
            'form': form,
            redirect_field_name: redirect_to,
        }
    )
dataset/ETHPy150Open bryanveloso/hello-social-registration/social_registration/views.py/login/original