im having a problem in creating a confirmation email that leads to a view and set up the account.is_active to True things that keep in mind ,i have a custom user model that abstracts from the User model the token generator works fine ,i get the email i click the link ,it says that the account is activated but nothing actually is happening i think the problem is in the activate view
my models.py
class Account(AbstractBaseUser):
email = models.EmailField(verbose_name="email",max_length=60, unique=True)
username = models.CharField(max_length=60,unique=True)
phone = models.CharField(max_length=60,unique=True)
date_joined = models.DateTimeField(verbose_name="date joined",auto_now_add=True)
last_login = models.DateTimeField(verbose_name="last login",auto_now=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email','phone']
objects = MyAccountManager()
def __str__(self):
return self.username
def has_perm(self, perm, obj=None):
return self.is_admin
def has_module_perms(self, app_label):
return True
tokens.py
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class TokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, account, timestamp):
return (
six.text_type(account.pk) + six.text_type(timestamp) +
six.text_type(account.is_active)
)
account_activation_token = TokenGenerator()
view.py
#active view==========================================
def activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
account = Account.objects.get(pk=uid)
except(TypeError, ValueError, OverflowError, Account.DoesNotExist):
account = None
if account is not None and account_activation_token.check_token(account, token):
account.is_active = True
account.save()
login(request, account, backend="users.backends.AccountAuthBackend")
# return redirect('home')
return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
else:
return HttpResponse('Activation link is invalid!')
i used to work with the same way with the default django User but now when i changed to my custom user model and working with rest framework api this happened