Skip to content
Snippets Groups Projects
Commit 9bd333ec authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

pre-commit

parent 74ab9bd6
No related branches found
No related tags found
No related merge requests found
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)
......@@ -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.!#$%&amp;'*+\/=?^_`\{\|\}~\-]+@[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.!#$%&amp;'*+\/=?^_`\{\|\}~\-]+@[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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment