@cseb Where did you get that Django Code?
On Wed, 6 Nov 2024 at 15:07, Ruby <dev.rubyshell@gmail.com> wrote:
Your code needs to be refactored, here is the real deal, your ChangePassowrdFrom is missing `request`, it should be as it is belowform = grandmas4hire.forms.ChangePasswordForm(request, request.POST)--RubyThank you very much. Here is my code...
INV = grandmas4hire.models.Invitation
...def add_url_param(url, param, arg):
prefix = "&" if "?" in url else "/?"
return url + prefix + f'{param}={str(arg).replace(" ", "+")}'
---
@django.contrib.auth.decorators.login_required
def change_password(request):
user = request.user
msg = request.GET.get("msg")
if request.method == "POST":
form = grandmas4hire.forms.ChangePasswordForm(request.POST)
if form.is_valid():
new_password = form.cleaned_data["new_password"]
inv = INV.objects.get(user = user)
inv.user.set_password(new_password)
inv.user.save()
django.contrib.auth.update_session_auth_hash(request,
user)
url = add_url_param("/change_password",
"msg",
"Password+changed.")
reply = django.shortcuts.redirect(url)
else:
reply = django.shortcuts.render(request,
"change_password.html",
{"form" : form})
else:
form = grandmas4hire.forms.ChangePasswordForm()
reply = django.shortcuts.render(request,
"change_password.html",
{"form" : form,
"msg" : msg})
return reply--On Tuesday, November 5, 2024 at 5:41:09 PM UTC-6 Ruby wrote:How was it implemented?Show a snippet from your codeSee how it was used in my codeform = ChangePasswordForm(request, request.POST)if form.is_valid():user = form.save()update_session_auth_hash(request, user)messages.success(request, "Your password has been successfully updated")return redirect(request.META.get('HTTP_REFERER'))When I change a password, users are logged out.Django recommends keeping users logged inby calling django.contrib.auth.update_session_auth_hash(request, user).This is not working in a Django website of mine.They must log in again!?There are no error messages. Is there any way I can providemore details?Chris--
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.
To view this discussion visit https://groups.google.com/d/msgid/django-users/04908d1c-a1e4-41ea-afd8-e227f78af8bcn%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 django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/0c0c2c50-5064-4e9d-a579-f0ddb323c11an%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 django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CAPUD46tCgtE4bK6yrrZ18FuxE4oTsvkda%2BLG2S8Fz14pxrkb%3DA%40mail.gmail.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 django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CAGiSraBJ4SuFGgJKiMWvuspOM0Sp3%3DKgKVb%2BAfoHQDkG6%3D2HsQ%40mail.gmail.com.
No comments:
Post a Comment