I have two forms in the Settings page: change password and change email. My 
code in profile.py:

@auth.requires_login()
def settings():

        #change user's password
change_password = auth.change_password(next=URL('profile', 'settings'))
change_password.update(_class='formstyle', _name='change_password')

#change user's email        
        change_email = SQLFORM.factory(Field('email', 
requires=[IS_EMAIL(error_message="Wrong email"), IS_NOT_IN_DB(db, 
'auth_user.email', error_message="Email already exists")], label='New 
email'), formstyle='divs')
change_email.update(_class='formstyle', _name='email_change')

if change_email.process(formname='email_change').accepted:
response.flash = "Email changed"
else:
response.flash = None

return dict(change_password=change_password,
change_email=change_email)

Both forms work fine. Password and email get changed.

When the change_email form is submitted, I am still on Settings page and 
flash message is displayed ("Email changed"). I would like the same when I 
submit change_password.

I'm not sure how to check whether session.flash gets overridden.

On Sunday, October 13, 2013 12:17:46 AM UTC+2, Anthony wrote:
>
> Is there any code in the settings function or view that could be clearing 
> the session flash or somehow removing/overriding the flash? 
> auth.change_password sets session.flash before the redirect, so session 
> flash should get moved into response.flash after the redirect.
>
> Anthony
>
> On Saturday, October 12, 2013 6:00:00 PM UTC-4, lesssugar wrote:
>>
>> OK, I removed next from auth.change_password(). Now, after submitting, 
>> I'm being redirected to default/index and the default flash message appears.
>>
>> The thing is I would like to stay on Settings page after changing the 
>> password - hence I tried next. Is there a way to change the default 
>> redirect URL with my own?
>>
>> On Saturday, October 12, 2013 11:46:58 PM UTC+2, Anthony wrote:
>>>
>>> auth.change_password() does a redirect when you specify "next", so you 
>>> can't set anything after calling it. However, instead you can just do:
>>>
>>> auth.messages.password_changed = 'Your custom flash message'
>>>
>>> Of course, there is already a default message set ("Password changed."), 
>>> so if you're not seeing it, something is going wrong. Do you get other 
>>> flash messages? Maybe confirm that session.flash is being set.
>>>
>>> Anthony
>>>
>>> On Saturday, October 12, 2013 5:23:44 PM UTC-4, lesssugar wrote:
>>>>
>>>> I'm using auth.change_password() in my profile Settings section. The 
>>>> code responsible for the form:
>>>>
>>>> change_password = auth.change_password(next=URL('profile', 'settings'))
>>>> change_password.update(_class='formstyle', _name='change_password')
>>>>
>>>> return dict(change_password=change_password)
>>>>
>>>>
>>>> The form works, the input is processed, the password gets changed. 
>>>> However there's no flash message after submitting the form. I guess, as 
>>>> change_password() is a build-in function, there should be a default flash 
>>>> message.
>>>>
>>>> I tried adding this (below), and it also doesn't work:
>>>>
>>>> if change_password.accepted:
>>>>     response.flash = "Password changed"
>>>>
>>>> Any ideas?
>>>>
>>>>
>>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to