summaryrefslogtreecommitdiff
path: root/service/auth-service.lisp
blob: 6cbc134cc45e3637662c8b65bb70a169274f049e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))

(in-package #:music-dispensary)

;; ========================================================================== ;;

(defclass auth-service (rest-service)
  ()
  (:documentation ""))

(defmethod initialize-instance :after ((auth-service auth-service) &key)
  (when (not (string= (session-value :permissions) "admin"))
    (setf (location auth-service) "home")
    (setf (errormsg auth-service) "You are not authorized to access this resource.")))

(defmacro with-auth ((instance form-class) &body body)
  `(let ((,instance (make-instance ',form-class)))
     (when (null (errormsg ,instance))
       ,@body)
     (objects-to-json `(,,instance))))