Public archive for the Return to Ritherdon project.
https://www.nicolaellisandritherdon.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
2 years ago
|
(in-package #:cl-user)
|
||
|
(defpackage #:nera-db
|
||
|
(:nicknames #:nera)
|
||
|
(:use #:cl
|
||
|
#:app-constants
|
||
|
#:hermetic
|
||
|
#:ritherdon-archive.db
|
||
|
#:utils
|
||
|
#:user)
|
||
|
(:export #:init-db
|
||
|
#:update-user
|
||
|
#:get-user
|
||
|
#:get-user-id))
|
||
|
(in-package #:nera-db)
|
||
|
|
||
|
(defun init-db (request)
|
||
|
"Creates the database and creates Admin. in `USER' table."
|
||
|
(destructuring-bind
|
||
|
(&key username display-name password &allow-other-keys)
|
||
|
(utils:request-params request)
|
||
|
(with-connection (db)
|
||
|
;; Add to the list to add more tables.
|
||
|
(mapcar #'mito:ensure-table-exists '(user))
|
||
|
(mito:create-dao 'user
|
||
|
:username username
|
||
|
:display-name display-name
|
||
|
:password (hermetic::hash password)
|
||
|
:administrator +true+))))
|
||
|
|
||
|
(defun update-user (username &optional display-name new-password)
|
||
|
"Updates `USER' in database."
|
||
|
(with-connection (db)
|
||
|
(let ((user-to-update
|
||
|
(mito:find-dao 'user:user :username username)))
|
||
|
(if (not (utils:string-is-nil-or-empty? display-name))
|
||
|
(setf (user::display-name-of user-to-update) display-name))
|
||
|
(if (not (utils:string-is-nil-or-empty? new-password))
|
||
|
(setf (user::password-of user-to-update) (hermetic::hash new-password)))
|
||
|
(mito:save-dao user-to-update))))
|
||
|
|
||
|
(defun get-user-id (username)
|
||
|
"Returns the Id. number of the specified `USERNAME' in the database."
|
||
|
(with-connection (db)
|
||
|
(mito:object-id
|
||
|
(mito:find-dao 'user :username username))))
|
||
|
|
||
|
(defun get-user (username)
|
||
|
"Returns a `USER' profile from the database."
|
||
|
(with-connection (db)
|
||
|
(mito:find-dao 'user :username username)))
|