From 78b0522b2cebfec3b9509c2ac60176524919fee3 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@le-filament.com> Date: Tue, 25 Feb 2025 16:06:00 +0100 Subject: [PATCH] gestion du mail --- __init__.py | 1 + __manifest__.py | 4 +--- controllers/__init__.py | 1 + controllers/main.py | 22 ++++++++++++++++++++ static/src/js/signup.js | 30 --------------------------- views/auth_signup_login_templates.xml | 23 +++++++++++++------- 6 files changed, 40 insertions(+), 41 deletions(-) create mode 100644 controllers/__init__.py create mode 100644 controllers/main.py delete mode 100644 static/src/js/signup.js diff --git a/__init__.py b/__init__.py index e69de29..e046e49 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/__manifest__.py b/__manifest__.py index 43f9804..03b8cb5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -13,9 +13,7 @@ "assets": { "web._assets_primary_variables": [], "web._assets_frontend_helpers": [], - 'web.assets_frontend': [ - 'solagro_auth_signup/static/**/*', - ], + "web.assets_frontend": [], "web.assets_tests": [], "web.assets_qweb": [], }, diff --git a/controllers/__init__.py b/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/controllers/main.py b/controllers/main.py new file mode 100644 index 0000000..9a8c5ab --- /dev/null +++ b/controllers/main.py @@ -0,0 +1,22 @@ +from odoo import http, tools, _ +from odoo.addons.auth_signup.controllers.main import AuthSignupHome + + +class SolagroAuthSignupHome(AuthSignupHome): + @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 email and not tools.single_email_re.match(email): + 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') + post["name"] = firstname + " " + lastname + # update request params + http.request.params.update(post) + return super().web_auth_signup() diff --git a/static/src/js/signup.js b/static/src/js/signup.js deleted file mode 100644 index 1928ef9..0000000 --- a/static/src/js/signup.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @odoo-module */ - -import "web.dom_ready"; - -console.log("ready") - -// il semble que web.signup n'a pas été porté en OWL, donc j'utilise l'ancienne forme - -const signupForm = document.querySelector('.oe_signup_form'); -if (signupForm) { - const name = document.querySelector("input[name='name']"); - const firstname = document.querySelector("input[name='firstname']"); - const lastname = document.querySelector("input[name='lastname']"); - - let firstname_val = "" - let lastname_val = "" - - firstname.addEventListener("input", (e) => { - firstname_val = e.target.value - update_name() - }); - lastname.addEventListener("input", (e) => { - lastname_val = e.target.value - update_name() - }); - - function update_name() { - name.value = firstname_val + " " + lastname_val - } -} diff --git a/views/auth_signup_login_templates.xml b/views/auth_signup_login_templates.xml index 92ce845..c29b986 100644 --- a/views/auth_signup_login_templates.xml +++ b/views/auth_signup_login_templates.xml @@ -3,21 +3,29 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> - <template id="auth_signup_fields_inherit" inherit_id="auth_signup.fields"> - <!-- replaces name by firstname / lastname --> - <xpath expr="//div[@class='mb-3 field-name']/input" position="attributes"> - <attribute name="required">False</attribute> - <attribute name="t-att-readonly">True</attribute> + <!-- email field --> + <!-- div with correct error class --> + <xpath expr="//input[@id='login']/.." position="attributes"> + <attribute name="t-attf-class">mb-3 {{'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-attf-class">form-control {{'is-invalid' if error_email else ''}}</attribute> + </xpath> + - <xpath expr="//div[@class='mb-3 field-name']" position="after"> + <!-- replaces name by firstname / lastname --> + <xpath expr="//input[@name='name']/.." position="replace"> <div class="mb-3 field-firstname"> <label for="name">Prénom</label> <input type="text" name="firstname" t-att-value="firstname" id="firstname" class="form-control form-control-sm" placeholder="par ex. Julie" - required="required" t-att-readonly="'readonly' if only_passwords else None"/> + required="required" t-att-readonly="'readonly' if only_passwords else None" + /> </div> <div class="mb-3 field-lastname"> <label for="name">Nom</label> @@ -28,5 +36,4 @@ </xpath> </template> - </odoo> -- GitLab