fmartingr
/
shelfzilla
Archived
1
0
Fork 0

Removed access code from registration form

This commit is contained in:
Felipe Martín 2015-08-24 06:25:15 +00:00
parent c2229c4214
commit 43fd4f1cb6
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