core: prevent duplicate fixed_username/email

This commit is contained in:
Jens Langhammer 2018-12-10 15:27:55 +01:00
parent 4111ca96a7
commit 564483cab8
1 changed files with 17 additions and 1 deletions

View File

@ -1,13 +1,29 @@
"""passbook core invitation form"""
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
from passbook.core.models import Invitation
from passbook.core.models import Invitation, User
class InvitationForm(forms.ModelForm):
"""InvitationForm"""
def clean_fixed_username(self):
"""Check if username is already used"""
username = self.cleaned_data.get('fixed_username')
if User.objects.filter(username=username).exists():
raise ValidationError(_('Username is already in use.'))
return username
def clean_fixed_email(self):
"""Check if email is already used"""
email = self.cleaned_data.get('fixed_email')
if User.objects.filter(email=email).exists():
raise ValidationError(_('E-Mail is already in use.'))
return email
class Meta:
model = Invitation