auth stuff.
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
from babel.dates import format_date
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth import forms as auth_forms, password_validation
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils.translation import get_language, ugettext, ugettext_lazy as _
|
||||
from datetimewidget.widgets import DateWidget, TimeWidget, DateTimeWidget
|
||||
@@ -18,6 +19,67 @@ logger = logging.getLogger(__name__)
|
||||
DEVELOPMENT_INIT_FORMS = True
|
||||
|
||||
|
||||
class LoginForm(auth_forms.AuthenticationForm):
|
||||
username = auth_forms.UsernameField(
|
||||
max_length=254,
|
||||
label=_(u'E-Mail-Adresse'),
|
||||
widget=forms.TextInput(attrs={'autofocus': True,
|
||||
'placeholder': ''}),
|
||||
)
|
||||
password = forms.CharField(
|
||||
label=_(u'Passwort'),
|
||||
widget=forms.PasswordInput(attrs={'placeholder': ''}),
|
||||
)
|
||||
|
||||
error_messages = {
|
||||
'invalid_login': _(u'Benutzername oder Passwort falsch.'),
|
||||
'inactive': _("This account is inactive."),
|
||||
}
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data.get('username')
|
||||
return username.lower()
|
||||
|
||||
|
||||
class SetPasswordForm(forms.Form):
|
||||
new_password = forms.CharField(max_length=12,
|
||||
label=_(u'Neues Passwort'),
|
||||
widget=forms.PasswordInput(attrs={'placeholder': ''}))
|
||||
new_password_repeat = forms.CharField(max_length=12,
|
||||
label=_(u'Neues Passwort wiederholen'),
|
||||
widget=forms.PasswordInput(attrs={'placeholder': ''}))
|
||||
send_password_mail = forms.BooleanField(required=False,
|
||||
label=_(u'Neues Passwort per E-Mail zusenden'),
|
||||
)
|
||||
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
self.user = user
|
||||
super(SetPasswordForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean_new_password(self):
|
||||
password = self.cleaned_data.get('new_password')
|
||||
password_validation.validate_password(password, self.user)
|
||||
return password
|
||||
|
||||
def clean_new_password_repeat(self):
|
||||
password1 = self.cleaned_data.get('new_password')
|
||||
password2 = self.cleaned_data.get('new_password_repeat')
|
||||
if password1 and password2:
|
||||
if password1 != password2:
|
||||
raise forms.ValidationError(
|
||||
ugettext(u'Passwörter stimmen nicht überein'),
|
||||
code='password_mismatch',
|
||||
)
|
||||
return password2
|
||||
|
||||
def save(self, commit=True):
|
||||
new_password = self.cleaned_data.get('new_password')
|
||||
self.user.set_password(new_password)
|
||||
if commit:
|
||||
self.user.save()
|
||||
return self.user
|
||||
|
||||
|
||||
class ChainedForm(forms.Form):
|
||||
_next_form_name = None
|
||||
|
||||
@@ -722,6 +784,7 @@ class ChargesForm(EventCreateForm):
|
||||
additional_costs = forms.CharField(required=False,
|
||||
max_length=config.ADDITIONAL_COSTS_MAX_LENGTH,
|
||||
label=_(u'Zusätzliche Kosten (Text)'),
|
||||
help_text=_(u'Kann freigelassen werden'),
|
||||
)
|
||||
|
||||
def _proceed_session_data(self, session_data):
|
||||
@@ -823,7 +886,7 @@ class ChargesForm(EventCreateForm):
|
||||
participation_fee = 25
|
||||
participation_day_fee = 25
|
||||
|
||||
additional_costs_text = ugettext(u'zzgl. Fahrtkosten')
|
||||
additional_costs_text = ugettext(u'Fahrtkosten')
|
||||
|
||||
if last_day:
|
||||
timedelta = last_day - first_day
|
||||
@@ -844,6 +907,9 @@ class ChargesForm(EventCreateForm):
|
||||
trainer_reward += orga_day_fee / 2
|
||||
charge += participation_day_fee / 2
|
||||
|
||||
if charge > 0:
|
||||
additional_costs_text = u'%s %s' % (ugettext(u'zzgl.'), additional_costs_text)
|
||||
|
||||
self.fields['charge_key'].initial = charge_key
|
||||
self.fields['orga_fee'].initial = orga_fee
|
||||
self.fields['pre_meeting_fee'].initial = pre_meeting_fee
|
||||
|
||||
Reference in New Issue
Block a user