背景:由於需要集成odoo平台在其他頁面,需要繞開登陸。
解決辦法:開辟一個自動登陸的路由用與集成頁面。
1、修改web模塊中controller/main.py文件,在class名字為Home中添加登陸路由:
dbname:指定登陸數據庫名稱
username:用戶名
password:密碼
1 @http.route('/web/login_(自定義路由名稱)', type='http', auth="none") 2 def web_login_(方法名稱)(self, redirect=None, **kw): 3 if request.httprequest.method == 'GET': 4 old_uid = request.uid 5 uid = request.session.authenticate('dbname', 'username', 'password') 6 if uid is not False: 7 request.params['login_success'] = True 8 if not redirect: 9 redirect = '/web' 10 return http.redirect_with_hash(redirect) 11 request.uid = old_uid 12 values['error'] = _("Wrong login/password") 13 return request.render('web.login', values)
2、訪問路由(訪問前需要先調用清除cookie的方法)。在class名字為Session中添加頁面訪問路由的方法
@http.route('/web/(訪問路由名稱)', type='http', auth="none") def logout_login(self, redirect='/web'): request.session.logout(keep_db=True) return http.redirect_with_hash('/web/login_(自定義路由名稱)') #從定向到上面定義的路由名稱
3、重啟odoo、訪問第二步中的路由就能直接進入odoo