[FIX] auth_signup: send confirmation email when registering
Steps to reproduce:
- In settings, activate "Free sign up" option;
- Go to "Sign in" page;
- Click on "Don't have an account?";
- Create an account.
Issue:
No confirmation email is sent.
Cause:
The `qcontext.get('token')` variable does not exist
in the case of a "Free sign up".
And therefore, we do not respect the condition to send an email.
opw-3103867
closes odoo/odoo#112078
X-original-commit: 6711a0ca362763fa641f0e855e4a3c283fe633ec
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
This commit is contained in:
@@ -43,14 +43,13 @@ class AuthSignupHome(Home):
|
||||
try:
|
||||
self.do_signup(qcontext)
|
||||
# Send an account creation confirmation email
|
||||
if qcontext.get('token'):
|
||||
User = request.env['res.users']
|
||||
user_sudo = User.sudo().search(
|
||||
User._get_login_domain(qcontext.get('login')), order=User._get_login_order(), limit=1
|
||||
)
|
||||
template = request.env.ref('auth_signup.mail_template_user_signup_account_created', raise_if_not_found=False)
|
||||
if user_sudo and template:
|
||||
template.sudo().send_mail(user_sudo.id, force_send=True)
|
||||
User = request.env['res.users']
|
||||
user_sudo = User.sudo().search(
|
||||
User._get_login_domain(qcontext.get('login')), order=User._get_login_order(), limit=1
|
||||
)
|
||||
template = request.env.ref('auth_signup.mail_template_user_signup_account_created', raise_if_not_found=False)
|
||||
if user_sudo and template:
|
||||
template.sudo().send_mail(user_sudo.id, force_send=True)
|
||||
return self.web_login(*args, **kw)
|
||||
except UserError as e:
|
||||
qcontext['error'] = e.args[0]
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_login
|
||||
from . import test_reset_password
|
||||
from . import test_auth_signup
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import odoo
|
||||
from odoo.tests import HttpCase
|
||||
from odoo import http
|
||||
|
||||
class TestAuthSignupFlow(HttpCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAuthSignupFlow, self).setUp()
|
||||
res_config = self.env['res.config.settings']
|
||||
self.default_values = res_config.default_get(list(res_config.fields_get()))
|
||||
|
||||
def _activate_free_signup(self):
|
||||
self.default_values.update({'auth_signup_uninvited': 'b2c'})
|
||||
|
||||
def _get_free_signup_url(self):
|
||||
return '/web/signup'
|
||||
|
||||
def test_confirmation_mail_free_signup(self):
|
||||
"""
|
||||
Check if a new user is informed by email when he is registered
|
||||
"""
|
||||
|
||||
# Activate free signup
|
||||
self._activate_free_signup()
|
||||
|
||||
# Get csrf_token
|
||||
self.authenticate(None, None)
|
||||
csrf_token = http.Request.csrf_token(self)
|
||||
|
||||
# Values from login form
|
||||
name = 'toto'
|
||||
payload = {
|
||||
'login': 'toto@example.com',
|
||||
'name': name,
|
||||
'password': 'mypassword',
|
||||
'confirm_password': 'mypassword',
|
||||
'csrf_token': csrf_token,
|
||||
}
|
||||
|
||||
# Override unlink to not delete the email if the send works.
|
||||
with patch.object(odoo.addons.mail.models.mail_mail.MailMail, 'unlink', lambda self: None):
|
||||
# Call the controller
|
||||
url_free_signup = self._get_free_signup_url()
|
||||
self.url_open(url_free_signup, data=payload)
|
||||
# Check if an email is sent to the new userw
|
||||
new_user = self.env['res.users'].search([('name', '=', name)])
|
||||
self.assertTrue(new_user)
|
||||
mail = self.env['mail.message'].search([('message_type', '=', 'email'), ('model', '=', 'res.users'), ('res_id', '=', new_user.id)], limit=1)
|
||||
self.assertTrue(mail, "The new user must be informed of his registration")
|
||||
Reference in New Issue
Block a user