diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/auth_totp/controllers | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/auth_totp/controllers')
| -rw-r--r-- | addons/auth_totp/controllers/__init__.py | 2 | ||||
| -rw-r--r-- | addons/auth_totp/controllers/home.py | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/addons/auth_totp/controllers/__init__.py b/addons/auth_totp/controllers/__init__.py new file mode 100644 index 00000000..3f3f69c6 --- /dev/null +++ b/addons/auth_totp/controllers/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import home diff --git a/addons/auth_totp/controllers/home.py b/addons/auth_totp/controllers/home.py new file mode 100644 index 00000000..10c2461e --- /dev/null +++ b/addons/auth_totp/controllers/home.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +import re + +import odoo.addons.web.controllers.main +from odoo import http, _ +from odoo.exceptions import AccessDenied +from odoo.http import request + + +class Home(odoo.addons.web.controllers.main.Home): + @http.route( + '/web/login/totp', + type='http', auth='public', methods=['GET', 'POST'], sitemap=False, + website=True, # website breaks the login layout... + ) + def web_totp(self, redirect=None, **kwargs): + if request.session.uid: + return http.redirect_with_hash(self._login_redirect(request.session.uid, redirect=redirect)) + + if not request.session.pre_uid: + return http.redirect_with_hash('/web/login') + + error = None + if request.httprequest.method == 'POST': + user = request.env['res.users'].browse(request.session.pre_uid) + try: + with user._assert_can_auth(): + user._totp_check(int(re.sub(r'\s', '', kwargs['totp_token']))) + except AccessDenied: + error = _("Verification failed, please double-check the 6-digit code") + except ValueError: + error = _("Invalid authentication code format.") + else: + request.session.finalize() + return http.redirect_with_hash(self._login_redirect(request.session.uid, redirect=redirect)) + + return request.render('auth_totp.auth_totp_form', { + 'error': error, + 'redirect': redirect, + }) |
