summaryrefslogtreecommitdiff
path: root/lisp/sql/user.lisp
blob: a181ff469af099da37064d6c5b625a2493c42d2c (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
41
42
43
44
45
46
47
48
49
50
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))

(in-package :woodriverlessons)

(defclass user (org-ckons-session::session-object postgres-record)
  ((id :initarg :id
       :initform nil
       :accessor id)
   (username :initarg :username
             :initform nil
             :accessor username)
   (pwd :initarg :pwd
        :initform nil
        :accessor pwd)
   (first_name :initarg :first_name
               :initform nil
               :accessor first_name)
   (last_name :initarg :last_name
              :initform nil
              :accessor last_name)
   (email :initarg :email
          :initform nil
          :accessor email)
   (phone :initarg :phone
          :initform nil
          :accessor phone)
   (active :initarg :active
           :initform nil
           :accessor active)
   (created :initarg :created
            :initform nil)
   (*table :initform "auth.users")
   (*where-expression :initform "id = ~a")
   (org-ckons-session::*session-key :initform "user"))
  (:documentation "Holds the data for a user record."))

(defmethod created ((user user))
  (slot-value user 'created))

(defmethod (setf created) (value (user user))
  (handler-case
      (setf (slot-value user 'created) (simple-date-to-date value))
    (error (e)
      (declare (ignore e))
      (setf (slot-value user 'created) nil))))

(defmethod sanitize-json ((user user))
  (setf (pwd user) nil)
  (call-next-method))