Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
20358 Widoki

Hello,

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

Awatar
Odrzuć
Najlepsza odpowiedź

Hello


if request.env.user == request.website.user_id:
Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

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', {})
Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź



Awatar
Odrzuć
Autor Najlepsza odpowiedź

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


Awatar
Odrzuć

A really bad idea to do it...

Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
86
5
sie 25
9883
2
lip 25
1001
4
cze 25
1130
1
cze 25
1445