dash-stack/authcp/forms.py
Paarhati Ozkasgarli 29cbae8ff7 Initial Multi Language Support
From this change onward all strings must tagged with oslo_i18n
translate tag.

Welcome multi language support and do not forget to tag missing
strings.

Change-Id: I9c59b2c91a31cb92abe1f0cb092efd611b300dfa
2017-03-03 20:53:10 +03:00

38 lines
1.2 KiB
Python

import re
from oslo_i18n import translate as _
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django import forms
class UserRegisterForm(forms.Form):
email = forms.EmailField(label=_('Email'))
password1 = forms.CharField(
label=_('Password'),
widget=forms.PasswordInput(),
)
password2 = forms.CharField(
label=_('Password (Again)'),
widget=forms.PasswordInput(),
)
tos = forms.BooleanField(
required=True,
error_messages={'required': _('You must accept TOS.')}
)
def clean_email(self):
email = self.cleaned_data['email']
try:
User.objects.get(email=email)
except ObjectDoesNotExist:
return email
raise forms.ValidationError(_('Email address is not available.'))
def clean_password2(self):
if 'password1' in self.cleaned_data:
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
raise forms.ValidationError(_('Password do not match.'))