This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/core/forms/invitations.py

39 lines
1.2 KiB
Python
Raw Normal View History

2018-12-10 13:21:42 +00:00
"""passbook core invitation form"""
2018-12-10 13:13:18 +00:00
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
2018-12-10 13:13:18 +00:00
from passbook.core.models import Invitation, User
2018-12-10 13:13:18 +00:00
2018-12-10 13:49:15 +00:00
class InvitationForm(forms.ModelForm):
"""InvitationForm"""
2018-12-10 13:13:18 +00:00
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
2018-12-10 13:13:18 +00:00
class Meta:
2018-12-10 13:49:15 +00:00
model = Invitation
fields = ['expires', 'fixed_username', 'fixed_email', 'needs_confirmation']
labels = {
'fixed_username': "Force user's username (optional)",
'fixed_email': "Force user's email (optional)",
}
widgets = {
'fixed_username': forms.TextInput(),
'fixed_email': forms.TextInput(),
}