Skip to content

Commit

Permalink
[IMP] auth_signup_verify_email: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 authored and pedrobaeza committed Jan 21, 2022
1 parent b7a44b7 commit d8cda28
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 55 deletions.
21 changes: 6 additions & 15 deletions auth_signup_verify_email/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
"category": "Authentication",
"website": "https://github.com/OCA/server-auth",
"author": "Antiun Ingeniería S.L., "
"Tecnativa, "
"Odoo Community Association (OCA)",
"Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"auth_signup",
],
"external_dependencies": {
"python": [
"lxml",
"email_validator",
],
},
"data": [
"views/signup.xml",
],
'installable': True,
"depends": ["auth_signup"],
"external_dependencies": {"python": ["lxml", "email_validator"]},
"data": ["views/signup.xml"],
"installable": True,
}
34 changes: 17 additions & 17 deletions auth_signup_verify_email/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from email_validator import validate_email, EmailSyntaxError, \
EmailUndeliverableError

from email_validator import EmailSyntaxError, EmailUndeliverableError, validate_email

from odoo import _
from odoo.http import request, route

from odoo.addons.auth_signup.controllers.main import AuthSignupHome

_logger = logging.getLogger(__name__)


class SignupVerifyEmail(AuthSignupHome):

@route()
def web_auth_signup(self, *args, **kw):
if (request.params.get("login") and not
request.params.get("password")):
if request.params.get("login") and not request.params.get("password"):
return self.passwordless_signup()
return super().web_auth_signup(*args, **kw)

Expand All @@ -29,9 +29,7 @@ def passwordless_signup(self):
validate_email(values.get("login", ""))
except EmailSyntaxError as error:
qcontext["error"] = getattr(
error,
"message",
_("That does not seem to be an email address."),
error, "message", _("That does not seem to be an email address."),
)
return request.render("auth_signup.signup", qcontext)
except EmailUndeliverableError as error:
Expand All @@ -44,12 +42,11 @@ def passwordless_signup(self):
values["email"] = values.get("login")

# preserve user lang
values['lang'] = request.lang
values["lang"] = request.lang

# Remove password
values["password"] = ""
sudo_users = (request.env["res.users"]
.with_context(create_user=True).sudo())
sudo_users = request.env["res.users"].with_context(create_user=True).sudo()

try:
with request.cr.savepoint():
Expand All @@ -58,16 +55,19 @@ def passwordless_signup(self):
except Exception as error:
# Duplicate key or wrong SMTP settings, probably
_logger.exception(error)
if request.env["res.users"].sudo().search(
[("login", "=", qcontext.get("login"))]):
if (
request.env["res.users"]
.sudo()
.search([("login", "=", qcontext.get("login"))])
):
qcontext["error"] = _(
"Another user is already registered using this email"
" address.")
"Another user is already registered using this email" " address."
)
else:
# Agnostic message for security
qcontext["error"] = _(
"Something went wrong, please try again later or"
" contact us.")
"Something went wrong, please try again later or" " contact us."
)
return request.render("auth_signup.signup", qcontext)

qcontext["message"] = _("Check your email to activate your account!")
Expand Down
14 changes: 7 additions & 7 deletions auth_signup_verify_email/tests/test_verify_email.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Copyright 2016 Jairo Llopis <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from mock import patch
from lxml.html import document_fromstring
from mock import patch

from odoo.tests.common import HttpCase
from odoo.addons.mail.models import mail_template
from odoo.tools.misc import mute_logger

from odoo.addons.mail.models import mail_template


class UICase(HttpCase):
def setUp(self):
super().setUp()
if "website" in self.env:
# Enable public signup in website if it is installed; otherwise
# tests here would fail
current_website = self.env['website'].get_current_website()
current_website = self.env["website"].get_current_website()
current_website.auth_signup_uninvited = "b2c"
self.env["ir.config_parameter"].set_param(
"auth_signup.invitation_scope", "b2c"
)
self.env["ir.config_parameter"].set_param("auth_signup.invitation_scope", "b2c")
self.data = {
"csrf_token": self.csrf_token(),
"name": "Somebody",
Expand All @@ -41,7 +41,7 @@ def test_bad_email(self):
doc = self.html_doc(data=self.data)
self.assertTrue(doc.xpath('//p[@class="alert alert-danger"]'))

@mute_logger('odoo.addons.auth_signup_verify_email.controllers.main')
@mute_logger("odoo.addons.auth_signup_verify_email.controllers.main")
def test_good_email(self):
"""Test acceptance of good emails."""
self.data["login"] = "[email protected]"
Expand Down
28 changes: 12 additions & 16 deletions auth_signup_verify_email/views/signup.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2016 Jairo Llopis <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<template id="signup_fields" inherit_id="auth_signup.fields">
<xpath expr="//div[hasclass('field-password')]"
position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
<xpath expr="//div[hasclass('field-confirm_password')]"
position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
<xpath expr="//input[@name='login']" position="attributes">
<attribute name="type">email</attribute>
</xpath>
</template>

<template id="signup_fields" inherit_id="auth_signup.fields">
<xpath expr="//div[hasclass('field-password')]" position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
<xpath expr="//div[hasclass('field-confirm_password')]" position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
<xpath expr="//input[@name='login']" position="attributes">
<attribute name="type">email</attribute>
</xpath>
</template>
</odoo>

0 comments on commit d8cda28

Please sign in to comment.