You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
2.5 KiB

# -*- encoding: utf-8 -*-
##############################################################################
#
# Authentification - Generate Password module for Odoo
# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# This line is noqa flaged, to allow users to use string functions written
# in ir_config_parameter
import string # flake8: noqa
import random
from openerp.osv.orm import Model
from openerp.osv.osv import except_osv
from openerp.tools.translate import _
class res_users(Model):
_inherit = 'res.users'
def generate_password(self, cr, uid, ids, context=None):
mm_obj = self.pool['mail.mail']
icp_obj = self.pool['ir.config_parameter']
imd_obj = self.pool['ir.model.data']
et_obj = self.pool['email.template']
password_size = eval(icp_obj.get_param(
cr, uid, 'auth_generate_password.password_size'))
password_chars = eval(icp_obj.get_param(
cr, uid, 'auth_generate_password.password_chars'))
for ru in self.browse(cr, uid, ids, context=context):
if not ru.email:
raise osv.except_osv(
_("Cannot send email: user has no email address."),
user.name)
# Generate Password
password = "".join([random.choice(
password_chars) for n in xrange(password_size)])
self._set_new_password(
cr, uid, ru.id, None, password, None, context=None)
# Send Mail
et = imd_obj.get_object(
cr, uid, 'auth_generate_password',
'generate_password_template')
mail_id = et_obj.send_mail(
cr, uid, et.id, ru.id, True, context=context)
return {}