[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')( old_password, new_password,confirm_password = operator.itemgetter('old_pwd', 'new_password','confirm_pwd')(
dict(map(operator.itemgetter('name', 'value'), fields))) dict(map(operator.itemgetter('name', 'value'), fields)))
if not (old_password.strip() and new_password.strip() and confirm_password.strip()): 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: if new_password != confirm_password:
return {'error': 'The new password and its confirmation must be identical.','title': 'Change Password'} return {'error': 'The new password and its confirmation must be identical.','title': 'Change Password'}
try: try:
@ -905,7 +905,7 @@ class Session(openerpweb.Controller):
old_password, new_password): old_password, new_password):
return {'new_password':new_password} return {'new_password':new_password}
except Exception: 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'} return {'error': 'Error, password not changed !', 'title': 'Change Password'}
@openerpweb.jsonrequest @openerpweb.jsonrequest

View File

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

View File

@ -315,26 +315,32 @@
<t t-name="ChangePassword"> <t t-name="ChangePassword">
<form name="change_password_form" method="POST"> <form name="change_password_form" method="POST">
<div class="oe_form">
<table align="center"> <table align="center">
<tr> <tr>
<td><label for="old_pwd">Old Password:</label></td> <td class="oe_form_group_cell oe_form_group_cell_label"><label for="old_pwd" class="oe_form_label">Old Password:</label></td>
<td><input type="password" name="old_pwd" <td class="oe_form_group_cell"><input type="password" name="old_pwd"
minlength="1" autofocus="autofocus"/></td> minlength="1" autofocus="autofocus"/></td>
</tr> </tr>
<tr> <tr>
<td><label for="new_password">New Password:</label></td> <td class="oe_form_group_cell oe_form_group_cell_label"><label for="new_password" class="oe_form_label">New Password:</label></td>
<td><input type="password" name="new_password" <td class="oe_form_group_cell"><input type="password" name="new_password"
minlength="1"/></td> minlength="1"/></td>
</tr> </tr>
<tr> <tr>
<td><label for="confirm_pwd">Confirm Password:</label></td> <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><input type="password" name="confirm_pwd" <td class="oe_form_group_cell"><input type="password" name="confirm_pwd"
minlength="1"/></td> minlength="1"/></td>
</tr> </tr>
<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> </tr>
</table> </table>
</div>
</form> </form>
</t> </t>