示例#1
0
def login_page(request):
    ''' authentication '''
    # send user to the login page
    data = {
        'login_form': forms.LoginForm(),
        'register_form': forms.RegisterForm(),
    }
    return TemplateResponse(request, 'login.html', data)
示例#2
0
def login_page(request):
    ''' authentication '''
    # send user to the login page
    data = {
        'site_settings': models.SiteSettings.get(),
        'login_form': forms.LoginForm(),
        'register_form': forms.RegisterForm(),
    }
    return TemplateResponse(request, 'login.html', data)
示例#3
0
def user_login(request):
    ''' authentication '''
    # send user to the login page
    if request.method == 'GET':
        form = forms.LoginForm()
        return TemplateResponse(request, 'login.html', {'login_form': form})

    # authenticate user
    form = forms.LoginForm(request.POST)
    if not form.is_valid():
        return TemplateResponse(request, 'login.html', {'login_form': form})

    username = form.data['username']
    username = '******' % (username, DOMAIN)
    password = form.data['password']
    user = authenticate(request, username=username, password=password)
    if user is not None:
        login(request, user)
        return redirect(request.GET.get('next', '/'))
    return TemplateResponse(request, 'login.html', {'login_form': form})
示例#4
0
def user_login(request):
    ''' authenticate user login '''
    if request.method == 'GET':
        return redirect('/login')

    register_form = forms.RegisterForm()
    login_form = forms.LoginForm(request.POST)
    if not login_form.is_valid():
        return TemplateResponse(request, 'login.html', {
            'login_form': login_form,
            'register_form': register_form
        })

    username = login_form.data['username']
    username = '******' % (username, DOMAIN)
    password = login_form.data['password']
    user = authenticate(request, username=username, password=password)
    if user is not None:
        login(request, user)
        return redirect(request.GET.get('next', '/'))
    return TemplateResponse(request, 'login.html', {
        'login_form': login_form,
        'register_form': register_form
    })