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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
Attachments in Website Chatter
Đã xử lý
|
|
1
thg 8 19
|
4299 | |
|
3
thg 6 20
|
11298 | ||
|
0
thg 7 19
|
9593 | ||
|
0
thg 7 19
|
5 | ||
|
1
thg 10 24
|
4891 |