fmartingr
/
shelfzilla
Archived
1
0
Fork 0

Merge branch 'access-code-remove' into 'master'

Removed access code from registration form

See merge request !1
This commit is contained in:
Felipe Martín 2015-08-24 06:27:51 +00:00
commit f9c55c352a
1 changed files with 1 additions and 18 deletions

View File

@ -56,26 +56,11 @@ class RegistrationForm(forms.ModelForm):
widget=forms.PasswordInput)
password2 = forms.CharField(label=_('Repeat password'),
widget=forms.PasswordInput)
access_code = forms.CharField(label=_('Invitation code'), required=True)
class Meta:
model = models.User
fields = ('email', 'username', )
def get_access_code(self):
try:
return models.AccessCode.objects.get(
code=self.cleaned_data['access_code'])
except models.AccessCode.DoesNotExist:
return False
def clean_access_code(self):
code = self.get_access_code()
if not code or (code and not code.usable):
raise forms.ValidationError(_('Invitation code is not valid'))
return self.cleaned_data['access_code']
def clean_password2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get("password1")
@ -88,9 +73,7 @@ class RegistrationForm(forms.ModelForm):
# Save the provided password in hashed format
with transaction.atomic():
user = super(RegistrationForm, self).save(commit=False)
access_code = self.get_access_code()
user.access_code = access_code
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
return user