+#----------------------------------------------------------
+# change password wizard
+#----------------------------------------------------------
+
+class change_password_wizard(osv.TransientModel):
+ """
+ A wizard to manage the change of users' passwords
+ """
+
+ _name = "change.password.wizard"
+ _description = "Change Password Wizard"
+ _columns = {
+ 'user_ids': fields.one2many('change.password.user', 'wizard_id', string='Users'),
+ }
+
+ def _default_user_ids(self, cr, uid, context=None):
+ if context is None:
+ context = {}
+ user_model = self.pool['res.users']
+ user_ids = context.get('active_model') == 'res.users' and context.get('active_ids') or []
+ return [
+ (0, 0, {'user_id': user.id, 'user_login': user.login})
+ for user in user_model.browse(cr, uid, user_ids, context=context)
+ ]
+
+ _defaults = {
+ 'user_ids': _default_user_ids,
+ }
+
+ def change_password_button(self, cr, uid, ids, context=None):
+ wizard = self.browse(cr, uid, ids, context=context)[0]
+ need_reload = any(uid == user.user_id.id for user in wizard.user_ids)
+
+ line_ids = [user.id for user in wizard.user_ids]
+ self.pool.get('change.password.user').change_password_button(cr, uid, line_ids, context=context)
+
+ if need_reload:
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'reload'
+ }
+
+ return {'type': 'ir.actions.act_window_close'}
+
+class change_password_user(osv.TransientModel):
+ """
+ A model to configure users in the change password wizard
+ """
+
+ _name = 'change.password.user'
+ _description = 'Change Password Wizard User'
+ _columns = {
+ 'wizard_id': fields.many2one('change.password.wizard', string='Wizard', required=True),
+ 'user_id': fields.many2one('res.users', string='User', required=True),
+ 'user_login': fields.char('User Login', readonly=True),
+ 'new_passwd': fields.char('New Password'),
+ }
+ _defaults = {
+ 'new_passwd': '',
+ }
+
+ def change_password_button(self, cr, uid, ids, context=None):
+ for line in self.browse(cr, uid, ids, context=context):
+ line.user_id.write({'password': line.new_passwd})
+ # don't keep temporary passwords in the database longer than necessary
+ self.write(cr, uid, ids, {'new_passwd': False}, context=context)
+
+