[IMP] auth_reset_password: add button on user form view to reset the user's password
bzr revid: rco@openerp.com-20121003132152-1vbzao6n34na2uw6
This commit is contained in:
parent
224520c2ca
commit
8fbdc2a825
|
@ -20,4 +20,4 @@
|
|||
##############################################################################
|
||||
|
||||
import controllers
|
||||
import auth_reset_password
|
||||
import res_users
|
||||
|
|
|
@ -31,7 +31,10 @@ Allow users to reset their password from the login page.
|
|||
'website': 'http://www.openerp.com',
|
||||
'installable': True,
|
||||
'depends': ['auth_signup', 'email_template'],
|
||||
'data': ['auth_reset_password.xml'],
|
||||
'data': [
|
||||
'auth_reset_password.xml',
|
||||
'res_users_view.xml',
|
||||
],
|
||||
'js': ['static/src/js/reset_password.js'],
|
||||
'qweb': ['static/src/xml/reset_password.xml'],
|
||||
}
|
||||
|
|
|
@ -34,22 +34,26 @@ class res_users(osv.osv):
|
|||
|
||||
def reset_password(self, cr, uid, login, context=None):
|
||||
""" retrieve the user corresponding to login (login or email),
|
||||
create a specific signup token, and send it to the user
|
||||
and reset their password
|
||||
"""
|
||||
user_ids = self.search(cr, uid, [('login', '=', login)], context=context)
|
||||
if not user_ids:
|
||||
user_ids = self.search(cr, uid, [('email', '=', login)], context=context)
|
||||
if len(user_ids) != 1:
|
||||
raise Exception('Reset password: invalid username or email')
|
||||
return self.action_reset_password(cr, uid, user_ids, context=context)
|
||||
|
||||
def action_reset_password(self, cr, uid, ids, context=None):
|
||||
""" create signup token for each user, and send their signup url by email """
|
||||
# prepare reset password signup
|
||||
user = self.browse(cr, uid, user_ids[0], context)
|
||||
user.partner_id.signup_prepare(expiration=now(days=+1))
|
||||
res_partner = self.pool.get('res.partner')
|
||||
partner_ids = [user.partner_id.id for user in self.browse(cr, uid, ids, context)]
|
||||
res_partner.signup_prepare(cr, uid, partner_ids, expiration=now(days=+1), context=context)
|
||||
|
||||
# send email to user with their signup url
|
||||
user = self.browse(cr, uid, user.id, context)
|
||||
# send email to users with their signup url
|
||||
template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_reset_password', 'reset_password_email')
|
||||
assert template._name == 'email.template'
|
||||
self.pool.get('email.template').send_mail(cr, uid, template.id, user.id, force_send=True, context=context)
|
||||
for user in self.browse(cr, uid, ids, context):
|
||||
self.pool.get('email.template').send_mail(cr, uid, template.id, user.id, context=context)
|
||||
|
||||
return True
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="res_users_form_view" model="ir.ui.view">
|
||||
<field name="name">user.form.reset_password</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//sheet/*[1]" position="before">
|
||||
<div class="oe_right oe_button_box">
|
||||
<button string="Reset Password" type="object" name="action_reset_password"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue