From 8760144735b4a4e7a3bfcf899ab516c0f61dfd42 Mon Sep 17 00:00:00 2001 From: ditaajipratama Date: Thu, 13 Jun 2024 12:43:46 +0700 Subject: [PATCH] Implement session with beaker --- .beaker/data/.noremove | 0 .gitignore | 5 +++++ config/server.py | 8 +++++++- costa.py | 5 ++++- install.sh | 7 ++++--- 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .beaker/data/.noremove diff --git a/.beaker/data/.noremove b/.beaker/data/.noremove new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index eeb8a6e..2b8380b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ **/__pycache__ +*.pyc +venv/ +env/ +.beaker/data/* +!.beaker/data/.noremove diff --git a/config/server.py b/config/server.py index 5830cfc..019e867 100644 --- a/config/server.py +++ b/config/server.py @@ -4,8 +4,14 @@ reloader = False debug = False server = 'gunicorn' # default = 'wsgiref' +session_opts = { + 'session.type': 'file', + 'session.cookie_expires': 5*60, # Session expiration in seconds: minutes*seconds + 'session.data_dir': './beaker/data', + 'session.auto': True +} + # cors -# session # error page 403 # error page 404 diff --git a/costa.py b/costa.py index 997b56a..8bc8677 100644 --- a/costa.py +++ b/costa.py @@ -6,7 +6,8 @@ # You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. import sys -from bottle import Bottle, run +from bottle import Bottle, run +from beaker.middleware import SessionMiddleware import handler @@ -18,6 +19,8 @@ app = Bottle() app.merge(handler.app) app.merge(staticdir.app) +app = SessionMiddleware(app, server.session_opts) + run(app, host = server.host, port = server.port, diff --git a/install.sh b/install.sh index 6604a9d..150b2d2 100644 --- a/install.sh +++ b/install.sh @@ -1,5 +1,6 @@ sudo apt-get install -y python3-pip pip install --upgrade pip -pip install bottle -pip install gunicorn -pip install mako +pip install bottle # Micro Framework +pip install gunicorn # WSGI Server Backend +pip install beaker # Session & caching library +pip install mako # Template library