Adding cancel_token generation to user on creation

remotes/origin/enhancement/email-actions
Alejandro Alonso 2014-10-08 09:18:34 +02:00
parent 81e8c24da8
commit a43711be70
3 changed files with 30 additions and 1 deletions

View File

@ -48,7 +48,7 @@ class UserAdmin(DjangoUserAdmin):
fieldsets = ( fieldsets = (
(None, {'fields': ('username', 'password')}), (None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('full_name', 'email', 'bio', 'photo')}), (_('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',)}), (_('Permissions'), {'fields': ('is_active', 'is_superuser',)}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}), (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
) )

View File

@ -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,
),
]

View File

@ -19,6 +19,7 @@ import os
import os.path as path import os.path as path
import random import random
import re import re
import uuid
from django.db import models from django.db import models
from django.dispatch import receiver 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")) 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' USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email'] REQUIRED_FIELDS = ['email']
@ -146,6 +150,11 @@ class User(AbstractBaseUser, PermissionsMixin):
def get_full_name(self): def get_full_name(self):
return self.full_name or self.username or self.email 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): class Role(models.Model):
name = models.CharField(max_length=200, null=False, blank=False, name = models.CharField(max_length=200, null=False, blank=False,