Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
5 Odgovori
20390 Prikazi

Hello,

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

Avatar
Opusti
Best Answer

Hello


if request.env.user == request.website.user_id:
Avatar
Opusti
Avtor

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

Best Answer

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', {})
Avatar
Opusti
Best Answer

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

Avatar
Opusti
Best Answer



Avatar
Opusti
Avtor Best Answer

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


Avatar
Opusti

A really bad idea to do it...

Avtor

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 Odgovori Prikazi Aktivnost
2
avg. 25
407
5
avg. 25
9965
2
jul. 25
1023
4
jun. 25
1162
1
jun. 25
1475