Ruby
Thank 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