How to I change the redirect link of the website login button via developer mode? For example, the default is link to Home after a successful login and I want to redirect to About or another page instead. I'm using Odoo12.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
With Developer mode activated. go to the user settings > Preferences Tab and look for a fields called Home Action, select the view you wish to see on login.
What if I want to see the apps switcher after login (not the website)?
Hi Khoa Doan,
Yes you can do this. I have done this in past. Just go to web/controllers/main.py and find "class Home(http.Controller)" in that there is one route method which validate login and redirect to Home. So what you have to do is, you have to inherit this controller in your custom module and override this route method called:
@http.route('/web/login', type='http', auth="none", sitemap=False)
def web_login(self, redirect=None, **kw):
So copy that function to your custom module controller and do as following code.
@http.route('/web/login', type='http', auth="none", sitemap=False)
def web_login(self, redirect=None, **kw):
ensure_db()
request.params['login_success'] = False
if request.httprequest.method == 'GET' and redirect and request.session.uid:
return http.redirect_with_hash(redirect)
if not request.uid:
request.uid = odoo.SUPERUSER_ID
values = request.params.copy()
try:
values['databases'] = http.db_list()
except odoo.exceptions.AccessDenied:
values['databases'] = None
if request.httprequest.method == 'POST':
old_uid = request.uid
try:
uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
request.params['login_success'] = True
# You can redirect to any view from here
url = '/web#id={0}&view_type={1}&model={2}'.format(1, 'form', 'res.partner')
return werkzeug.utils.redirect(url)
# return http.redirect_with_hash(self._login_redirect(uid, redirect=redirect))
except odoo.exceptions.AccessDenied as e:
request.uid = old_uid
if e.args == odoo.exceptions.AccessDenied().args:
values['error'] = _("Wrong login/password")
else:
values['error'] = e.args[0]
else:
if 'error' in request.params and request.params.get('error') == 'access':
values['error'] = _('Only employee can access this database. Please contact the administrator.')
if 'login' not in values and request.session.get('auth_login'):
values['login'] = request.session.get('auth_login')
if not odoo.tools.config['list_db']:
values['disable_database_manager'] = True
# otherwise no real way to test debug mode in template as ?debug =>
# values['debug'] = '' but that's also the fallback value when
# missing variables in qweb
if 'debug' in values:
values['debug'] = True
response = request.render('web.login', values)
response.headers['X-Frame-Options'] = 'DENY'
return response
In above code, in try block, I have just commented return line of base and prepared my own view to redirect and just return url Like: return werkzeug.utils.redirect(url)
I Hope it will helpful for you and also you know how to inherit controller in custom module and override route method.
Thanks and regards
Haresh Kansara
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Aug 19
|
3440 | ||
|
3
Jun 20
|
9926 | ||
|
0
Jul 19
|
8436 | ||
|
0
Jul 19
|
4 | ||
|
1
Oct 24
|
3923 |