Adding cancel_token generation to user on creation
parent
81e8c24da8
commit
a43711be70
|
@ -48,7 +48,7 @@ class UserAdmin(DjangoUserAdmin):
|
|||
fieldsets = (
|
||||
(None, {'fields': ('username', 'password')}),
|
||||
(_('Personal info'), {'fields': ('full_name', 'email', 'bio', 'photo')}),
|
||||
(_('Extra info'), {'fields': ('color', 'default_language', 'default_timezone', 'token', 'colorize_tags', 'email_token', 'new_email')}),
|
||||
(_('Extra info'), {'fields': ('color', 'default_language', 'default_timezone', 'token', 'colorize_tags', 'email_token', 'new_email', 'cancel_token')}),
|
||||
(_('Permissions'), {'fields': ('is_active', 'is_superuser',)}),
|
||||
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
|
||||
)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0005_alter_user_photo'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='cancel_token',
|
||||
field=models.CharField(default=None, max_length=200, blank=True, null=True, verbose_name='email token'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -19,6 +19,7 @@ import os
|
|||
import os.path as path
|
||||
import random
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.dispatch import receiver
|
||||
|
@ -123,6 +124,9 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||
|
||||
github_id = models.IntegerField(null=True, blank=True, verbose_name=_("github ID"))
|
||||
|
||||
cancel_token = models.CharField(max_length=200, null=True, blank=True, default=None,
|
||||
verbose_name=_("cancel account token"))
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
REQUIRED_FIELDS = ['email']
|
||||
|
||||
|
@ -146,6 +150,11 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||
def get_full_name(self):
|
||||
return self.full_name or self.username or self.email
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.cancel_token:
|
||||
self.cancel_token = str(uuid.uuid1())
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=200, null=False, blank=False,
|
||||
|
|
Loading…
Reference in New Issue