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.










share|improve this question





















  • 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














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.










share|improve this question





















  • 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












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 5 at 23:43









Nico

137




137











  • 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
















  • 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















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












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)






share|improve this answer




















  • I tried but no effect.
    – Nico
    Nov 6 at 19:38

















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






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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)






    share|improve this answer




















    • I tried but no effect.
      – Nico
      Nov 6 at 19:38














    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)






    share|improve this answer




















    • I tried but no effect.
      – Nico
      Nov 6 at 19:38












    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)






    share|improve this answer












    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)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 6 at 5:59









    Reema Parakh

    468




    468











    • 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




    I tried but no effect.
    – Nico
    Nov 6 at 19:38












    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






    share|improve this answer


























      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






      share|improve this answer
























        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






        share|improve this answer














        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 22 hours ago

























        answered yesterday









        Nico

        137




        137



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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














































































            這個網誌中的熱門文章

            How to combine Bézier curves to a surface?

            Mutual Information Always Non-negative

            Why am i infinitely getting the same tweet with the Twitter Search API?