Display a confirmation message after a password change
up vote
0
down vote
favorite
After a user succesfull password change I keep the user on the same page named password_change.
url.py:
path('password_change/', auth_views.PasswordChangeView.as_view(success_url=reverse_lazy('password_change')), name='password_change'),
I tried using the messages framework with:
views.py:
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
messages.success(request, 'Your password has been updated', extra_tags='safe')
return render(request, 'registration/password_change_form.html', 'password_form': password_form)
with this in my html :
% if messages %
% for message in messages %
<p class=' message.tags '> message </p>
% endfor %
% endif %
And I tried:
views.py:
def password_change(request):
success = False;
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
success = True;
return render(request, 'registration/password_change_form.html', 'password_form': password_form, 'success': success)
with that in my html :
% if success %
<div>Password changed !!!</div>
% endif %
The password is changed but I can't display a message to celebrate this wonderful success.
django django-forms
add a comment |
up vote
0
down vote
favorite
After a user succesfull password change I keep the user on the same page named password_change.
url.py:
path('password_change/', auth_views.PasswordChangeView.as_view(success_url=reverse_lazy('password_change')), name='password_change'),
I tried using the messages framework with:
views.py:
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
messages.success(request, 'Your password has been updated', extra_tags='safe')
return render(request, 'registration/password_change_form.html', 'password_form': password_form)
with this in my html :
% if messages %
% for message in messages %
<p class=' message.tags '> message </p>
% endfor %
% endif %
And I tried:
views.py:
def password_change(request):
success = False;
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
success = True;
return render(request, 'registration/password_change_form.html', 'password_form': password_form, 'success': success)
with that in my html :
% if success %
<div>Password changed !!!</div>
% endif %
The password is changed but I can't display a message to celebrate this wonderful success.
django django-forms
What happens when you remove themessage.tags
and just showmessage
?
– Riyaaz-0
Nov 6 at 12:04
Nothing new has happened.
– Nico
Nov 6 at 19:39
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
After a user succesfull password change I keep the user on the same page named password_change.
url.py:
path('password_change/', auth_views.PasswordChangeView.as_view(success_url=reverse_lazy('password_change')), name='password_change'),
I tried using the messages framework with:
views.py:
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
messages.success(request, 'Your password has been updated', extra_tags='safe')
return render(request, 'registration/password_change_form.html', 'password_form': password_form)
with this in my html :
% if messages %
% for message in messages %
<p class=' message.tags '> message </p>
% endfor %
% endif %
And I tried:
views.py:
def password_change(request):
success = False;
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
success = True;
return render(request, 'registration/password_change_form.html', 'password_form': password_form, 'success': success)
with that in my html :
% if success %
<div>Password changed !!!</div>
% endif %
The password is changed but I can't display a message to celebrate this wonderful success.
django django-forms
After a user succesfull password change I keep the user on the same page named password_change.
url.py:
path('password_change/', auth_views.PasswordChangeView.as_view(success_url=reverse_lazy('password_change')), name='password_change'),
I tried using the messages framework with:
views.py:
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
messages.success(request, 'Your password has been updated', extra_tags='safe')
return render(request, 'registration/password_change_form.html', 'password_form': password_form)
with this in my html :
% if messages %
% for message in messages %
<p class=' message.tags '> message </p>
% endfor %
% endif %
And I tried:
views.py:
def password_change(request):
success = False;
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
success = True;
return render(request, 'registration/password_change_form.html', 'password_form': password_form, 'success': success)
with that in my html :
% if success %
<div>Password changed !!!</div>
% endif %
The password is changed but I can't display a message to celebrate this wonderful success.
django django-forms
django django-forms
asked Nov 5 at 23:43
Nico
137
137
What happens when you remove themessage.tags
and just showmessage
?
– Riyaaz-0
Nov 6 at 12:04
Nothing new has happened.
– Nico
Nov 6 at 19:39
add a comment |
What happens when you remove themessage.tags
and just showmessage
?
– Riyaaz-0
Nov 6 at 12:04
Nothing new has happened.
– Nico
Nov 6 at 19:39
What happens when you remove the
message.tags
and just show message
?– Riyaaz-0
Nov 6 at 12:04
What happens when you remove the
message.tags
and just show message
?– Riyaaz-0
Nov 6 at 12:04
Nothing new has happened.
– Nico
Nov 6 at 19:39
Nothing new has happened.
– Nico
Nov 6 at 19:39
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Might be your success variable is not setting its value to "True".
In your second method try putting success=True
before the line update_session_auth_hash(request, password_form.user)
I tried but no effect.
– Nico
Nov 6 at 19:38
add a comment |
up vote
0
down vote
I found an acceptable solution.
In this example I redirect to an other page but the principle would be the same if I wanted to redirect on the same page :
urls.py:
path('password_change/', auth_views.PasswordChangeView.as_view(), name = 'password_change'),
path('edit_profile_alt/', views.CustomPasswordChangeDoneView.as_view(), name = 'password_change_done'),
views.py:
@login_required(redirect_field_name = 'login')
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
class CustomPasswordChangeDoneView(PasswordChangeDoneView):
template_name = 'appName/edit_profile.html'
extra_context = 'done': 'done'
the html template:
% if done %
<p>
You have a changed your password.
</p>
% else %
Good to read if you want to do the same kind of thing : https://docs.djangoproject.com/en/2.1/topics/auth/default/#django.contrib.auth.views.PasswordChangeDoneView
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Might be your success variable is not setting its value to "True".
In your second method try putting success=True
before the line update_session_auth_hash(request, password_form.user)
I tried but no effect.
– Nico
Nov 6 at 19:38
add a comment |
up vote
0
down vote
Might be your success variable is not setting its value to "True".
In your second method try putting success=True
before the line update_session_auth_hash(request, password_form.user)
I tried but no effect.
– Nico
Nov 6 at 19:38
add a comment |
up vote
0
down vote
up vote
0
down vote
Might be your success variable is not setting its value to "True".
In your second method try putting success=True
before the line update_session_auth_hash(request, password_form.user)
Might be your success variable is not setting its value to "True".
In your second method try putting success=True
before the line update_session_auth_hash(request, password_form.user)
answered Nov 6 at 5:59
Reema Parakh
468
468
I tried but no effect.
– Nico
Nov 6 at 19:38
add a comment |
I tried but no effect.
– Nico
Nov 6 at 19:38
I tried but no effect.
– Nico
Nov 6 at 19:38
I tried but no effect.
– Nico
Nov 6 at 19:38
add a comment |
up vote
0
down vote
I found an acceptable solution.
In this example I redirect to an other page but the principle would be the same if I wanted to redirect on the same page :
urls.py:
path('password_change/', auth_views.PasswordChangeView.as_view(), name = 'password_change'),
path('edit_profile_alt/', views.CustomPasswordChangeDoneView.as_view(), name = 'password_change_done'),
views.py:
@login_required(redirect_field_name = 'login')
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
class CustomPasswordChangeDoneView(PasswordChangeDoneView):
template_name = 'appName/edit_profile.html'
extra_context = 'done': 'done'
the html template:
% if done %
<p>
You have a changed your password.
</p>
% else %
Good to read if you want to do the same kind of thing : https://docs.djangoproject.com/en/2.1/topics/auth/default/#django.contrib.auth.views.PasswordChangeDoneView
add a comment |
up vote
0
down vote
I found an acceptable solution.
In this example I redirect to an other page but the principle would be the same if I wanted to redirect on the same page :
urls.py:
path('password_change/', auth_views.PasswordChangeView.as_view(), name = 'password_change'),
path('edit_profile_alt/', views.CustomPasswordChangeDoneView.as_view(), name = 'password_change_done'),
views.py:
@login_required(redirect_field_name = 'login')
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
class CustomPasswordChangeDoneView(PasswordChangeDoneView):
template_name = 'appName/edit_profile.html'
extra_context = 'done': 'done'
the html template:
% if done %
<p>
You have a changed your password.
</p>
% else %
Good to read if you want to do the same kind of thing : https://docs.djangoproject.com/en/2.1/topics/auth/default/#django.contrib.auth.views.PasswordChangeDoneView
add a comment |
up vote
0
down vote
up vote
0
down vote
I found an acceptable solution.
In this example I redirect to an other page but the principle would be the same if I wanted to redirect on the same page :
urls.py:
path('password_change/', auth_views.PasswordChangeView.as_view(), name = 'password_change'),
path('edit_profile_alt/', views.CustomPasswordChangeDoneView.as_view(), name = 'password_change_done'),
views.py:
@login_required(redirect_field_name = 'login')
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
class CustomPasswordChangeDoneView(PasswordChangeDoneView):
template_name = 'appName/edit_profile.html'
extra_context = 'done': 'done'
the html template:
% if done %
<p>
You have a changed your password.
</p>
% else %
Good to read if you want to do the same kind of thing : https://docs.djangoproject.com/en/2.1/topics/auth/default/#django.contrib.auth.views.PasswordChangeDoneView
I found an acceptable solution.
In this example I redirect to an other page but the principle would be the same if I wanted to redirect on the same page :
urls.py:
path('password_change/', auth_views.PasswordChangeView.as_view(), name = 'password_change'),
path('edit_profile_alt/', views.CustomPasswordChangeDoneView.as_view(), name = 'password_change_done'),
views.py:
@login_required(redirect_field_name = 'login')
def password_change(request):
password_form = PasswordChangeForm(instance = request.user, data = request.POST)
if request.method == 'POST':
if password_form.is_valid():
password_form.save()
update_session_auth_hash(request, password_form.user) # <-- keep the user loged after password change
class CustomPasswordChangeDoneView(PasswordChangeDoneView):
template_name = 'appName/edit_profile.html'
extra_context = 'done': 'done'
the html template:
% if done %
<p>
You have a changed your password.
</p>
% else %
Good to read if you want to do the same kind of thing : https://docs.djangoproject.com/en/2.1/topics/auth/default/#django.contrib.auth.views.PasswordChangeDoneView
edited 22 hours ago
answered yesterday
Nico
137
137
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53163907%2fdisplay-a-confirmation-message-after-a-password-change%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What happens when you remove the
message.tags
and just showmessage
?– Riyaaz-0
Nov 6 at 12:04
Nothing new has happened.
– Nico
Nov 6 at 19:39