-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from corenting/fix/cookie-expiry
fix(cookies): set expiry (fix #143)
- Loading branch information
Showing
11 changed files
with
186 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from dataclasses import dataclass | ||
from datetime import UTC, datetime, timedelta | ||
|
||
from eddrit.config import DEBUG | ||
|
||
|
||
@dataclass | ||
class CookieSettings: | ||
secure: bool | ||
http_only: bool | ||
expiration_date: datetime | ||
|
||
|
||
def get_default_cookie_settings() -> CookieSettings: | ||
""" | ||
Get default cookie settings | ||
""" | ||
return CookieSettings( | ||
secure=not DEBUG, | ||
http_only=True, | ||
expiration_date=datetime.now(tz=UTC) + timedelta(days=90), | ||
) | ||
|
||
|
||
def get_bool_setting_value_from_cookie( | ||
name: str, cookies: dict[str, str], default: bool = False | ||
) -> bool: | ||
"""Get boolean value of a given setting according to the given cookies. | ||
If setting not present, use default value | ||
""" | ||
if name in cookies: | ||
return cookies[name] == "1" | ||
else: | ||
return default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.