[IMP] improved change password dialog

bzr revid: fp@tinyerp.com-20121126084339-10z9t97tbc3izmm6
This commit is contained in:
Fabien Pinckaers 2012-11-26 09:43:39 +01:00
commit 456dd91064
3 changed files with 33 additions and 23 deletions

View File

@ -897,7 +897,7 @@ class Session(openerpweb.Controller):
old_password, new_password,confirm_password = operator.itemgetter('old_pwd', 'new_password','confirm_pwd')(
dict(map(operator.itemgetter('name', 'value'), fields)))
if not (old_password.strip() and new_password.strip() and confirm_password.strip()):
return {'error':'All passwords have to be filled.','title': 'Change Password'}
return {'error':'You cannot leave any password empty.','title': 'Change Password'}
if new_password != confirm_password:
return {'error': 'The new password and its confirmation must be identical.','title': 'Change Password'}
try:
@ -905,7 +905,7 @@ class Session(openerpweb.Controller):
old_password, new_password):
return {'new_password':new_password}
except Exception:
return {'error': 'Original password incorrect, your password was not changed.', 'title': 'Change Password'}
return {'error': 'The old password you provided is incorrect, your password was not changed.', 'title': 'Change Password'}
return {'error': 'Error, password not changed !', 'title': 'Change Password'}
@openerpweb.jsonrequest

View File

@ -765,20 +765,24 @@ instance.web.ChangePassword = instance.web.Widget.extend({
template: "ChangePassword",
start: function() {
var self = this;
self.$el.validate({
submitHandler: function (form) {
self.rpc("/web/session/change_password",{
'fields': $(form).serializeArray()
}).done(function(result) {
if (result.error) {
self.display_error(result);
return;
} else {
instance.webclient.on_logout();
}
});
}
});
this.getParent().dialog_title = "Change Password";
var $button = self.$el.find('.oe_form_button');
$button.appendTo(this.getParent().$buttons);
$button.eq(2).click(function(){
self.getParent().close();
})
$button.eq(0).click(function(){
self.rpc("/web/session/change_password",{
'fields': $("form[name=change_password_form]").serializeArray()
}).done(function(result) {
if (result.error) {
self.display_error(result);
return;
} else {
instance.webclient.on_logout();
}
});
})
},
display_error: function (error) {
return instance.web.dialog($('<div>'), {

View File

@ -315,26 +315,32 @@
<t t-name="ChangePassword">
<form name="change_password_form" method="POST">
<div class="oe_form">
<table align="center">
<tr>
<td><label for="old_pwd">Old Password:</label></td>
<td><input type="password" name="old_pwd"
<td class="oe_form_group_cell oe_form_group_cell_label"><label for="old_pwd" class="oe_form_label">Old Password:</label></td>
<td class="oe_form_group_cell"><input type="password" name="old_pwd"
minlength="1" autofocus="autofocus"/></td>
</tr>
<tr>
<td><label for="new_password">New Password:</label></td>
<td><input type="password" name="new_password"
<td class="oe_form_group_cell oe_form_group_cell_label"><label for="new_password" class="oe_form_label">New Password:</label></td>
<td class="oe_form_group_cell"><input type="password" name="new_password"
minlength="1"/></td>
</tr>
<tr>
<td><label for="confirm_pwd">Confirm Password:</label></td>
<td><input type="password" name="confirm_pwd"
<td class="oe_form_group_cell oe_form_group_cell_label"><label for="confirm_pwd" class="oe_form_label">Confirm New Password:</label></td>
<td class="oe_form_group_cell"><input type="password" name="confirm_pwd"
minlength="1"/></td>
</tr>
<tr>
<td colspan="2" align="right"><button class="oe_button">Change Password</button></td>
<td colspan="2" align="right">
<button class='oe_button oe_form_button'>Change Password</button>
<span class="oe_fade oe_form_button"> or </span>
<button type="button" class="oe_button oe_form_button_cancel oe_form_button oe_link" href="javascript:void(0)"><span>Cancel</span></button>
</td>
</tr>
</table>
</div>
</form>
</t>