跳至內容
選單
此問題已被標幟
5 回覆
20356 瀏覽次數

Hello,

How to test if the user is logged in in Odoo website ?

頭像
捨棄
最佳答案

Hello


if request.env.user == request.website.user_id:
頭像
捨棄
作者

Does this `request.website.user_id` returns the public user id ?

最佳答案

Safer to use the reference to the public user instead of hardcoding its id.

if request.env.user.id == request.env.ref('base.public_user').id:
return request.render('web.login', {})
頭像
捨棄
最佳答案

hi,
you can use request.session.uid or env.context.get('uid')

頭像
捨棄
最佳答案



頭像
捨棄
作者 最佳答案

Hello,

This could be done with this code snippet inside a web controller: (Tested on Odoo 8)

public_user = http.request.env['res.users'].sudo().search([('id', '=', 3),('active', '=', False)]) # Public user default ID
if request.uid == public_user.id:
     # The user is logged in
     # Put your code for logged in user here
else:
    # The user is not logged in
    # Put your code for public users here

Regards,

Slim BHIRI


頭像
捨棄

A really bad idea to do it...

作者

Could you provide more explanation why it is a good idea and clarify your response please ? Because I haden't understood your reponse.

相關帖文 回覆 瀏覽次數 活動
5
8月 25
9881
2
7月 25
999
4
6月 25
1130
1
6月 25
1444
1
5月 25
1355