Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
5 Vastaukset
20369 Näkymät

Hello,

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

Avatar
Hylkää
Paras vastaus

Hello


if request.env.user == request.website.user_id:
Avatar
Hylkää
Tekijä

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

Paras vastaus

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
Hylkää
Paras vastaus

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

Avatar
Hylkää
Paras vastaus



Avatar
Hylkää
Tekijä Paras vastaus

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
Hylkää

A really bad idea to do it...

Tekijä

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

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
elok. 25
138
5
elok. 25
9889
2
heinäk. 25
1002
4
kesäk. 25
1133
1
kesäk. 25
1448