small error corrections in the templates and forms
This commit is contained in:
parent
847eb691fe
commit
7ecf520ec3
9 changed files with 87 additions and 28 deletions
|
|
@ -4,6 +4,7 @@
|
|||
import re
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth import authenticate
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
|
|
@ -11,8 +12,24 @@ class LoginForm(forms.Form):
|
|||
username = forms.CharField(max_length=255)
|
||||
password = forms.CharField(max_length=255, widget=forms.PasswordInput)
|
||||
|
||||
def clean(self):
|
||||
username = self.cleaned_data.get('username')
|
||||
password = self.cleaned_data.get('password')
|
||||
user = authenticate(username=username, password=password)
|
||||
if not user or not user.is_active:
|
||||
raise forms.ValidationError(_('Sorry, that login was invalid. '
|
||||
'Please try again.'), code='invalid_login')
|
||||
return self.cleaned_data
|
||||
|
||||
def login(self, request):
|
||||
username = self.cleaned_data.get('username')
|
||||
password = self.cleaned_data.get('password')
|
||||
user = authenticate(username=username, password=password)
|
||||
return user
|
||||
|
||||
|
||||
class GastroPinField(forms.CharField):
|
||||
widget = forms.PasswordInput
|
||||
def validate(self, value):
|
||||
"""
|
||||
Check if the value is all numeric and 4 - 6 chars long.
|
||||
|
|
@ -23,34 +40,60 @@ class GastroPinField(forms.CharField):
|
|||
|
||||
|
||||
class GastroPinForm(forms.Form):
|
||||
gastropin = GastroPinField()
|
||||
gastropin1 = GastroPinField(label=_('New Gastro-PIN'))
|
||||
gastropin2 = GastroPinField(label=_('Repeat Gastro-PIN'))
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(GastroPinForm, self).clean()
|
||||
gastropin1 = cleaned_data.get("gastropin1")
|
||||
gastropin2 = cleaned_data.get("gastropin2")
|
||||
if gastropin1 != gastropin2:
|
||||
raise forms.ValidationError(
|
||||
_('The PINs entered were not identical.'),
|
||||
code='not_identical')
|
||||
|
||||
|
||||
|
||||
class WlanPresenceForm(forms.Form):
|
||||
# Boolean fields must never be required.
|
||||
presence = forms.BooleanField(required=False,
|
||||
help_text=_('Enable WiFi presence?'))
|
||||
label=_('Enable WiFi presence'))
|
||||
|
||||
|
||||
class PasswordForm(forms.Form):
|
||||
password1 = forms.CharField(max_length=255, widget=forms.PasswordInput,
|
||||
help_text=_('New password'))
|
||||
label=_('New password'))
|
||||
password2 = forms.CharField(max_length=255, widget=forms.PasswordInput,
|
||||
help_text=_('Repeat password'))
|
||||
label=_('Repeat password'))
|
||||
|
||||
|
||||
class RFIDForm(forms.Form):
|
||||
rfid = forms.CharField(max_length=255, help_text=_('Your RFID'))
|
||||
rfid = forms.CharField(max_length=255, label=_('Your RFID'),
|
||||
help_text=_('Find out your RFID by holding your RFID tag to the '
|
||||
'reader in the airlock.'))
|
||||
|
||||
|
||||
class SIPPinForm(forms.Form):
|
||||
sippin = forms.CharField(max_length=255, help_text=_('Your SIP PIN'))
|
||||
sippin1 = GastroPinField(label=_('Your SIP PIN'))
|
||||
sippin2 = GastroPinField(label=_('Repeat SIP PIN'))
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(SIPPinForm, self).clean()
|
||||
sippin1 = cleaned_data.get("sippin1")
|
||||
sippin2 = cleaned_data.get("sippin2")
|
||||
if sippin1 != sippin2:
|
||||
raise forms.ValidationError(
|
||||
_('The PINs entered were not identical.'),
|
||||
code='not_identical')
|
||||
|
||||
|
||||
class NRF24Form(forms.Form):
|
||||
nrf24 = forms.CharField(max_length=255,
|
||||
help_text=_('Your NRF24 identification'))
|
||||
label = _('NRF24-ID'),
|
||||
help_text=_("Your r0ket's NRF24 identification"))
|
||||
|
||||
|
||||
class CLabPinForm(forms.Form):
|
||||
c_lab_pin = GastroPinField(help_text=_('Your c-lab PIN'))
|
||||
c_lab_pin1 = GastroPinField(label=_('New c-lab PIN'))
|
||||
c_lab_pin2 = GastroPinField(label=_('Repeat c-lab PIN'),
|
||||
help_text=_('Numerical only, 4 to 6 digits'))
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ form.non_field_errors }}
|
||||
<form action="{% url account.views.clabpin %}" method="post" class="form-horizontal well">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ form.non_field_errors }}
|
||||
<form action="{% url account.views.gastropin %}" method="post" class="form-horizontal well">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
<div class="row">
|
||||
<div class="span11 well">
|
||||
<h3>Login</h3>
|
||||
|
||||
<form class="form form-horizontal" action="/account/login/?next={{ redirect_to }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
{% block form_title %}{% trans "NRF24"%}{% endblock %}
|
||||
|
||||
{% block form_description %}
|
||||
<p>{% blocktrans %}The NRF24 identification is used for your R0K3T!{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}The NRF24 identification is used to interface with the
|
||||
CCC's <a href="http://r0ket.badge.events.ccc.de/">r0ket badge</a>.{% endblocktrans %}</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ form.non_field_errors }}
|
||||
<form action="{% url account.views.nrf24 %}" method="post" class="form-horizontal well">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,18 @@
|
|||
{% block form_title %}{% trans "RFID"%}{% endblock %}
|
||||
|
||||
{% block form_description %}
|
||||
<p>{% blocktrans %}Blabla testblab bla bla blub{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}A Radio Frequency Identification (RFID) tag can be used
|
||||
to announce your presence to other c-base members when you arrive.
|
||||
Place your RFID tag on the RFID reader in the airlock terminal.
|
||||
If you configured your RFID correctly, the airlock terminal will greet
|
||||
you and show additional information. If you place your RFID tag in the
|
||||
reader again when leaving, you will be logged out.{% endblocktrans %}</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ form.non_field_errors }}
|
||||
<form action="{% url account.views.rfid %}" method="post" class="form-horizontal well">
|
||||
<form action="{% url account.views.rfid %}" method="post"
|
||||
class="form-horizontal well">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ form.non_field_errors }}
|
||||
<form action="{% url account.views.sippin %}" method="post" class="form-horizontal well">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,6 @@ def landingpage(request):
|
|||
#return render_to_response("dashboard.html", locals())
|
||||
return render(request, 'base.html', {'form': form, 'admins': admins})
|
||||
|
||||
@login_required
|
||||
def home(request):
|
||||
member = retrieve_member(request)
|
||||
context = {'member': member.to_dict()}
|
||||
print context
|
||||
return render(request, 'start.html', context)
|
||||
|
||||
def auth_login(request):
|
||||
redirect_to = request.GET.get('next', '') or '/'
|
||||
if request.method == 'POST':
|
||||
|
|
@ -47,7 +40,7 @@ def auth_login(request):
|
|||
if form.is_valid():
|
||||
username = form.cleaned_data['username']
|
||||
password = form.cleaned_data['password']
|
||||
user = authenticate(username=username, password=password)
|
||||
user = form.login(request)
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
login(request, user)
|
||||
|
|
@ -55,19 +48,29 @@ def auth_login(request):
|
|||
User.objects.get_or_create(username=username)
|
||||
if created:
|
||||
member.save()
|
||||
|
||||
# save password in the session for later use with LDAP
|
||||
request.session['ldap_password'] = password
|
||||
# TODO: Change the
|
||||
|
||||
response = HttpResponseRedirect(redirect_to)
|
||||
response.set_cookie('sessionkey', 'bla')
|
||||
return response
|
||||
else:
|
||||
print 'user is none'
|
||||
return render(request, 'login.html', {'form': form})
|
||||
else:
|
||||
form = LoginForm()
|
||||
|
||||
return render_to_response('login.html',
|
||||
RequestContext(request, locals()))
|
||||
|
||||
@login_required
|
||||
def home(request):
|
||||
member = retrieve_member(request)
|
||||
context = {'member': member.to_dict()}
|
||||
print context
|
||||
return render(request, 'start.html', context)
|
||||
|
||||
@login_required
|
||||
def auth_logout(request):
|
||||
redirect_to = request.GET.get('next', '') or '/'
|
||||
|
|
@ -117,7 +120,7 @@ def set_ldap_field(request, form_type, field_names, template_name):
|
|||
'form': new_form, 'member': member.to_dict()})
|
||||
else:
|
||||
return render(request, template_name,
|
||||
{'form:': form, 'member': member.to_dict()})
|
||||
{'form': form, 'member': member.to_dict()})
|
||||
else:
|
||||
for form_field, ldap_field in field_names:
|
||||
initial[form_field] = member.get(ldap_field)
|
||||
|
|
@ -145,6 +148,6 @@ def password(request):
|
|||
|
||||
@login_required
|
||||
def clabpin(request):
|
||||
return set_ldap_field(request, CLabPinForm, [('c_lab_pin', 'c-labPIN')],
|
||||
return set_ldap_field(request, CLabPinForm, [('c_lab_pin1', 'c-labPIN')],
|
||||
'clabpin.html')
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@
|
|||
body {
|
||||
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
|
||||
}
|
||||
.asteriskField {
|
||||
color: #ff1111;
|
||||
margin-left: 3px;
|
||||
}
|
||||
.formRequired {
|
||||
margin-top: 0px;
|
||||
}
|
||||
</style>
|
||||
<!-- link rel="shortcut icon" href="{{ STATIC_URL }}ico/favicon.ico" -->
|
||||
<!-- link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
|
||||
|
|
@ -38,17 +45,19 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<span class="brand"><a href="/">{% trans "c-base Member Interface" %}</a></span>
|
||||
<span class="brand"><a href="/"><img src="http://c-base.org/cv6/images/c-base_raumstation.gif" />
|
||||
{% trans "Member Interface" %}</a></span>
|
||||
<div class="nav-collapse collapse">
|
||||
<p class="navbar-text pull-left">
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
<i class="icon-user icon-white"></i> {{ request.user.username }}{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<div class="pull-right">
|
||||
<ul class="nav">
|
||||
{% if request.user.is_authenticated %}
|
||||
|
||||
<li><a href="/account/logout/">Logout</a></li>
|
||||
{% else %}
|
||||
<li><a href="/account/login/">Login</a></li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue