class MyUserCreationForm(UserCreationForm):
class Meta:
# Yeni Model
model = User
# Yeni alanlar
fields = { 'username', 'password1', 'password2', 'email',}
exclude = ['Avatar','gender','birth_date',]
def clean_username(self):
username = self.cleaned_data['username'].lower()
if username in blacklist:
raise ValidationError("Lütfen başka bir kullanıcı adı seçin.")
return username
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=True)
current_site = Site.objects.get_current()
mail_subject = 'Activate your blog account.'
message = render_to_string('includes/emails/activation-mail.html', {
'user': user,
'domain': current_site.domain,
'uid':urlsafe_base64_encode(force_bytes(
user.pk)).decode(
'utf-8'),
'token':account_activation_token.make_token(user),
})
to_email = form.cleaned_data.get('email')
email = EmailMessage(
mail_subject, message, to=[to_email]
)
email.send()