콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
20359 화면

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.

관련 게시물 답글 화면 활동
1
8월 25
90
5
8월 25
9884
2
7월 25
1001
4
6월 25
1130
1
6월 25
1445