diff --git a/website_sale_require_login/README.rst b/website_sale_require_login/README.rst new file mode 100644 index 0000000000..65914b7288 --- /dev/null +++ b/website_sale_require_login/README.rst @@ -0,0 +1,108 @@ +========================= +Require login to checkout +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f4aa5874b86951a397f97b64909f0f3ba4ccac0e7fafc10caeb6f9c70ffcfb90 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/17.0/website_sale_require_login + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-17-0/e-commerce-17-0-website_sale_require_login + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of eCommerce to force users to +login before buying anything in the website and allow you to get rid of +those duplicated entries of returning unauthenticated users. + +If you do not allow external users to sign up, this can serve you to +make checkout available only for those that have a user account, and +make some sort of *members club*. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +You probably want to enable any user to sign up: + +- Go to *Settings > General Settings > Website > Customer Account*. +- Enable *Free sign up*. + +Usage +===== + +To use this module, you need to: + +- Log out. +- Try to buy something. +- You will be forced to log in. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa +* LasLabs + +Contributors +------------ + +- Dave Lasley +- Oscar Alcala +- Lorenzo Battistini +- Foram Shah +- `Tecnativa `__: + + - Rafael Blasco + - Jairo Llopis + - Alexandre Diaz + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_require_login/__init__.py b/website_sale_require_login/__init__.py new file mode 100644 index 0000000000..46da3336bf --- /dev/null +++ b/website_sale_require_login/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2015 Antiun Ingeniería, S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import controllers +from .hooks import post_init_hook diff --git a/website_sale_require_login/__manifest__.py b/website_sale_require_login/__manifest__.py new file mode 100644 index 0000000000..cc4f500364 --- /dev/null +++ b/website_sale_require_login/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2015 Antiun Ingeniería, S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Require login to checkout", + "summary": "Force users to login for buying", + "version": "17.0.1.0.0", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "Tecnativa, " "LasLabs, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["website_sale_suggest_create_account", "web_tour"], + "data": ["views/website_sale.xml"], + "assets": { + "web.assets_tests": [ + "website_sale_require_login/static/tests/tours/checkout.esm.js", + ], + }, + "post_init_hook": "post_init_hook", +} diff --git a/website_sale_require_login/controllers/__init__.py b/website_sale_require_login/controllers/__init__.py new file mode 100644 index 0000000000..dd3803df93 --- /dev/null +++ b/website_sale_require_login/controllers/__init__.py @@ -0,0 +1,4 @@ +# © 2015 Antiun Ingeniería, S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import main diff --git a/website_sale_require_login/controllers/main.py b/website_sale_require_login/controllers/main.py new file mode 100644 index 0000000000..f35cd52cfb --- /dev/null +++ b/website_sale_require_login/controllers/main.py @@ -0,0 +1,16 @@ +# Copyright 2015 Antiun Ingeniería, S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import http + +from odoo.addons.website_sale.controllers.main import WebsiteSale + + +class RequireLoginToCheckout(WebsiteSale): + @http.route(auth="user") + def checkout(self, **post): + return super().checkout(**post) + + @http.route(auth="user") + def address(self, **post): + return super().address(**post) diff --git a/website_sale_require_login/hooks.py b/website_sale_require_login/hooks.py new file mode 100644 index 0000000000..b1362b5b85 --- /dev/null +++ b/website_sale_require_login/hooks.py @@ -0,0 +1,8 @@ +# Copyright (C) 2020 Alexandre Díaz - Tecnativa S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tools import config + + +def post_init_hook(env): + if config["test_enable"] or config["test_file"]: + env.ref("website_sale_require_login.cart").active = False diff --git a/website_sale_require_login/i18n/de.po b/website_sale_require_login/i18n/de.po new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_require_login/i18n/it.po b/website_sale_require_login/i18n/it.po new file mode 100644 index 0000000000..bdd71bc34e --- /dev/null +++ b/website_sale_require_login/i18n/it.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_require_login +# +# Translators: +# Paolo Valier, 2016 +msgid "" +msgstr "" +"Project-Id-Version: e-commerce (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-05-06 13:06+0000\n" +"PO-Revision-Date: 2016-05-01 08:33+0000\n" +"Last-Translator: Paolo Valier\n" +"Language-Team: Italian (http://www.transifex.com/oca/OCA-e-commerce-8-0/" +"language/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#~ msgid "" +#~ "(\n" +#~ " user_id != website.user_id and\n" +#~ " not optional_products and\n" +#~ " website_sale_order and\n" +#~ " website_sale_order.website_order_line\n" +#~ " )" +#~ msgstr "" +#~ "(\n" +#~ "user_id != website.user_id and\n" +#~ "not optional_products and\n" +#~ "website_sale_order and\n" +#~ "website_sale_order.website_order_line\n" +#~ ")" diff --git a/website_sale_require_login/i18n/sl.po b/website_sale_require_login/i18n/sl.po new file mode 100644 index 0000000000..585ca26a15 --- /dev/null +++ b/website_sale_require_login/i18n/sl.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_require_login +# +# Translators: +# Matjaž Mozetič , 2016 +msgid "" +msgstr "" +"Project-Id-Version: e-commerce (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-29 10:29+0000\n" +"PO-Revision-Date: 2016-04-01 04:55+0000\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-e-commerce-8-0/" +"language/sl/)\n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\n" + +#~ msgid "" +#~ "(\n" +#~ " user_id != website.user_id and\n" +#~ " not optional_products and\n" +#~ " website_sale_order and\n" +#~ " website_sale_order.website_order_line\n" +#~ " )" +#~ msgstr "" +#~ "(\n" +#~ " user_id != website.user_id and\n" +#~ " not optional_products and\n" +#~ " website_sale_order and\n" +#~ " website_sale_order.website_order_line\n" +#~ " )" diff --git a/website_sale_require_login/i18n/website_sale_require_login.pot b/website_sale_require_login/i18n/website_sale_require_login.pot new file mode 100644 index 0000000000..4d8b20f912 --- /dev/null +++ b/website_sale_require_login/i18n/website_sale_require_login.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/website_sale_require_login/pyproject.toml b/website_sale_require_login/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_require_login/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_require_login/readme/CONFIGURE.md b/website_sale_require_login/readme/CONFIGURE.md new file mode 100644 index 0000000000..510c027b4b --- /dev/null +++ b/website_sale_require_login/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +You probably want to enable any user to sign up: + +- Go to *Settings \> General Settings \> Website \> Customer Account*. +- Enable *Free sign up*. diff --git a/website_sale_require_login/readme/CONTRIBUTORS.md b/website_sale_require_login/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..cb0ec4707a --- /dev/null +++ b/website_sale_require_login/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- Dave Lasley \<\> +- Oscar Alcala \<\> +- Lorenzo Battistini \<\> +- Foram Shah \<\> +- [Tecnativa](https://www.tecnativa.com): + - Rafael Blasco + - Jairo Llopis + - Alexandre Diaz diff --git a/website_sale_require_login/readme/DESCRIPTION.md b/website_sale_require_login/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f42cf9dbb5 --- /dev/null +++ b/website_sale_require_login/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module extends the functionality of eCommerce to force users to +login before buying anything in the website and allow you to get rid of +those duplicated entries of returning unauthenticated users. + +If you do not allow external users to sign up, this can serve you to +make checkout available only for those that have a user account, and +make some sort of *members club*. diff --git a/website_sale_require_login/readme/USAGE.md b/website_sale_require_login/readme/USAGE.md new file mode 100644 index 0000000000..df7c4d1ca4 --- /dev/null +++ b/website_sale_require_login/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +- Log out. +- Try to buy something. +- You will be forced to log in. diff --git a/website_sale_require_login/static/description/icon.png b/website_sale_require_login/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_require_login/static/description/icon.png differ diff --git a/website_sale_require_login/static/description/index.html b/website_sale_require_login/static/description/index.html new file mode 100644 index 0000000000..3cd34a61a4 --- /dev/null +++ b/website_sale_require_login/static/description/index.html @@ -0,0 +1,457 @@ + + + + + +Require login to checkout + + + +
+

Require login to checkout

+ + +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

This module extends the functionality of eCommerce to force users to +login before buying anything in the website and allow you to get rid of +those duplicated entries of returning unauthenticated users.

+

If you do not allow external users to sign up, this can serve you to +make checkout available only for those that have a user account, and +make some sort of members club.

+

Table of contents

+ +
+

Configuration

+

You probably want to enable any user to sign up:

+
    +
  • Go to Settings > General Settings > Website > Customer Account.
  • +
  • Enable Free sign up.
  • +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  • Log out.
  • +
  • Try to buy something.
  • +
  • You will be forced to log in.
  • +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
  • LasLabs
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/e-commerce project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_sale_require_login/static/tests/tours/checkout.esm.js b/website_sale_require_login/static/tests/tours/checkout.esm.js new file mode 100644 index 0000000000..96f9504234 --- /dev/null +++ b/website_sale_require_login/static/tests/tours/checkout.esm.js @@ -0,0 +1,34 @@ +/** @odoo-module */ + +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("shop_buy_checkout_required_login_website", { + test: true, + url: "/shop", + steps: () => [ + // Shop Page + { + trigger: "td.oe_product a:first", + }, + // Product Page + { + trigger: "#add_to_cart", + }, + { + trigger: 'a.o_navlink_background.btn[href="/shop/cart"]', + }, + { + trigger: '.oe_website_sale:not(a.btn-primary[href^="/shop/checkout"])', + run: function () { + // Check: do nothing + }, + }, + { + trigger: '.oe_website_sale:not(a.btn-default[href^="/shop/checkout"])', + run: function () { + // Check: do nothing + }, + }, + // The End + ], +}); diff --git a/website_sale_require_login/tests/__init__.py b/website_sale_require_login/tests/__init__.py new file mode 100644 index 0000000000..92fd741d86 --- /dev/null +++ b/website_sale_require_login/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_checkout +from . import test_website_sale_require_login diff --git a/website_sale_require_login/tests/test_checkout.py b/website_sale_require_login/tests/test_checkout.py new file mode 100644 index 0000000000..d18c953450 --- /dev/null +++ b/website_sale_require_login/tests/test_checkout.py @@ -0,0 +1,12 @@ +# Copyright (C) 2020 Alexandre Díaz - Tecnativa S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +import odoo.tests + + +@odoo.tests.tagged("post_install", "-at_install") +class TestUi(odoo.tests.HttpCase): + def test_01_shop_buy(self): + current_website = self.env["website"].get_current_website() + current_website.auth_signup_uninvited = "b2b" + self.env.ref("website_sale_require_login.cart").active = True + self.start_tour("/shop", "shop_buy_checkout_required_login_website") diff --git a/website_sale_require_login/tests/test_website_sale_require_login.py b/website_sale_require_login/tests/test_website_sale_require_login.py new file mode 100644 index 0000000000..393e0402b1 --- /dev/null +++ b/website_sale_require_login/tests/test_website_sale_require_login.py @@ -0,0 +1,57 @@ +from urllib.parse import urlparse + +from odoo.tests.common import HttpCase + + +class TestWebsiteSaleRequireLogin(HttpCase): + def setUp(self): + super().setUp() + self.guest_user = self.env.ref("base.public_user") + self.logged_in_user = self.env["res.users"].create( + { + "name": "Test User", + "login": "testuser@example.com", + "email": "testuser@example.com", + "password": "password", + } + ) + + def test_guest_checkout_redirection(self): + """Test if guest user is redirected to login when accessing checkout.""" + response = self.url_open("/shop/checkout") + redirect_url = urlparse(response.url).path + self.assertEqual( + redirect_url, + "/web/login", + "Guest should be redirected to login when accessing checkout.", + ) + + def test_logged_in_checkout_access(self): + """Test if logged-in user is not redirected when accessing checkout.""" + self.authenticate(self.logged_in_user.login, "password") + response = self.url_open("/shop/checkout") + self.assertNotEqual( + response.url, + "/web/login", + "Logged-in user should not be redirected when accessing checkout.", + ) + + def test_guest_address_redirection(self): + """Test if guest user is redirected to login when accessing address.""" + response = self.url_open("/shop/address") + redirect_url = urlparse(response.url).path + self.assertEqual( + redirect_url, + "/web/login", + "Guest should be redirected to login when accessing address.", + ) + + def test_logged_in_address_access(self): + """Test if logged-in user is not redirected when accessing address.""" + self.authenticate(self.logged_in_user.login, "password") + response = self.url_open("/shop/address") + self.assertNotEqual( + response.url, + "/web/login", + "Logged-in user should not be redirected when accessing address.", + ) diff --git a/website_sale_require_login/views/website_sale.xml b/website_sale_require_login/views/website_sale.xml new file mode 100644 index 0000000000..f5792a595d --- /dev/null +++ b/website_sale_require_login/views/website_sale.xml @@ -0,0 +1,18 @@ + + + + +