mirror of
https://github.com/pretix/pretix.git
synced 2026-08-14 11:26:26 +00:00
Improve email and password change forms, implement is_verified flag
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
import binascii
|
||||
import json
|
||||
import operator
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from functools import reduce
|
||||
|
||||
@@ -243,7 +244,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
||||
|
||||
email = models.EmailField(unique=True, db_index=True, null=True, blank=True,
|
||||
verbose_name=_('Email'), max_length=190)
|
||||
verified_email = models.EmailField(null=True, blank=True, verbose_name=_('Verified Email'), max_length=190)
|
||||
is_verified = models.BooleanField(default=True, verbose_name=_('Verified email address'))
|
||||
fullname = models.CharField(max_length=255, blank=True, null=True,
|
||||
verbose_name=_('Full name'))
|
||||
is_active = models.BooleanField(default=True,
|
||||
@@ -355,6 +356,43 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
||||
except SendMailException:
|
||||
pass # Already logged
|
||||
|
||||
def send_confirmation_code(self, reason, email=None):
|
||||
from pretix.base.services.mail import mail
|
||||
|
||||
with language(self.locale):
|
||||
if reason == 'email_change':
|
||||
msg = str(_('to confirm changing your email address from {old_email}\nto {new_email}, use the following code:').format(
|
||||
old_email=self.email, new_email=email,
|
||||
))
|
||||
else:
|
||||
raise Exception('Invalid confirmation code reason')
|
||||
|
||||
code = "%07d" % random.randint(0, 9999999)
|
||||
cache.set('user_confirmation_code:' + str(self.pk), code + ':' + reason + ':' + str(email), 1800)
|
||||
|
||||
mail(
|
||||
email or self.email,
|
||||
_('pretix confirmation code'),
|
||||
'pretixcontrol/email/confirmation_code.txt',
|
||||
{
|
||||
'user': self,
|
||||
'reason': msg,
|
||||
'code': code,
|
||||
},
|
||||
event=None,
|
||||
user=self,
|
||||
locale=self.locale
|
||||
)
|
||||
|
||||
def check_confirmation_code(self, reason, code):
|
||||
stored = cache.get('user_confirmation_code:' + str(self.pk))
|
||||
if not stored:
|
||||
return None
|
||||
stored_code, stored_reason, email = stored.split(":", maxsplit=2)
|
||||
if int(stored_code) == int(code) and stored_reason == reason:
|
||||
return email
|
||||
|
||||
|
||||
def send_password_reset(self):
|
||||
from pretix.base.services.mail import mail
|
||||
|
||||
|
||||
Reference in New Issue
Block a user