This question has been flagged

I need to redirect the users to custom website login page when anyone tries to access a route with  auth="user". By default Odoo redirects to Odoo back-end login page. I tried the following code, by overriding  _handle_exception(self, exception) in HttpRequest. But still it doesn't work,

from odoo.http import HttpRequest
class WebsiteRequest(HttpRequest):

def _handle_exception(self, exception):
"""Called within an except block to allow converting exceptions
to abitrary responses. Anything returned (except None) will
be used as response."""
try:
return super(WebsiteRequest, self)._handle_exception(exception)
except SessionExpiredException:
redirect = None
req = request.httprequest
if req.method == 'POST':
request.session.save_request_data()
redirect = '/web/proxy/post{r.full_path}'.format(r=req)
elif not request.params.get('noredirect'):
redirect = req.url
if redirect:
query = urls.url_encode({
'redirect': redirect,
})
if 'web' in redirect:
return utils.redirect('/web/login?%s' % query)
else:
return utils.redirect('/login?%s' % query)
except werkzeug.exceptions.HTTPException as e:
return e



Can someone please provide a solution for this? Thanks
Avatar
Discard