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

How to logout automatically when browser is closing.is there any options in odoo for this requirement?

Awatar
Odrzuć
Najlepsza odpowiedź

Hello, I will not post the easy sollution here but just an idea for solving.
As far as I know there is no config or switcher for this, so you need to implement this on your own. How?

Let's sum up what we know about session:

  1. Session in odoo is maintained (like almost in every online app) with session cookies
  2. Session cookies are specific - why?:
    1. by default if you will not set expiry date or "max_age" parameter while setting cookie it will exactly behave like you would like to exepct:
    2. whenever user closes the window/browser - cookie will be gone
  3. So the idea is to set the session cookie without this parameter or to change the cookies validity time. How? So lets check what's the cookie documentation says:
    1. Set the cookie "Max-Age" attribute.
      A positive value indicates when the cookie should expire relative to the current time. A value of 0 means the cookie should expire immediately. A negative value results in no "Max-Age" attribute in which case the cookie is removed when the browser is closed.
  4. So you need to set cookie without this parameter or even better with "-1" value - it will force the browser to delete the cookie immediately after it's closed - BINGO!

  5. So now what to do, and where to find it? I see you use Odoo 11
    You must inherit the "def get_response" method from Root(object) - link below
    github.com/odoo/odoo/blob/6a52d22c6f13dd8cd4a9e4b7cc424a1c47010f35/odoo/http.py#L1420
    1. Look at line 1427 - here you see setting the max_age parameter for session cookies
    2. Make your custom module inheriting the whole get_response (line 1392) and adjust line 1427 to your needs
    3. for example like this:

    4. if not explicit_session and hasattr(response, 'set_cookie'):
      response.set_cookie('session_id', httprequest.session.sid, max_age=-1, httponly=True)

So I do not exactly know what is your knowledge, but assume you have dived into odoo development so far. So, please, take it easy with small steps and you will achieve your goal.

Good luck!
Hope it will help you anything.



Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
paź 20
8959
1
mar 18
7869
1
mar 23
6830
1
kwi 22
3458
1
lis 22
3250