跳至内容
菜单
此问题已终结
2 回复
45004 查看

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.

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
8月 19
4277
3
6月 20
11259
0
7月 19
9557
0
7月 19
5
1
10月 24
4861