authenticate() only authenticate superuser

22 views
Skip to first unread message

irtazahu...@gmail.com

unread,
Apr 23, 2019, 3:11:08 PM4/23/19
to Django users
I am using authenticate function to authenticate user on login this is working properly but only allow superuser to login.

def Login_View(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['pwd']
        user =authenticate(request,username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                name = User.objects.get(username=request.user)
                request.session['username'] = username
                return redirect('/dashboard/',{'name':name.username})
                # return render(request,'dashboard_app/index.html',{'name':name.username})
            else:
                 return render(request, 'login_app/index.html', {'error_message': 'Your account has been disabled'})
        else:
            return render(request, 'login_app/index.html', {'error_message': 'Invalid login'})
    return render(request, 'login_app/index.html')
kindly aolve my issue asap

Mike Dewhirst

unread,
Apr 23, 2019, 6:04:43 PM4/23/19
to django...@googlegroups.com
On 24/04/2019 4:39 am, irtazahu...@gmail.com wrote:
> I am using authenticate function to authenticate user on login this is
> working properly but only allow superuser to login.

Are your other users active?

>
> def Login_View(request):
>
>     if request.method == "POST":
>
>         username = request.POST['username']
>
>         password = request.POST['pwd']
>
>         user =authenticate(request,username=username,
> password=password)
>
>         if user is not None:
>
>             if user.is_active:
>
> login(request, user)
>
>                 name = User.objects.get(username=request.user)
>
> request.session['username'] = username
>
> return redirect('/dashboard/',{'name':name.username})
>
>                 # return
> render(request,'dashboard_app/index.html',{'name':name.username})
>
>             else:
>
>  return render(request, 'login_app/index.html',
> {'error_message': 'Your account has been disabled'})
>
>         else:
>
>             return render(request, 'login_app/index.html',
> {'error_message': 'Invalid login'})
>
>     return render(request, 'login_app/index.html')
>
> kindly aolve my issue asap
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/af4b7e96-eb62-4d56-988e-7eb4140f0a77%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/af4b7e96-eb62-4d56-988e-7eb4140f0a77%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

meliodis live

unread,
Apr 23, 2019, 6:05:59 PM4/23/19
to django...@googlegroups.com
Yes

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

Mike Dewhirst

unread,
Apr 23, 2019, 6:28:35 PM4/23/19
to django...@googlegroups.com
On 24/04/2019 8:05 am, meliodis live wrote:
> Yes

I would instrument the code below with print statements to identify
where it is going off the rails.

>
> On Wed, 24 Apr 2019, 3:04 am Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au> wrote:
>
> On 24/04/2019 4:39 am, irtazahu...@gmail.com
> <mailto:django-users%2Bunsu...@googlegroups.com>
> > <mailto:django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>>.
> > To post to this group, send email to
> django...@googlegroups.com <mailto:django...@googlegroups.com>
> > <mailto:django...@googlegroups.com
> <mailto:django...@googlegroups.com>>.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/af4b7e96-eb62-4d56-988e-7eb4140f0a77%40googlegroups.com
>
> >
> <https://groups.google.com/d/msgid/django-users/af4b7e96-eb62-4d56-988e-7eb4140f0a77%40googlegroups.com?utm_medium=email&utm_source=footer>.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMiRa0KR9M9OXYJNdOt01QNiWzM3zyR_5bYvx3Ryi8wjfFmMNQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMiRa0KR9M9OXYJNdOt01QNiWzM3zyR_5bYvx3Ryi8wjfFmMNQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

meliodis live

unread,
Apr 24, 2019, 12:41:42 AM4/24/19
to django...@googlegroups.com
I had pass a error on both inactive and inauthentic statememt it gives invalid user error not inactve one

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages