Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
solagro_auth_signup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Le Filament
Solagro
solagro_auth_signup
Commits
9bd333ec
Commit
9bd333ec
authored
3 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
pre-commit
parent
74ab9bd6
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/main.py
+20
-10
20 additions, 10 deletions
controllers/main.py
views/auth_signup_login_templates.xml
+33
-10
33 additions, 10 deletions
views/auth_signup_login_templates.xml
with
53 additions
and
20 deletions
controllers/main.py
+
20
−
10
View file @
9bd333ec
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
)
This diff is collapsed.
Click to expand it.
views/auth_signup_login_templates.xml
+
33
−
10
View file @
9bd333ec
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment