This branch adds request.redirect on all requests. In case of a front end request, we do an url_for to the location. We removed redirect_with_hash that was only for retro compatibility local_redirect has been renamed to redirect_query, and param keep_hash has been removed and moved. Default code for redirect is 303 now instead of 302. Now redirect and redirect_query make local redirect by default, you need to pass local=False to make external redirect. All werkeug.utils.redirect has been replaced by request.redirect. Http.redirect now use an http.Response type, and it become easy to add an override like 'set_cookies' e.g. Dispatch of a website.page return an http.response too, so we first need to check if it is a cached version before to check if it is an Odoo Response. Migrate your code: http.redirect -> request.redirect(location, code, local) http.local_redirect -> request.redirect_query(location, query, code, local) http.redirect_with_hash -> request.redirect Courtesy of odony for help and review ;) closes odoo/odoo#72599 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
# -*- 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 request.redirect(self._login_redirect(request.session.uid, redirect=redirect))
|
|
|
|
if not request.session.pre_uid:
|
|
return request.redirect('/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 request.redirect(self._login_redirect(request.session.uid, redirect=redirect))
|
|
|
|
return request.render('auth_totp.auth_totp_form', {
|
|
'error': error,
|
|
'redirect': redirect,
|
|
})
|