From fc447dfb58db8a4e806cd21065b75cd7308ce239 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 22 Jan 2018 18:30:09 +0100 Subject: [PATCH] [MIG][11] auth_signup_verify_email --- auth_signup_verify_email/README.rst | 18 +++++++------- auth_signup_verify_email/__init__.py | 3 +-- auth_signup_verify_email/__manifest__.py | 16 ++++++------- .../controllers/__init__.py | 3 +-- auth_signup_verify_email/controllers/main.py | 24 +++++++++++-------- auth_signup_verify_email/tests/__init__.py | 2 +- .../tests/test_verify_email.py | 15 ++++++------ auth_signup_verify_email/views/signup.xml | 6 ++--- 8 files changed, 42 insertions(+), 45 deletions(-) diff --git a/auth_signup_verify_email/README.rst b/auth_signup_verify_email/README.rst index 041de578ee..e7ebc18d56 100644 --- a/auth_signup_verify_email/README.rst +++ b/auth_signup_verify_email/README.rst @@ -6,16 +6,16 @@ Verify email at signup ====================== -This module extends the functionality of public sign up, and forces users to +This module extends the functionality of public sign up to force users to provide a valid email address. -To achieve this requirement, the user does not need to provide a password at -sign up, but when logging in later for the first time. +To achieve this, users are not required to provide a password at +sign up: they are asked for only at first login attempt. Installation ============ -* Install validate_email_ with ``pip install validate_email`` or equivalent. +* Install `validate_email `_ with ``pip install validate_email`` or equivalent. Configuration ============= @@ -24,8 +24,7 @@ To configure this module, you need to: * `Properly configure your outgoing email server(s) `_. -* Go to *Settings > General Settings* and enable *Allow - external users to sign up*. +* Go to *Settings > General Settings -> General settings*, search for the *Users* section and enable *Free sign up* in *Customer account*. Usage ===== @@ -37,7 +36,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/149/9.0 + :target: https://runbot.odoo-community.org/runbot/149/11.0 Known issues / Roadmap ====================== @@ -51,7 +50,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback. +help us smash it by providing detailed and welcomed feedback. Credits @@ -68,6 +67,7 @@ Contributors * Rafael Blasco * Jairo Llopis +* Simone Orsi Maintainer ---------- @@ -83,5 +83,3 @@ mission is to support the collaborative development of Odoo features and promote its widespread use. To contribute to this module, please visit https://odoo-community.org. - -.. _validate_email: https://pypi.python.org/pypi/validate_email diff --git a/auth_signup_verify_email/__init__.py b/auth_signup_verify_email/__init__.py index 35233d377a..54d1454ece 100644 --- a/auth_signup_verify_email/__init__.py +++ b/auth_signup_verify_email/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2015 Antiun Ingeniería, S.L. +# Copyright 2015 Antiun Ingeniería, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import controllers diff --git a/auth_signup_verify_email/__manifest__.py b/auth_signup_verify_email/__manifest__.py index 3908671e10..a965fefa4d 100644 --- a/auth_signup_verify_email/__manifest__.py +++ b/auth_signup_verify_email/__manifest__.py @@ -1,28 +1,26 @@ -# -*- coding: utf-8 -*- -# © 2015 Antiun Ingeniería, S.L. +# Copyright 2015 Antiun Ingeniería, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Verify email at signup", "summary": "Force uninvited users to use a good email for signup", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "category": "Authentication", - "website": "http://www.tecnativa.com", + "website": "https://github.com/OCA/server-auth", "author": "Antiun Ingeniería S.L., " "Tecnativa, " "Odoo Community Association (OCA)", "license": "AGPL-3", - "application": False, - 'installable': True, + "depends": [ + "auth_signup", + ], "external_dependencies": { "python": [ "lxml", "validate_email", ], }, - "depends": [ - "auth_signup", - ], "data": [ "views/signup.xml", ], + 'installable': True, } diff --git a/auth_signup_verify_email/controllers/__init__.py b/auth_signup_verify_email/controllers/__init__.py index d10129bede..437ebe48e0 100644 --- a/auth_signup_verify_email/controllers/__init__.py +++ b/auth_signup_verify_email/controllers/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2015 Antiun Ingeniería, S.L. +# Copyright 2015 Antiun Ingeniería, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import main diff --git a/auth_signup_verify_email/controllers/main.py b/auth_signup_verify_email/controllers/main.py index 0fb5e06638..38ad7e4742 100644 --- a/auth_signup_verify_email/controllers/main.py +++ b/auth_signup_verify_email/controllers/main.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- -# © 2015 Antiun Ingeniería, S.L. +# Copyright 2015 Antiun Ingeniería, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from odoo import _, http +from odoo.http import request from odoo.addons.auth_signup.controllers.main import AuthSignupHome _logger = logging.getLogger(__name__) @@ -15,11 +15,12 @@ class SignupVerifyEmail(AuthSignupHome): + @http.route() def web_auth_signup(self, *args, **kw): - if (http.request.params.get("login") and - not http.request.params.get("password")): - return self.passwordless_signup(http.request.params) + if (request.params.get("login") and + not request.params.get("password")): + return self.passwordless_signup(request.params) else: return super(SignupVerifyEmail, self).web_auth_signup(*args, **kw) @@ -29,17 +30,20 @@ def passwordless_signup(self, values): # Check good format of e-mail if not validate_email(values.get("login", "")): qcontext["error"] = _("That does not seem to be an email address.") - return http.request.render("auth_signup.signup", qcontext) + return request.render("auth_signup.signup", qcontext) elif not values.get("email"): values["email"] = values.get("login") + # preserve user lang + values['lang'] = request.lang + # Remove password values["password"] = "" - sudo_users = (http.request.env["res.users"] + sudo_users = (request.env["res.users"] .with_context(create_user=True).sudo()) try: - with http.request.cr.savepoint(): + with request.cr.savepoint(): sudo_users.signup(values, qcontext.get("token")) sudo_users.reset_password(values.get("login")) except Exception as error: @@ -49,7 +53,7 @@ def passwordless_signup(self, values): # Agnostic message for security qcontext["error"] = _( "Something went wrong, please try again later or contact us.") - return http.request.render("auth_signup.signup", qcontext) + return request.render("auth_signup.signup", qcontext) qcontext["message"] = _("Check your email to activate your account!") - return http.request.render("auth_signup.reset_password", qcontext) + return request.render("auth_signup.reset_password", qcontext) diff --git a/auth_signup_verify_email/tests/__init__.py b/auth_signup_verify_email/tests/__init__.py index 8858be4966..bed770df15 100644 --- a/auth_signup_verify_email/tests/__init__.py +++ b/auth_signup_verify_email/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Jairo Llopis +# Copyright 2016 Jairo Llopis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import test_verify_email diff --git a/auth_signup_verify_email/tests/test_verify_email.py b/auth_signup_verify_email/tests/test_verify_email.py index a3649cd7de..244535f321 100644 --- a/auth_signup_verify_email/tests/test_verify_email.py +++ b/auth_signup_verify_email/tests/test_verify_email.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- -# © 2016 Jairo Llopis +# Copyright 2016 Jairo Llopis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from urllib import urlencode from lxml.html import document_fromstring -from openerp import _ -from openerp.tests.common import HttpCase +from odoo import _ +from odoo.tests.common import HttpCase +from odoo.tools.misc import mute_logger class UICase(HttpCase): @@ -39,9 +38,8 @@ def tearDown(self): def html_doc(self, url="/web/signup", data=None, timeout=10): """Get an HTML LXML document.""" - if data: - data = bytes(urlencode(data)) - return document_fromstring(self.url_open(url, data, timeout).read()) + resp = self.url_open(url, data=data, timeout=timeout) + return document_fromstring(resp.content) def csrf_token(self): """Get a valid CSRF token.""" @@ -58,6 +56,7 @@ def test_bad_email(self): doc = self.html_doc(data=self.data) self.assertTrue(self.search_text(doc, self.msg["badmail"])) + @mute_logger('odoo.addons.auth_signup_verify_email.controllers.main') def test_good_email(self): """Test acceptance of good emails. diff --git a/auth_signup_verify_email/views/signup.xml b/auth_signup_verify_email/views/signup.xml index cc81fcccf2..0a55571a4b 100644 --- a/auth_signup_verify_email/views/signup.xml +++ b/auth_signup_verify_email/views/signup.xml @@ -1,14 +1,14 @@ -