Hello, I am trying to create a user account dashboard where there will
be multiple forms, for example, one to change the name and email,
another to change the password and yet another for an account
termination request. While everything else is working just fine, the
auth.change_password form is not working as desired. I am using AJAX-
Auth-LOAD together and the problem I am facing is that after
validation and everything, the complete 'app/index' page is injected
into the target div.. i.e. Page inside the DIV of another Page! How
can I override and disable the injection of app/index into the target
DIV when password has been successfully changed.. n instead just do a
response.flash = "Password Updated"
Here's the code I am using:
####################
# Controller: ACCOUNT
####################
@auth.requires_login()
def settings():
response.title = "Dashboard"
next = URL(r=request,c='account',f='settings')
# auth.settings.register_next =
URL(r=request,c='account',f='settings')
return dict(form1 = auth.change_password(onaccept=lambda
form:response.headers.update({('web2py-component-
command'):"document.location='%s'"%next})) )
def changePreferences():
# Preferences form - for full name and email change
user_id = auth.user.id
u = db(db.auth_user.id == user_id).select(db.auth_user.ALL)[0]
record = db.auth_user(user_id)
settings_form = SQLFORM(db.auth_user, record, fields =
['display_name', 'email'], labels = {'display_name' : 'Full Name:',
'email': 'Email Address:'}, submit_button = 'Save Changes',
showid=False, _id='user_settings_form')
if settings_form.accepts(request.vars, formname = 'form2'):
if not ((settings_form.vars.display_name ==
auth.user.display_name) and (settings_form.vars.email ==
auth.user.email)):
if settings_form.vars.display_name !=
auth.user.display_name:
u.update_record(display_name =
settings_form.vars.display_name)
auth.user.display_name =
settings_form.vars.display_name
if settings_form.vars.email != auth.user.email:
u.update_record(email = settings_form.vars.email)
auth.user.email = settings_form.vars.email
response.flash = "Preferences Updated"
#redirect(URL(request.application, c='default',
f='index'))
#redirect(URL())
return settings_form
def changePassword():
next = URL(r=request,c='account',f='settings')
# auth.settings.register_next =
URL(r=request,c='account',f='settings')
return auth.change_password(onaccept=lambda
form:response.headers.update({('web2py-component-
command'):"document.location='%s'"%next}))
#return change_password
################################
# view:ACCOUNT > SETTINGS.html
################################
<h2 class="form_title">Preferences:</h2>
{{=LOAD('account', 'changePreferences', ajax=True,
target='TargetDiv')}}<br />
{{if not (auth.user.fbuser_id):}}
<script>
$('#TargetDiv2 form').bind('submit', function(){
url="{{=URL(r=request, f='settings')}}";
alert(url);
ids = ['no_table_old_password',
'no_table_new_password', 'no_table_new_password2'];
ajax(url, ids, 'TargetDiv2');
return false;
});
</script>
<h2 class="form_title">Change Password:</h2>
{{=LOAD('account', 'changePassword', ajax=True,
target='TargetDiv2')}}<br />
{{pass}}
I'd be really thankful for any suggestions n help..
-
Regards