コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
45047 ビュー

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
4305
3
6月 20
11301
0
7月 19
9598
0
7月 19
5
1
10月 24
4894