Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
20780 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.ย. 25
2164
Login Website แก้ไขแล้ว
3
ต.ค. 25
149265
1
ก.ย. 25
1344
Can't delete website แก้ไขแล้ว
4
ก.ย. 25
6075
2
ส.ค. 25
1357