Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions website_event_private/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@ def event_register(self, event, **post):
# Business method
# ------------------------------------------------------
def _check_privacy(self, event, **post):
# for private events, check authorization
if event.event_privacy != "public" and not request.env.user.has_group(
"website.group_website_restricted_editor"
):
# get cookie from http request
cookie = request.httprequest.cookies.get("odoo-event-%d" % event.id)
if (
post
and post.get("access_token")
and post.get("access_token") == event.access_token
):
access_token = post.get("access_token")
request.future_response.set_cookie(
key="odoo-event-%d" % event.id,
value=access_token,
max_age=10 * 86400,
secure=True,
httponly=True,
samesite="Strict",
)
return True
elif cookie and cookie == event.access_token:
# check if cookie match access token
if cookie and cookie == event.access_token:
return True
else:
return False
# if cookie does not match, get the cookie from url
if post and post.get("access_token"):
access_token = post.get("access_token")
# if the cookie is correct, set the cookie accordingly and succeed
if access_token == event.access_token:
request.future_response.set_cookie(
key="odoo-event-%d" % event.id,
value=access_token,
max_age=10 * 86400,
secure=True,
httponly=True,
samesite="Strict",
)
return True
# if cookie is incorrect, do not set the cookie and fail
else:
return False
# for public event or if user is authorized, allow access
return True