示例#1
0
def login(request):

    """ view that renders the login """

    if request.user.is_authenticated():
        return redirect('home')

    def captched_form(req=None, data=None):
        return CaptchaAuthenticationForm(
            req, data, initial={'captcha': request.META['REMOTE_ADDR']})

    template_name = "accounts/login.jade"

    login_try_count = request.session.get('login_try_count', 0)

    # If the form has been submitted...
    if request.method == "POST":
        request.session['login_try_count'] = login_try_count + 1

    if login_try_count >= 20:
        return django_login_view(request, authentication_form=captched_form,
                                 template_name=template_name)

    return django_login_view(request, authentication_form=AuthenticationForm,
                             template_name=template_name)
示例#2
0
def login(request):
    local_host = utils.get_local_host(request)
    ctx = {
        'facebook_login_url': utils.get_facebook_login_url(local_host),
        'google_login_url': utils.get_google_login_url(local_host)}
    return django_login_view(request, authentication_form=forms.LoginForm,
                             extra_context=ctx)
示例#3
0
def login(request):
    local_host = utils.get_local_host(request)
    ctx = {
        'facebook_login_url': utils.get_facebook_login_url(local_host),
        'google_login_url': utils.get_google_login_url(local_host)}
    return django_login_view(request, authentication_form=forms.LoginForm,
                             extra_context=ctx)
示例#4
0
def login(request, *args, **kwargs):
    """
    This delegates most of the work to `django.contrib.auth.views.login`, but
    we need to display an extra form, that allows users to login with just an
    email address. To do that without rewriting all the django login code, we
    tap into the TemplateResponse.context_data and add the extra form
    """
    response = django_login_view(request, *args, **kwargs)
    # if our special "OTHER_LOGIN" flag is present, we process our login form
    if request.method == "POST" and request.POST.get("form") == "OTHER_LOGIN":
        # make it look like the django login form wasn't filled out
        response.context_data['form'] = response.context_data[
            'form'].__class__(request)
        # now do the regular form processing stuff...
        other_form = LoginForm(request.POST)
        if other_form.is_valid():
            other_form.save(request=request)
            messages.success(
                request,
                "Check your email! You have been sent the login link.")
            return redirect(request.get_full_path())
    else:
        other_form = LoginForm()

    # patch in the other_form variable, so the template can render it.
    # Sometimes the django_login_view returns an HttpResponseRedirect, which
    # doesn't have context_data, hence the check
    if hasattr(response, "context_data"):
        response.context_data['other_form'] = other_form

    return response
示例#5
0
def login(request, *args, **kwargs):
    """
    This delegates most of the work to `django.contrib.auth.views.login`, but
    we need to display an extra form, that allows users to login with just an
    email address. To do that without rewriting all the django login code, we
    tap into the TemplateResponse.context_data and add the extra form
    """
    response = django_login_view(request, *args, **kwargs)
    # if our special "OTHER_LOGIN" flag is present, we process our login form
    if request.method == "POST" and request.POST.get("form") == "OTHER_LOGIN":
        # make it look like the django login form wasn't filled out
        response.context_data['form'] = response.context_data['form'].__class__(request)
        # now do the regular form processing stuff...
        other_form = LoginForm(request.POST)
        if other_form.is_valid():
            other_form.save(request=request)
            messages.success(request, "Check your email! You have been sent the login link.")
            return redirect(request.get_full_path())
    else:
        other_form = LoginForm()

    # patch in the other_form variable, so the template can render it.
    # Sometimes the django_login_view returns an HttpResponseRedirect, which
    # doesn't have context_data, hence the check
    if hasattr(response, "context_data"):
        response.context_data['other_form'] = other_form

    return response
示例#6
0
def login(request):
    response = django_login_view(
        request, template_name='login.html', redirect_field_name='next')
    # Don't redirect to locator view upon login.
    if (isinstance(response, HttpResponseRedirect) and
        response['Location'] == reverse('locator')):
        return redirect('home')
    return response
示例#7
0
def login(request):
    local_host = utils.get_local_host(request)
    notifications = Notification.objects.order_by('-pk')[:6]
    ctx = {
        'facebook_login_url': utils.get_facebook_login_url(local_host),
        'google_login_url': utils.get_google_login_url(local_host)
        }
    return django_login_view(request, authentication_form=forms.LoginForm,
                             extra_context=ctx)
示例#8
0
def login_view(request, template_name='registration/login.html',
                      redirect_field_name=REDIRECT_FIELD_NAME,
                      authentication_form=AuthenticationForm,
                      current_app=None, extra_context=None):

    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        return django_login_view(request, template_name, redirect_field_name, authentication_form, current_app, extra_context)
示例#9
0
def login(request):
    response = django_login_view(request,
                                 template_name='login.html',
                                 redirect_field_name='next')
    # Don't redirect to locator view upon login.
    if (isinstance(response, HttpResponseRedirect)
            and response['Location'] == reverse('locator')):
        return redirect('home')
    return response
示例#10
0
def login(request):
    user = request.user
    if user.is_authenticated() and user.is_staff:
        return redirect('account_main')
    else:
        return django_login_view(
            request,
            template_name='account/login.html',
            authentication_form=AuthenticationForm
        )
示例#11
0
def login(request):
    """ view that renders the login """

    def chapched_form(req=None, data=None):
        return CaptchaAuthenticationForm(
            req, data, initial={'captcha': request.META['REMOTE_ADDR']})

    # If the form has been submitted...
    template_name = "accounts/login.html"

    if request.method == "POST":
        login_try_count = request.session.get('login_try_count', 0)
        request.session['login_try_count'] = login_try_count + 1
        if login_try_count >= 2:
            return django_login_view(request,
                                     authentication_form=chapched_form,
                                     template_name=template_name)

    return django_login_view(request, authentication_form=AuthenticationForm,
                             template_name=template_name)
示例#12
0
def login_view(request, *args, **kwargs):
    if "extra_context" not in kwargs:
        kwargs["extra_context"] = {}
    if "backends" not in kwargs["extra_context"]:
        kwargs["extra_context"]["backends"] = []
    # Note: sorry but I really find the .setdefault() method non-obvious and
    # harder to re-read that the lines above.
    for backend in get_backends():
        if not isinstance(backend, SocialAuthBackend):
            continue # It should be checked using duck-typing instead
        kwargs["extra_context"]["backends"].append(backend.name)
    return django_login_view(request, *args, **kwargs)
示例#13
0
def login_view(request, *args, **kwargs):
    if "extra_context" not in kwargs:
        kwargs["extra_context"] = {}
    if "backends" not in kwargs["extra_context"]:
        kwargs["extra_context"]["backends"] = []
    # Note: sorry but I really find the .setdefault() method non-obvious and
    # harder to re-read that the lines above.
    for backend in get_backends():
        if not isinstance(backend, SocialAuthBackend):
            continue # It should be checked using duck-typing instead
        kwargs["extra_context"]["backends"].append(backend.name)
    return django_login_view(request, *args, **kwargs)
示例#14
0
def login_view(request,
               template_name='registration/login.html',
               redirect_field_name=REDIRECT_FIELD_NAME,
               authentication_form=AuthenticationForm,
               current_app=None,
               extra_context=None):

    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        return django_login_view(request, template_name, redirect_field_name,
                                 authentication_form, current_app,
                                 extra_context)
示例#15
0
def login(request):
    if request.method == 'GET':
        return django_login_view(request)

    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    form = AuthenticationForm(data=request.POST)
    if form.is_valid():
        # Ensure the user-originating redirection url is safe.
        if not is_safe_url(url=redirect_to, host=request.get_host()):
            redirect_to = settings.LOGIN_REDIRECT_URL

        # Okay, security check complete. Log the user in.
        django_login_method(request, form.get_user())

        return HttpResponseRedirect(redirect_to)
    else:
        return HttpResponseForbidden()
示例#16
0
def login(request):
    local_host = utils.get_local_host(request)
    return django_login_view(request)
示例#17
0
def login(request):
    return django_login_view(request, 'login.html')
示例#18
0
def login(request):
    return django_login_view(request, 'login.html')
def login(request):
    local_host = utils.get_local_host(request)
    return django_login_view(request)