diff --git a/controllers/main.py b/controllers/main.py index 0cfbc948f19ee8f074b4b335744f7cf8f70944b7..2c0a61535ae097850aae91cf44dc89f2eca8dd04 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -1,28 +1,38 @@ -from odoo import http, tools, _ -from odoo.addons.web.controllers.home import SIGN_UP_REQUEST_PARAMS +from odoo import _, http, tools from odoo.addons.auth_signup.controllers.main import AuthSignupHome +from odoo.addons.web.controllers.home import SIGN_UP_REQUEST_PARAMS # add firstname and lastname to qcontext whitelist SIGN_UP_REQUEST_PARAMS.update({"firstname", "lastname"}) SIGN_UP_REQUEST_PARAMS.update({"error_email"}) + class SolagroAuthSignupHome(AuthSignupHome): - @http.route('/web/signup', type='http', auth='public', website=True, sitemap=False) + @http.route("/web/signup", type="http", auth="public", website=True, sitemap=False) def web_auth_signup(self, **post): # email validation - if post and http.request.httprequest.method == 'POST': - email = post.get('email') + if post and http.request.httprequest.method == "POST": + email = post.get("email") if email and not tools.single_email_re.match(email): - post.update({'error': _('Invalid Email! Please enter a valid email address.'), 'error_email': True}) + post.update( + { + "error": _( + "Invalid Email! Please enter a valid email address." + ), + "error_email": True, + } + ) else: post["login"] = email # name from firstname / lastname - if post and http.request.httprequest.method == 'POST': - firstname = post.get('firstname') - lastname = post.get('lastname') + if post and http.request.httprequest.method == "POST": + firstname = post.get("firstname") + lastname = post.get("lastname") # compute name using partner_firstname method - post["name"] = http.request.env['res.partner']._get_computed_name(lastname, firstname) + post["name"] = http.request.env["res.partner"]._get_computed_name( + lastname, firstname + ) # update request params because super() uses this instead of kwargs http.request.params.update(post) return super().web_auth_signup(**post) diff --git a/views/auth_signup_login_templates.xml b/views/auth_signup_login_templates.xml index cd6dbf638ae05f8fb5df64f9b601b120d5b6b9c7..de6c7e028651d75e31a8b9346cdc1752188a1b8b 100644 --- a/views/auth_signup_login_templates.xml +++ b/views/auth_signup_login_templates.xml @@ -4,23 +4,33 @@ <odoo> <!-- high priority because replacing name field --> - <template id="auth_signup_fields_inherit" inherit_id="auth_signup.fields" priority="200"> + <template + id="auth_signup_fields_inherit" + inherit_id="auth_signup.fields" + priority="200" + > <!-- email field --> <!-- div with correct error class --> <xpath expr="//input[@id='login']/.." position="attributes"> - <attribute name="t-attf-class">mb-3 field-login {{'o_has_error' if error_email else ''}}</attribute> + <attribute + name="t-attf-class" + >mb-3 field-login {{'o_has_error' if error_email else ''}}</attribute> </xpath> <!-- input with correct type and error class--> <xpath expr="//input[@id='login']" position="attributes"> <attribute name="type">email</attribute> <attribute name="name">email</attribute> <attribute name="t-att-value">email</attribute> - <attribute name="t-attf-class">form-control {{'is-invalid' if error_email else ''}}</attribute> + <attribute + name="t-attf-class" + >form-control {{'is-invalid' if error_email else ''}}</attribute> <!-- regexp prise sur https://developer.mozilla.org/fr/docs/Web/HTML/Element/input/email#validation_simple --> <!-- mais avec un '+' plutôt qu'un '*' à la fin, comme demandé par solagro --> <!-- et échappée correctement --> - <attribute name="pattern">^[a-zA-Z0-9.!#$%&'*+\/=?^_`\{\|\}~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)+$</attribute> + <attribute + name="pattern" + >^[a-zA-Z0-9.!#$%&'*+\/=?^_`\{\|\}~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)+$</attribute> </xpath> @@ -28,16 +38,29 @@ <xpath expr="//input[@name='name']/.." position="replace"> <div class="mb-3 field-firstname"> <label for="name">Firstname</label> - <input type="text" name="firstname" t-att-value="firstname" id="firstname" - class="form-control" placeholder="i.e. John" - required="required" t-att-readonly="'readonly' if only_passwords else None" + <input + type="text" + name="firstname" + t-att-value="firstname" + id="firstname" + class="form-control" + placeholder="i.e. John" + required="required" + t-att-readonly="'readonly' if only_passwords else None" /> </div> <div class="mb-3 field-lastname"> <label for="name">Lastname</label> - <input type="text" name="lastname" t-att-value="lastname" id="lastname" - class="form-control" placeholder="i.e. Doe" - required="required" t-att-readonly="'readonly' if only_passwords else None"/> + <input + type="text" + name="lastname" + t-att-value="lastname" + id="lastname" + class="form-control" + placeholder="i.e. Doe" + required="required" + t-att-readonly="'readonly' if only_passwords else None" + /> </div> </xpath> </template>