Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
20363 Lượt xem

Hello,

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello


if request.env.user == request.website.user_id:
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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', {})
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ

A really bad idea to do it...

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
118
5
thg 8 25
9885
2
thg 7 25
1001
4
thg 6 25
1131
1
thg 6 25
1448