summaryrefslogtreecommitdiff
path: root/session.lisp
blob: d7bd937d142fb186abeb45ba28777d4d02c280a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;; session.lisp

(in-package :vampire)

;;; SESSION CLASS 

(defclass/bknr session (keyed)
  ((user :std (error "Sessions must be associated with users."))))

(defun make-session (user)
  (with-transaction ()
    (make-instance 'session :user user)))

;;; SESSION PARAMETER KEYS

(defparameter +session-key+ "vampire-session-key"
  "Stored in the browser's local storage")


;;; SESSION ACCESSORS

(defun session-key (window)
  (jonathan:parse (storage-element window :local +session-key+)))

(defun (setf session-key) (val window)
  (setf (storage-element window :local +session-key+) (jonathan:to-json val)))

(defun session-user (clog-obj)
  (when-let (obj (object-with-key (session-key (window (connection-body clog-obj)))))
    (when (typep obj 'session)
      (user obj))))