summaryrefslogtreecommitdiff
path: root/session.lisp
blob: 6d36bec895c16c075166158b92a534cf61f00304 (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
34
35
36
37
38
39
40
;;;; 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")

(defparameter +playlist-connection-key+ "playlist-connection-key"
  "Stored in the clog connection object")

;;; 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))))

(defun cur-playlist-ctl (obj)
  (connection-data-item obj +playlist-connection-key+))

(defun (setf cur-playlist-ctl) (newval obj)
  (setf (connection-data-item obj +playlist-connection-key+) newval))