|
|
|
@ -9,15 +9,17 @@ from django.core.exceptions import ObjectDoesNotExist |
|
|
|
from django.forms import inlineformset_factory |
|
|
|
from django.forms import inlineformset_factory |
|
|
|
from django.urls import reverse, reverse_lazy |
|
|
|
from django.urls import reverse, reverse_lazy |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
|
|
from django_email_blacklist import DisposableEmailChecker |
|
|
|
from registration.forms import RegistrationFormUniqueEmail |
|
|
|
from registration.forms import RegistrationFormUniqueEmail |
|
|
|
from django.contrib.auth.forms import ( |
|
|
|
from django.contrib.auth.forms import ( |
|
|
|
AuthenticationForm as AuthenticationFormBase, |
|
|
|
AuthenticationForm as AuthenticationFormBase, |
|
|
|
PasswordResetForm as PasswordResetFormBase, |
|
|
|
PasswordResetForm as PasswordResetFormBase, |
|
|
|
PasswordChangeForm as PasswordChangeFormBase |
|
|
|
PasswordChangeForm as PasswordChangeFormBase, |
|
|
|
) |
|
|
|
UsernameField) |
|
|
|
|
|
|
|
from registration.models import send_email |
|
|
|
|
|
|
|
|
|
|
|
from core.models import STATUS_ACTIVE |
|
|
|
from core.models import STATUS_ACTIVE |
|
|
|
from .models import User, Profile, Company |
|
|
|
from .models import User, Profile, Company, COMPANY_STATUS_INDIVIDUAL, COMPANY_STATUS_LEGAL |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
@ -53,23 +55,30 @@ class RegistrationForm(RegistrationFormUniqueEmail): |
|
|
|
|
|
|
|
|
|
|
|
title = _('Регистрация') |
|
|
|
title = _('Регистрация') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
|
|
|
email = super().clean_email() |
|
|
|
|
|
|
|
if DisposableEmailChecker().is_disposable(email): |
|
|
|
|
|
|
|
raise forms.ValidationError(_('Введите email с валидными доменом')) |
|
|
|
|
|
|
|
return email |
|
|
|
|
|
|
|
|
|
|
|
def save(self, commit=True): |
|
|
|
def save(self, commit=True): |
|
|
|
user = super().save(commit) |
|
|
|
user = super().save(commit) |
|
|
|
profile = Profile.objects.filter(user=user).first() |
|
|
|
profile = Profile.objects.filter(user=user).first() |
|
|
|
if profile: |
|
|
|
if profile: |
|
|
|
profile.first_name = self.cleaned_data.get('first_name') |
|
|
|
profile.first_name = self.cleaned_data['first_name'] |
|
|
|
profile.last_name = self.cleaned_data.get('last_name') |
|
|
|
profile.last_name = self.cleaned_data['last_name'] |
|
|
|
profile.patronymic = self.cleaned_data.get('patronymic') |
|
|
|
profile.patronymic = self.cleaned_data['patronymic'] |
|
|
|
profile.save() |
|
|
|
profile.save() |
|
|
|
else: |
|
|
|
else: |
|
|
|
logger.error( |
|
|
|
logger.error( |
|
|
|
msg="User {user_email} missing profile object".format({'user_email': user.email}) |
|
|
|
msg="User {user_email} missing profile object".format({'user_email': self.cleaned_data['email']}) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return user |
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
model = User |
|
|
|
model = User |
|
|
|
fields = ('username',) |
|
|
|
fields = ('username','email',) |
|
|
|
labels = { |
|
|
|
labels = { |
|
|
|
'username': _('Логин'), |
|
|
|
'username': _('Логин'), |
|
|
|
} |
|
|
|
} |
|
|
|
@ -86,6 +95,7 @@ class RegistrationCompanyForm(forms.ModelForm): |
|
|
|
|
|
|
|
|
|
|
|
def save(self, user, commit=True): |
|
|
|
def save(self, user, commit=True): |
|
|
|
self.instance.user = user |
|
|
|
self.instance.user = user |
|
|
|
|
|
|
|
self.instance.status = COMPANY_STATUS_INDIVIDUAL if self.cleaned_data['is_individual'] else COMPANY_STATUS_LEGAL |
|
|
|
return super().save(commit) |
|
|
|
return super().save(commit) |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
class Meta: |
|
|
|
@ -99,17 +109,17 @@ class RegistrationCompanyForm(forms.ModelForm): |
|
|
|
} |
|
|
|
} |
|
|
|
widgets = { |
|
|
|
widgets = { |
|
|
|
'company_name': forms.TextInput(attrs={'class': 'reg__text'}), |
|
|
|
'company_name': forms.TextInput(attrs={'class': 'reg__text'}), |
|
|
|
'inn': forms.TextInput(attrs={'class': 'reg__text'}), |
|
|
|
'inn': forms.TextInput(attrs={'placeholder': '111222333444', 'class': 'reg__text'}), |
|
|
|
'ogrn': forms.TextInput(attrs={'class': 'reg__text'}), |
|
|
|
'ogrn': forms.TextInput(attrs={'placeholder': 'С Г Г К К Н Н Х Х Х Х Х Ч', 'class': 'reg__text'}), |
|
|
|
'address': forms.Textarea(attrs={'class': 'reg__text', 'rows': 5, 'cols': 40}) |
|
|
|
'address': forms.Textarea(attrs={'class': 'reg__text', 'rows': 5, 'cols': 40}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AuthenticationForm(AuthenticationFormBase): |
|
|
|
class AuthenticationForm(AuthenticationFormBase): |
|
|
|
username = forms.CharField(max_length=255, widget=forms.TextInput(attrs={ |
|
|
|
username = UsernameField(max_length=255, widget=forms.TextInput(attrs={ |
|
|
|
'class': 'reg__text', |
|
|
|
'class': 'reg__text', |
|
|
|
'style': 'text-align:center', |
|
|
|
'style': 'text-align:center', |
|
|
|
'placeholder': _('Логин') |
|
|
|
'placeholder': _('Email') |
|
|
|
})) |
|
|
|
})) |
|
|
|
password = forms.CharField(max_length=255, widget=forms.PasswordInput(attrs={ |
|
|
|
password = forms.CharField(max_length=255, widget=forms.PasswordInput(attrs={ |
|
|
|
'class': 'reg__text', |
|
|
|
'class': 'reg__text', |
|
|
|
|