These are chat archives for django/django

13th
Nov 2016
Miracle Ayodele
@iammiracle
Nov 13 2016 00:39
@bkovacev this is the view.py
var code = "def user_login(request):
context = {}
if request.method == 'POST':
    print request.POST
    # email = request.POST['email']
    # password = request.POST['password']
    email = request.POST.get('email', None)
    password = request.POST.get('password', None)
    print email
    print password
    if email and password:
        confirm_user, created = User.objects.get_or_create(username=email)
        if created:
            confirm_user.set_password(password)
            confirm_user.save()
    confirm_user = authenticate(email=email, password=password)
    print confirm_user
    if confirm_user is not None:
        if confirm_user.is_active:
            login(request, confirm_user)
            print (request.user.is_authenticated())
            print confirm_user
            return HttpResponseRedirect('/home/')
        else:
            print (request.user.is_authenticated())
            print confirm_user
            return HttpResponse("Your Account is disabled")
    else:
        print (request.user.is_authenticated())
        print "Invalid login details: {0}, {1}".format(email, password)
        return HttpResponse("Invalid login details supplied")
else:
    print (request.user.is_authenticated())
    return render(request, 'index.html', context)";
Miracle Ayodele
@iammiracle
Nov 13 2016 02:28
@bkovacev @megapctr when i was ruminating on what could be the problem why the authenticate function is returning None. I tried registering a new user, which worked well, wen i tried testing on shell if it will be true or not, i got the error "User matching query does not exist."
so i guess the first username and password giving me true was cos theat was wat i used to register my superuser account
this is just a feeling tho, dont know if i am correct abt that
Pami Ketolainen
@keto
Nov 13 2016 08:36
koderNeptune: would need to see authenticate function to know why it returns None. But just a guess here, you use get_or_create(username=email), and authenticate(email=email... That seems a bit inconsistent
User.email is not set at any point, so if authenticate() uses that field instead of username, then that might be the problem
Miracle Ayodele
@iammiracle
Nov 13 2016 21:42
@keto i have tried those means
lik i said
its like the authenticate is not getting data from my mysql database
i tried verifying on shell
and i got True, but only authenticating what i have in my django admin database, the superuser accounts i created for the project