change initialization of company and profile object after user creation. Add sending activatino email

remotes/origin/HEAD
Max Yakovenko 8 years ago
parent 1b1de67093
commit ce12df429d
  1. 34
      accounts_ext/forms.py

@ -9,15 +9,17 @@ from django.core.exceptions import ObjectDoesNotExist
from django.forms import inlineformset_factory
from django.urls import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django_email_blacklist import DisposableEmailChecker
from registration.forms import RegistrationFormUniqueEmail
from django.contrib.auth.forms import (
AuthenticationForm as AuthenticationFormBase,
PasswordResetForm as PasswordResetFormBase,
PasswordChangeForm as PasswordChangeFormBase
)
PasswordChangeForm as PasswordChangeFormBase,
UsernameField)
from registration.models import send_email
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__)
@ -53,23 +55,30 @@ class RegistrationForm(RegistrationFormUniqueEmail):
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):
user = super().save(commit)
profile = Profile.objects.filter(user=user).first()
if profile:
profile.first_name = self.cleaned_data.get('first_name')
profile.last_name = self.cleaned_data.get('last_name')
profile.patronymic = self.cleaned_data.get('patronymic')
profile.first_name = self.cleaned_data['first_name']
profile.last_name = self.cleaned_data['last_name']
profile.patronymic = self.cleaned_data['patronymic']
profile.save()
else:
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
class Meta:
model = User
fields = ('username',)
fields = ('username','email',)
labels = {
'username': _('Логин'),
}
@ -86,6 +95,7 @@ class RegistrationCompanyForm(forms.ModelForm):
def save(self, user, commit=True):
self.instance.user = user
self.instance.status = COMPANY_STATUS_INDIVIDUAL if self.cleaned_data['is_individual'] else COMPANY_STATUS_LEGAL
return super().save(commit)
class Meta:
@ -99,17 +109,17 @@ class RegistrationCompanyForm(forms.ModelForm):
}
widgets = {
'company_name': forms.TextInput(attrs={'class': 'reg__text'}),
'inn': forms.TextInput(attrs={'class': 'reg__text'}),
'ogrn': forms.TextInput(attrs={'class': 'reg__text'}),
'inn': forms.TextInput(attrs={'placeholder': '111222333444', 'class': 'reg__text'}),
'ogrn': forms.TextInput(attrs={'placeholder': 'С Г Г К К Н Н Х Х Х Х Х Ч', 'class': 'reg__text'}),
'address': forms.Textarea(attrs={'class': 'reg__text', 'rows': 5, 'cols': 40})
}
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',
'style': 'text-align:center',
'placeholder': _('Логин')
'placeholder': _('Email')
}))
password = forms.CharField(max_length=255, widget=forms.PasswordInput(attrs={
'class': 'reg__text',

Loading…
Cancel
Save