Skip to content

Commit 4e53ef2

Browse files
committed
[FIX] auth_signup, website: make reset password multi website friendly
The "reset password" feature does not take into account multi-website. steps to reproduce: - create a website A - uncheck 'Shared Customer Accounts' on website A - create a portal user [email protected] on website A - create a website B - uncheck 'Shared Customer Accounts' on website B - create a portal user [email protected] on website B - reset password for [email protected] on any website before this commit: An error is raised "No account found for this login" (which is false, actually 2 accounts are found) after this commit: Only the user linked to the current website is properly selected opw-3551540 closes odoo#141925 X-original-commit: 4fd3b7a Signed-off-by: Romain Derie (rde) <[email protected]>
1 parent 8908de0 commit 4e53ef2

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

addons/auth_signup/i18n/auth_signup.pot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ msgstr ""
483483
msgid "Let your customers log in to see their documents"
484484
msgstr ""
485485

486+
#. module: auth_signup
487+
#: code:addons/auth_signup/models/res_users.py:0
488+
#, python-format
489+
msgid "Multiple accounts found for this email"
490+
msgstr ""
491+
486492
#. module: auth_signup
487493
#: model:ir.model.fields.selection,name:auth_signup.selection__res_users__state__new
488494
msgid "Never Connected"

addons/auth_signup/models/res_users.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ def reset_password(self, login):
152152
""" retrieve the user corresponding to login (login or email),
153153
and reset their password
154154
"""
155-
users = self.search([('login', '=', login)])
155+
users = self.search(self._get_login_domain(login))
156+
if not users:
157+
users = self.search(self._get_email_domain(login))
158+
156159
if not users:
157-
users = self.search([('email', '=', login)])
158-
if len(users) != 1:
159160
raise Exception(_('Reset password: invalid username or email'))
161+
if len(users) > 1:
162+
raise Exception(_('Multiple accounts found for this email'))
160163
return users.action_reset_password()
161164

162165
def action_reset_password(self):

addons/website/models/res_users.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def _get_login_domain(self, login):
4141
website = self.env['website'].get_current_website()
4242
return super(ResUsers, self)._get_login_domain(login) + website.website_domain()
4343

44+
@api.model
45+
def _get_email_domain(self, email):
46+
website = self.env['website'].get_current_website()
47+
return super()._get_email_domain(email) + website.website_domain()
48+
4449
@api.model
4550
def _get_login_order(self):
4651
return 'website_id, ' + super(ResUsers, self)._get_login_order()

addons/website/tests/test_website_reset_password.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,26 @@ def test_02_multi_user_login(self):
7575
# The most specific user should be selected
7676
self.authenticate("[email protected]", "[email protected]")
7777
self.assertEqual(self.session["uid"], user2.id)
78+
79+
def test_multi_website_reset_password_user_specific_user_account(self):
80+
# Create same user on different websites with 'Specific User Account'
81+
# option enabled and then reset password. Only the user from the
82+
# current website should be reset.
83+
website_1, website_2 = self.env['website'].create([
84+
{'name': 'Website 1', 'specific_user_account': True},
85+
{'name': 'Website 2', 'specific_user_account': True},
86+
])
87+
88+
login = '[email protected]' # same login for both users
89+
user_website_1, user_website_2 = self.env['res.users'].with_context(no_reset_password=True).create([
90+
{'website_id': website_1.id, 'login': login, 'email': login, 'name': login},
91+
{'website_id': website_2.id, 'login': login, 'email': login, 'name': login},
92+
])
93+
94+
self.assertFalse(user_website_1.signup_valid)
95+
self.assertFalse(user_website_2.signup_valid)
96+
97+
self.env['res.users'].with_context(website_id=website_1.id).reset_password(login)
98+
99+
self.assertTrue(user_website_1.signup_valid)
100+
self.assertFalse(user_website_2.signup_valid)

odoo/addons/base/models/res_users.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ def _update_last_login(self):
697697
def _get_login_domain(self, login):
698698
return [('login', '=', login)]
699699

700+
@api.model
701+
def _get_email_domain(self, email):
702+
return [('email', '=', email)]
703+
700704
@api.model
701705
def _get_login_order(self):
702706
return self._order

0 commit comments

Comments
 (0)