Skip to content

Commit

Permalink
Adding cancel_token generation to user on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
superalex committed Oct 8, 2014
1 parent 81e8c24 commit a43711b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion taiga/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')}),
)
Expand Down
20 changes: 20 additions & 0 deletions taiga/users/migrations/0006_user_cancel_token.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
9 changes: 9 additions & 0 deletions taiga/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os.path as path
import random
import re
import uuid

from django.db import models
from django.dispatch import receiver
Expand Down Expand Up @@ -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']

Expand All @@ -146,6 +150,11 @@ def get_short_name(self):
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,
Expand Down

0 comments on commit a43711b

Please sign in to comment.