|
| 1 | +# Copyright 2024 Quartile Limited (https://www.quartile.co) |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
| 3 | + |
| 4 | + |
| 5 | +from odoo import _, http |
| 6 | +from odoo.http import request |
| 7 | + |
| 8 | +from odoo.addons.auth_signup.controllers import main |
| 9 | +from odoo.addons.web.controllers import home |
| 10 | + |
| 11 | + |
| 12 | +class Home(home.Home): |
| 13 | + @http.route("/web/login", type="http", auth="none") |
| 14 | + def web_login(self, redirect=None, **kw): |
| 15 | + # Only proceed if it's a POST request and 'login' is provided |
| 16 | + if request.httprequest.method != "POST" or "login" not in kw: |
| 17 | + return super().web_login(redirect=redirect, **kw) |
| 18 | + login = kw["login"] |
| 19 | + user = request.env["res.users"].sudo().search([("login", "=", login)], limit=1) |
| 20 | + # Only proceed if 'force_oauth_domains' is set for the company |
| 21 | + if user._is_allowed_password_login(): |
| 22 | + return super().web_login(redirect=redirect, **kw) |
| 23 | + # User is not allowed to login with a password, prompt for OAuth login |
| 24 | + providers = self.list_providers() |
| 25 | + values = request.params |
| 26 | + values["error"] = _( |
| 27 | + "You are not allowed to login with password. Please use OAuth login." |
| 28 | + ) |
| 29 | + values["providers"] = providers |
| 30 | + return request.render("web.login", values) |
| 31 | + |
| 32 | + |
| 33 | +class CustomAuthSignup(main.AuthSignupHome): |
| 34 | + @http.route( |
| 35 | + "/web/reset_password", type="http", auth="public", website=True, sitemap=False |
| 36 | + ) |
| 37 | + def web_auth_reset_password(self, *args, **kw): |
| 38 | + qcontext = self.get_auth_signup_qcontext() |
| 39 | + login = qcontext.get("login", request.params.get("login")) |
| 40 | + password = qcontext.get("password") |
| 41 | + confirm_password = qcontext.get("confirm_password") |
| 42 | + if not login or not password or not confirm_password: |
| 43 | + return super().web_auth_reset_password(*args, **kw) |
| 44 | + user = request.env["res.users"].sudo().search([("login", "=", login)], limit=1) |
| 45 | + if user._is_allowed_password_login(): |
| 46 | + return super().web_auth_reset_password(*args, **kw) |
| 47 | + qcontext["error"] = _( |
| 48 | + "You are not allowed to login with password. Please use OAuth login." |
| 49 | + ) |
| 50 | + return request.render("auth_signup.reset_password", qcontext) |
0 commit comments