[Answer]-Do not want to prompt login screen again for the user after he register and log's in first time. Django

1👍

Which view is called when the user clicks the login button? Is the login_android view called when the user clicks the login button? If yes, add these lines at the beginning of the view:

from django.conf import settings
def login_android(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
        #if the redirect URL is not part of the Django app and you do not know where auth.login(request, user) redirects to, then try
        #user = request.user
        #auth.login(request, user)

This checks if the user is already logged in, and if he is, it will redirect him to whatever

auth.login(request, user)

redirects to. Just change up the

return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)

line to redirect to the URL of the application (I’m not sure what you made the URL of the application to be).

0👍

Here you can do one thing while registering you can redirect the user to main application page.
So user will automatically get log in.
try this

if request.method == "POST":
        print "you are in method"
        username = request.POST['name']
        password = request.POST['password']
        login_api(request,username,password)
        user = auth.authenticate(username=username,password=password)

        if user==None:

            dict = {'username': 'Wrong username or password'}
            response = json.dumps(dict)
            return HttpResponse(response, mimetype="application/json")
        else:
            response = json.dumps((model_to_dict(user)), cls=DjangoJSONEncoder)
            return HttpResponse(response, mimetype="application/json")

And do required changes in ajax request.

👤Wagh

Leave a comment