Skip to content Skip to sidebar Skip to footer

Django Differentiate Between The First Time User And Returning User

I am using django registration redux for login and auth purposes. I want to do the following. if the user logs in for the first time i want to redirect to URL-'profile/create' if

Solution 1:

django-registration-redux seems to use Django's login-view for logging users in per default.

Thus I would provide a customized login view instead that additionally inspects the user that tries to log in and checks if last_login is already filled out.

Depending on the result the user then can be redirected to the desired page once the authentication succeeded.

Solution 2:

in most basic form when user login first time it has to be registered. do not use this kind of functionality at login use it at register function (view)

this is a old draft code that give you the idea

def ragister(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile-settings/')

    if request.method == 'POST':
        fname = request.POST['fname']
        lname = request.POST['lname']
        username = request.POST['username']
        password = request.POST['password']
        users = User()
        users.password = password
        users.username = username
        users.first_name = fname
        users.last_name = lname

        try:
            users.set_password(password)
            users.save()
            users = authenticate(username=username, password=password)
            if users is not None:
                login(request,users)
                return HttpResponseRedirect('/profile-settings/')
            messages.success(request, "This number is registered please try other number or reset your password")
            return HttpResponseRedirect('/register/')

Post a Comment for "Django Differentiate Between The First Time User And Returning User"