0

I am working on custom user model, but the logout feature is not synchronized with root password. is_active(here activated) variable is not changing to False when I logout and the superuser logged in Django admin gets logout when logout button is pressed in the front end user. How to fix this.

models.py

class Users(AbstractBaseUser, PermissionsMixin):
    objects = UserManager()
    mobile_no = models.IntegerField(_('MobNumber'), null=True, blank=True,unique=True)
    email = models.EmailField(_('Email'), max_length=75, null=False, blank=False)
    first_name = models.CharField(_('FirstName'), max_length=50, null=True, blank=True)
    last_name = models.CharField(_('LastName'), max_length=70, null=True, blank=True)
    role = models.CharField(_('Role'), max_length=70, null=True, blank=True)
    location = models.CharField(_('Location'), max_length=70, null=True, blank=True)
    date_time = models.DateTimeField(_('DateTime'), auto_now=True, null=True, blank=True)
    activated = models.BooleanField(_('activated'), default=False)
    is_admin = models.BooleanField(_('is_admin'), default=False)
    is_itstaff = models.BooleanField(_('is_staff'), default=False)

    def __unicode__(self):
        return str(self.mobile_no)

    def __str__(self):
        return str(self.mobile_no)

    def get_full_name(self):
        return self.first_name + " " + self.last_name

    class Meta:
        ordering = ['-id']

    @property
    def is_staff(self):
        return self.is_admin


    def has_perm(self, perm, obj=None):
        return self.is_admin

    def has_module_perms(self, app_label):
        return self.is_admin

    USERNAME_FIELD = 'mobile_no'
    REQUIRED_FIELDS = ['role']

views.py

@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('login'))
VA splash
  • 553
  • 1
  • 8
  • 25
  • `logout()` clears the current session of the user, both in frontend and django Admin. – Jibin Mathews Mar 23 '19 at 15:23
  • Is there any way to prevent that. And how to solve the is_active variable problem. – VA splash Mar 23 '19 at 15:27
  • 'is_active' determines is the account can login or not. If you set it to `False` then you can't login. – shafik Mar 23 '19 at 15:32
  • How Django is able to track the current user is logged in or not? – VA splash Mar 23 '19 at 15:36
  • about Django tracking of logout : https://stackoverflow.com/questions/3644902/how-to-check-if-a-user-is-logged-in-how-to-properly-use-user-is-authenticated – VA splash Mar 23 '19 at 16:13
  • 1
    `is_active(here activated) variable is not changing`, that's not why is_active is for. It is there to determine if the user is active and can login or the user is inactive/suspended and can't login. – Bidhan Majhi Mar 24 '19 at 06:58
  • @BidhanMajhi I got your point, django provide has custom inbuilt is_active field, which is used to activate or deactivate accounts. Since the custom user inherited AbstractBaseUser, thus is_active can also be accessible for Users model, but activated field plays different purpose. What about admin and user logged out simultaneously. – VA splash Mar 24 '19 at 10:46

0 Answers0