mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
tixlcontrol: Login form
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Django>=1.7
|
||||
django-bootstrap3
|
||||
django-compressor
|
||||
BeautifulSoup4
|
||||
html5lib
|
||||
|
||||
@@ -40,6 +40,7 @@ INSTALLED_APPS = (
|
||||
'tixlcontrol',
|
||||
'tixlpresale',
|
||||
'compressor',
|
||||
'bootstrap3',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
||||
@@ -14,7 +14,7 @@ class LoginRequiredMiddleware:
|
||||
"""
|
||||
|
||||
EXCEPTIONS = (
|
||||
"login"
|
||||
"auth.login"
|
||||
)
|
||||
|
||||
def process_request(self, request):
|
||||
|
||||
22
src/tixlcontrol/static/tixlcontrol/less/auth.less
Normal file
22
src/tixlcontrol/static/tixlcontrol/less/auth.less
Normal file
@@ -0,0 +1,22 @@
|
||||
@import "../../../../tixlbase/static/bootstrap/less/bootstrap.less";
|
||||
|
||||
body {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.form-signin {
|
||||
.well;
|
||||
|
||||
max-width: 330px;
|
||||
margin: auto;
|
||||
margin-top: 10%;
|
||||
padding-bottom: 0;
|
||||
|
||||
.control-label {
|
||||
.sr-only;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
16
src/tixlcontrol/templates/tixlcontrol/auth/base.html
Normal file
16
src/tixlcontrol/templates/tixlcontrol/auth/base.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% load compress %}
|
||||
{% load staticfiles %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
{% compress css %}
|
||||
<link rel="stylesheet" type="text/less" href="{% static "tixlcontrol/less/auth.less" %}" />
|
||||
{% endcompress %}
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
15
src/tixlcontrol/templates/tixlcontrol/auth/login.html
Normal file
15
src/tixlcontrol/templates/tixlcontrol/auth/login.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends "tixlcontrol/auth/base.html" %}
|
||||
{% load bootstrap3 %}
|
||||
{% block content %}
|
||||
<form class="form-signin" action="" method="post">
|
||||
{% bootstrap_form_errors form type='all' layout='inline' %}
|
||||
{% csrf_token %}
|
||||
{% bootstrap_field form.email %}
|
||||
{% bootstrap_field form.password %}
|
||||
<div class="form-group buttons">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Log in
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -2,4 +2,5 @@ from django.conf.urls import patterns, url
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', 'tixlcontrol.views.main.index', name='index'),
|
||||
url(r'^login$', 'tixlcontrol.views.auth.login', name='auth.login'),
|
||||
)
|
||||
|
||||
55
src/tixlcontrol/views/auth.py
Normal file
55
src/tixlcontrol/views/auth.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import login as auth_login
|
||||
|
||||
|
||||
class AuthenticationForm(BaseAuthenticationForm):
|
||||
"""
|
||||
The login form.
|
||||
"""
|
||||
email = forms.EmailField(label=_("E-mail address"), max_length=254)
|
||||
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||
username = None
|
||||
|
||||
error_messages = {
|
||||
'invalid_login': _("Please enter a correct e-mail address and password."),
|
||||
'inactive': _("This account is inactive."),
|
||||
}
|
||||
|
||||
def __init__(self, request=None, *args, **kwargs):
|
||||
self.request = request
|
||||
self.user_cache = None
|
||||
super(forms.Form, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
email = self.cleaned_data.get('email')
|
||||
password = self.cleaned_data.get('password')
|
||||
|
||||
if email and password:
|
||||
self.user_cache = authenticate(identifier=email.lower(),
|
||||
password=password)
|
||||
if self.user_cache is None:
|
||||
raise forms.ValidationError(
|
||||
self.error_messages['invalid_login'],
|
||||
code='invalid_login',
|
||||
)
|
||||
else:
|
||||
self.confirm_login_allowed(self.user_cache)
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
def login(request):
|
||||
ctx = {}
|
||||
if request.method == 'POST':
|
||||
form = AuthenticationForm(data=request.POST)
|
||||
if form.is_valid() and form.user_cache:
|
||||
auth_login(request, form.user_cache)
|
||||
return redirect('control:index')
|
||||
else:
|
||||
form = AuthenticationForm()
|
||||
ctx['form'] = form
|
||||
return render(request, 'tixlcontrol/auth/login.html', ctx)
|
||||
Reference in New Issue
Block a user