reload the page and the logged in user converted to the admin

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

reload the page and the logged in user converted to the admin

ayoub ELMAJJODI
The problem that I have, when I logged with normal user in the request.user there is a current user, but if I reload the page, the currennt user converted to the admin ?
Enter code here...
def countries_rate(request):
auth_user = request.user
if request.user.is_authenticated:
auth_user = request.user
if (user_rate.objects.filter(user_id=auth_user).delete()):
print(auth_user,' OK deleted ----------------.................')
formset = countriesFormset(request.POST or None)
if request.method == 'POST':
if 'Add_More' in request.POST:
#print('--- add more in post -----')
cp = request.POST.copy()
cp['form-TOTAL_FORMS'] = int(cp['form-TOTAL_FORMS'])+ 1
formset = countriesFormset(cp,prefix='form')
total = cp['form-TOTAL_FORMS']
#print('total forms {}---------------------',format(total))
return render(request,'thesis_app/countries_rate.html', context={
'formset':formset,
'total':total
})
elif 'submit' in request.POST:
if formset.is_valid():
for inst in formset:
rate = user_rate()
if inst.is_valid():
#answer2 =inst.save(commit = False)
#answer2.user_id = auth_user
countries_name_id = inst.cleaned_data.get('countries_name_id')
country_rating = inst.cleaned_data.get('country_rating')
rate.user_id = auth_user
rate.countries_name_id = countries_name_id
rate.country_rating = country_rating
#print(auth_user,"................")
rate.save()
return redirect('thesis_app:result')
else:
return redirect('thesis_app:login')
user = request.user
formset = countriesFormset(request.POST or None)
return render(request,'thesis_app/countries_rate.html', context={
'user':user,
'formset':formset
}
)


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/62ccddff-7c4d-4fb1-96d2-431c60f6b760%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: reload the page and the logged in user converted to the admin

N'BE SORO
Hello, 
Use Django login function 



Le sam. 24 août 2019 à 19:12, ayoub ELMAJJODI <[hidden email]> a écrit :
The problem that I have, when I logged with normal user in the request.user there is a current user, but if I reload the page, the currennt user converted to the admin ?
Enter code here...
def countries_rate(request):
auth_user = request.user
if request.user.is_authenticated:
auth_user = request.user
if (user_rate.objects.filter(user_id=auth_user).delete()):
print(auth_user,' OK deleted ----------------.................')
formset = countriesFormset(request.POST or None)
if request.method == 'POST':
if 'Add_More' in request.POST:
#print('--- add more in post -----')
cp = request.POST.copy()
cp['form-TOTAL_FORMS'] = int(cp['form-TOTAL_FORMS'])+ 1
formset = countriesFormset(cp,prefix='form')
total = cp['form-TOTAL_FORMS']
#print('total forms {}---------------------',format(total))
return render(request,'thesis_app/countries_rate.html', context={
'formset':formset,
'total':total
})
elif 'submit' in request.POST:
if formset.is_valid():
for inst in formset:
rate = user_rate()
if inst.is_valid():
#answer2 =inst.save(commit = False)
#answer2.user_id = auth_user
countries_name_id = inst.cleaned_data.get('countries_name_id')
country_rating = inst.cleaned_data.get('country_rating')
rate.user_id = auth_user
rate.countries_name_id = countries_name_id
rate.country_rating = country_rating
#print(auth_user,"................")
rate.save()
return redirect('thesis_app:result')
else:
return redirect('thesis_app:login')
user = request.user
formset = countriesFormset(request.POST or None)
return render(request,'thesis_app/countries_rate.html', context={
'user':user,
'formset':formset
}
)


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/62ccddff-7c4d-4fb1-96d2-431c60f6b760%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOtSHp9Jb%3DuBEdMtR1z8y-kaop8BcPb8FGHn_VTqAcxXh%3DKNfg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: reload the page and the logged in user converted to the admin

James Schneider
In reply to this post by ayoub ELMAJJODI

request.user there is a current user, but if I reload the page, the currennt user converted to the admin ?
Enter code here...
def countries_rate(request):
auth_user = request.user
if request.user.is_authenticated:
auth_user = request.user
if (user_rate.objects.filter(user_id=auth_user).delete()):
print(auth_user,' OK deleted ----------------.................')
formset = countriesFormset(request.POST or None)


Not sure if it's related, but is there a reason you immediately delete the logged-in user as soon as the page loads? Even before any forms are submitted?

-James

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUTY%3DyMCqqRVQWPQyaq7%3D7D2-Zs-3wNK0HfH%2BCXRURkAQ%40mail.gmail.com.