Ejemplo n.º 1
0
def login_view(request):
    from htk.apps.accounts.forms.auth import UsernameEmailAuthenticationForm
    auth_form = UsernameEmailAuthenticationForm(None, request.POST)
    if auth_form.is_valid():
        user = auth_form.get_user()
        login_authenticated_user(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Ejemplo n.º 2
0
def login_view(request):
    from htk.apps.accounts.forms.auth import UsernameEmailAuthenticationForm
    auth_form = UsernameEmailAuthenticationForm(None, request.POST)
    if auth_form.is_valid():
        user = auth_form.get_user()
        login(request, user)
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Ejemplo n.º 3
0
def login_view(
    request,
    data=None,
    default_next_url_name='account_login_redirect',
    template='account/login.html',
    renderer=_r
):
    if data is None:
        data = wrap_data(request)
    data.update(csrf(request))
    success = False
    if request.method == 'POST':
        auth_form = UsernameEmailAuthenticationForm(None, request.POST)
        if auth_form.is_valid():
            user = auth_form.get_user()
            login(request, user)
            success = True
            user.profile.update_locale_info_by_ip_from_request(request)
            default_next_uri = reverse(default_next_url_name)
            next_uri = request.GET.get('next', default_next_uri)
        else:
            for error in auth_form.non_field_errors():
                data['errors'].append(error)
            auth_user = auth_form.get_user()
            if auth_user and not auth_user.is_active:
                data['errors'].append('Have you confirmed your email address yet? <a id="resend_confirmation" href="javascript:void(0);">Resend confirmation &gt;</a>')
                resend_confirmation_form = ResendConfirmationForm({'email': auth_user.email})
                data['resend_confirmation_form'] = resend_confirmation_form
            else:
                pass
    else:
        auth_form = UsernameEmailAuthenticationForm(None)

    if success:
        response = redirect(next_uri)
    else:
        data['auth_form'] = auth_form
        response = renderer(template, data)

    return response