diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index d5eaafaecee..6a7f143776c 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -278,7 +278,7 @@ class Database(openerpweb.Controller): except xmlrpclib.Fault, e: if e.faultCode and e.faultCode.split(':')[0] == 'AccessDenied': return {'error': e.faultCode, 'title': 'Change Password'} - return {'error': 'Error, password not changed !', 'title': 'Change Password'} + return {'error': 'Error, password not changed !', 'title': 'Change Password'} class Session(openerpweb.Controller): _cp_path = "/base/session" @@ -293,7 +293,19 @@ class Session(openerpweb.Controller): "uid": req.session._uid, "context": ctx } - + @openerpweb.jsonrequest + def change_password (self,req,fields): + old_password, new_password,confirm_password = operator.itemgetter('old_pwd', 'new_pwd','confirm_pwd')( + dict(map(operator.itemgetter('name', 'value'), fields))) + try: + if req.session.model('res.users').change_password( + old_password, new_password): + req.session.password = new_password + return dict(changed=True) + raise redirect('/') + except xmlrpclib.Fault, e: + return {'error': 'Original password incorrect, your password was not changed.', 'title': 'Change Password'} + @openerpweb.jsonrequest def sc_list(self, req): return req.session.model('ir.ui.view_sc').get_sc( diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 3aff7b5e402..861a02cc49a 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -572,6 +572,7 @@ openerp.base.Header = openerp.base.Widget.extend({ do_update: function () { this.$element.html(QWeb.render("Header", this)); this.$element.find(".logout").click(this.on_logout); + this.$element.find("a.preferences").click(this.on_preferences); return this.shortcut_load(); }, shortcut_load :function(){ @@ -621,9 +622,98 @@ openerp.base.Header = openerp.base.Widget.extend({ }); }); }, + on_action: function(action) { }, - + on_preferences: function(){ + var self = this; + var action_manager = new openerp.base.ActionManager(this); + this.rpc('/base/dataset/call', {model: 'res.users',method:"action_get",args: []},function(result){ + self.rpc('/base/action/load', { action_id: result}, function(result){ + result['result']['res_id'] = self.session.uid; + result['result']['res_model']= 'res.users'; + result['result']['view_id']=result['result']['views'][0][0]; + result['result']['flags']['action_buttons']=false; + result['result']['flags']['search_view']=false; + result['result']['flags']['sidebar']=false; + result['result']['view_mode']="form"; + result['result']['flags']['views_switcher']=false; + result['result']['flags']['pager']=false; + action_manager.do_action(result['result']); + }); + }); + this.dialog = new openerp.base.Dialog(this,{ + modal: true, + title: 'Preferences', + width: 600, + height: 500, + buttons: { + "Change password": function(){ + self.change_password(); + }, + Cancel: function(){ + $(this).dialog('destroy'); + }, + Save: function(){ + var inner_viewmanager = action_manager.inner_viewmanager; + inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save(function(){ + inner_viewmanager.start(); + }); + $(this).dialog('destroy'); + }, + }, + }); + this.dialog.start(); + this.dialog.open(); + action_manager.appendTo(this.dialog); + action_manager.render(this.dialog); + }, + + change_password :function() { + var self = this; + this.dialog = new openerp.base.Dialog(this,{ + modal : true, + title : 'Change Password', + width : 'auto', + height : 'auto', + }); + this.dialog.start(); + this.dialog.open(); + this.dialog.$element.html(QWeb.render("Change_Pwd", self)); + this.dialog.$element.find("form[name=change_password_form]").validate({ + messages: { + old_password: "Please enter your previous password", + new_password: "Please enter your new password", + confirm_password: { + required: "Please confirm your new password", + equalTo: "The confirmation does not match the password" + }, + }, + submitHandler: function (form) { + self.rpc("/base/session/change_password",{ + 'fields': $("form[name=change_password_form]").serializeArray() + }, function(result) { + if (result.error) { + self.display_error(result); + return; + } + self.notification.notify("Changed Password", "Password has been changed successfully"); + self.dialog.close(); + }); + }, + }); +}, + display_error: function (error) { + return $('
').dialog({ + modal: true, + title: error.title, + buttons: { + Ok: function() { + $(this).dialog("close"); + } + } + }).html(error.error); + }, on_logout: function() { this.$element.find('.oe-shortcuts ul').empty(); } diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index c85d1fd4cb2..66f41005c05 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -66,7 +66,6 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi var self = this; this.fields_view = data.fields_view; var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch); - this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this })); _.each(this.widgets, function(w) { w.start(); @@ -578,6 +577,7 @@ openerp.base.form.Widget = openerp.base.Widget.extend({ this.$element = $('#' + this.element_id); }, stop: function() { + this.$element = $('#' + this.element_id); this.$element.remove(); }, process_modifiers: function() { diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index 81255fb3e75..7baf8d91c13 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -1307,4 +1307,35 @@ + +
+ + + + +
+ CHANGE PASSWORD +
+ + + + + + + + + + + + + + + + +
+
+