How to differentiate the first time registered and regular logged in user in django

authentication, django, django-allauth

Solution

I think you can check your last_login field (if you are sure a user exists).

Try one of the next:

profile.user.last_login == profile.user.date_joined: # this may be True if a user logins for a first time

OR

profile.user.last_login == None:

I don't know the exactly value for the field but you can experiment and find the rule for first-time registered users.

Problem

I am using django allauth for all my `signin, signup and logout` functionality and working fine. Now i have a functionality that, 1.when a user is registered and logged in for the first time, i need to redirect him to a success page/verification page(`/success/`) 2.When a user who is already registered is logged in, he should be redirected to `/dashboard/` As of now i am redirected the user(first time registered and already registered) to `/dashboard/` by a setting called `LOGIN_REDIRECT_URL` in `settings.py` ``` LOGIN_REDIRECT_URL = /dashboard/ ``` Also i have observed that there is field/attribute called last_login for user object from which we can use to find the last login for the user, whether it will be helpful ? model.py ``` from django.contrib.auth.models import User class Profile(models.Model): business_name = models.CharField(max_length = 45, null = False, blank = False) user = models.ForeignKey(User, unique = True) work_field = models.CharField(max_length = 45, null = False, blank = False) image = models.ImageField(upload_to = '/images/', null = True, blank = True, max_length = 250) image.allow_tags = True url = models.URLField(max_length = 255, null = True, blank = True) ```

Original source