mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 10:40:45 -08:00
Add type checking
This commit is contained in:
parent
6000290619
commit
3d8d7f7136
3 changed files with 28 additions and 20 deletions
|
|
@ -42,6 +42,7 @@ for CLOG")
|
||||||
|
|
||||||
(defun get-authentication-token (body &key auth-path)
|
(defun get-authentication-token (body &key auth-path)
|
||||||
"Retrieve the stored authentication token"
|
"Retrieve the stored authentication token"
|
||||||
|
(check-type body clog-body)
|
||||||
(let ((token (storage-element (window body) :local *clog-auth-key*)))
|
(let ((token (storage-element (window body) :local *clog-auth-key*)))
|
||||||
(when (equalp token "null")
|
(when (equalp token "null")
|
||||||
(setf token nil))
|
(setf token nil))
|
||||||
|
|
@ -55,6 +56,7 @@ for CLOG")
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun store-authentication-token (body token)
|
(defun store-authentication-token (body token)
|
||||||
|
(check-type body clog-body)
|
||||||
(setf (storage-element (window body) :local *clog-auth-key*) token))
|
(setf (storage-element (window body) :local *clog-auth-key*) token))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
@ -62,19 +64,20 @@ for CLOG")
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun remove-authentication-token (body)
|
(defun remove-authentication-token (body)
|
||||||
|
(check-type body clog-body)
|
||||||
(storage-remove (window body) :local *clog-auth-key*))
|
(storage-remove (window body) :local *clog-auth-key*))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; set-on-authentication-change ;;
|
;; set-on-authentication-change ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun set-on-authentication-change (obj handler)
|
(defun set-on-authentication-change (body handler)
|
||||||
(let ((body (connection-body obj)))
|
(check-type body clog-body)
|
||||||
(set-on-storage (window body) (lambda (obj data)
|
(set-on-storage (window body) (lambda (obj data)
|
||||||
(set-on-storage (window body) nil)
|
(set-on-storage (window body) nil)
|
||||||
(when (equalp (getf data :key)
|
(when (equalp (getf data :key)
|
||||||
"clog-auth-token")
|
"clog-auth-token")
|
||||||
(funcall handler body))))))
|
(funcall handler body)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Implementation - clog-auth - Authorization
|
;; Implementation - clog-auth - Authorization
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@
|
||||||
(defun get-profile (obj sql-connection)
|
(defun get-profile (obj sql-connection)
|
||||||
"Retrieve profile based on current authentication token. If there is
|
"Retrieve profile based on current authentication token. If there is
|
||||||
no token or fails to match as user returns nil"
|
no token or fails to match as user returns nil"
|
||||||
(let ((token (clog-auth:get-authentication-token obj)))
|
(let* ((body (connection-body obj))
|
||||||
|
(token (clog-auth:get-authentication-token body)))
|
||||||
(when token
|
(when token
|
||||||
(let ((contents (dbi:fetch-all
|
(let ((contents (dbi:fetch-all
|
||||||
(dbi:execute
|
(dbi:execute
|
||||||
|
|
@ -45,9 +46,10 @@ no token or fails to match as user returns nil"
|
||||||
;; login ;;
|
;; login ;;
|
||||||
;;;;;;;;;;;
|
;;;;;;;;;;;
|
||||||
|
|
||||||
(defun login (obj sql-connection username password)
|
(defun login (body sql-connection username password)
|
||||||
"Login and set current authentication token, it does not remove token
|
"Login and set current authentication token, it does not remove token
|
||||||
if one is present and login fails."
|
if one is present and login fails."
|
||||||
|
(check-type body clog-body)
|
||||||
(let ((contents (dbi:fetch-all
|
(let ((contents (dbi:fetch-all
|
||||||
(dbi:execute
|
(dbi:execute
|
||||||
(dbi:prepare
|
(dbi:prepare
|
||||||
|
|
@ -55,24 +57,26 @@ if one is present and login fails."
|
||||||
"select token from users where username=? and password=?")
|
"select token from users where username=? and password=?")
|
||||||
(list username password)))))
|
(list username password)))))
|
||||||
(when contents
|
(when contents
|
||||||
(store-authentication-token obj (getf (car contents) :|token|)))))
|
(store-authentication-token body (getf (car contents) :|token|)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;
|
;;;;;;;;;;;;
|
||||||
;; logout ;;
|
;; logout ;;
|
||||||
;;;;;;;;;;;;
|
;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun logout (obj)
|
(defun logout (body)
|
||||||
"Logout and remove current authenitcation token"
|
"Logout and remove current authenitcation token"
|
||||||
(remove-authentication-token obj))
|
(check-type body clog-body)
|
||||||
|
(remove-authentication-token body))
|
||||||
|
|
||||||
;;;;;;;;;;;;;
|
;;;;;;;;;;;;;
|
||||||
;; sign-up ;;
|
;; sign-up ;;
|
||||||
;;;;;;;;;;;;;
|
;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun sign-up (obj sql-connection &key (title "Sign Up")
|
(defun sign-up (body sql-connection &key (title "Sign Up")
|
||||||
(next-step "/login"))
|
(next-step "/login"))
|
||||||
|
(check-type body clog-body)
|
||||||
(clog-web-form
|
(clog-web-form
|
||||||
obj title
|
body title
|
||||||
`(("Username" "username")
|
`(("Username" "username")
|
||||||
("Password" "password" :password)
|
("Password" "password" :password)
|
||||||
("Retype Password" "repass" :password))
|
("Retype Password" "repass" :password))
|
||||||
|
|
@ -80,17 +84,17 @@ if one is present and login fails."
|
||||||
(cond ((not
|
(cond ((not
|
||||||
(equal (form-result result "password")
|
(equal (form-result result "password")
|
||||||
(form-result result "repass")))
|
(form-result result "repass")))
|
||||||
(clog-web-alert obj "Mismatch"
|
(clog-web-alert body "Mismatch"
|
||||||
"The passwords do match."
|
"The passwords do match."
|
||||||
:time-out 3
|
:time-out 3
|
||||||
:place-top t))
|
:place-top t))
|
||||||
((< (length (form-result result "password")) 4)
|
((< (length (form-result result "password")) 4)
|
||||||
(clog-web-alert obj "Missize"
|
(clog-web-alert body "Missize"
|
||||||
"The passwords must at least 4 characters."
|
"The passwords must at least 4 characters."
|
||||||
:time-out 3
|
:time-out 3
|
||||||
:place-top t))
|
:place-top t))
|
||||||
((< (length (form-result result "username")) 4)
|
((< (length (form-result result "username")) 4)
|
||||||
(clog-web-alert obj "Missize"
|
(clog-web-alert body "Missize"
|
||||||
"The username must be at least 4 characters."
|
"The username must be at least 4 characters."
|
||||||
:time-out 3
|
:time-out 3
|
||||||
:place-top t))
|
:place-top t))
|
||||||
|
|
@ -102,7 +106,7 @@ if one is present and login fails."
|
||||||
"select username from users where username=?")
|
"select username from users where username=?")
|
||||||
(list (form-result result "username"))))))
|
(list (form-result result "username"))))))
|
||||||
(cond (contents
|
(cond (contents
|
||||||
(clog-web-alert obj "Exists"
|
(clog-web-alert body "Exists"
|
||||||
"The username is not available."
|
"The username is not available."
|
||||||
:time-out 3
|
:time-out 3
|
||||||
:place-top t))
|
:place-top t))
|
||||||
|
|
@ -114,7 +118,7 @@ if one is present and login fails."
|
||||||
`(:username ,(form-result result "username")
|
`(:username ,(form-result result "username")
|
||||||
:password ,(form-result result "password")
|
:password ,(form-result result "password")
|
||||||
:token ,(make-token))))
|
:token ,(make-token))))
|
||||||
(url-replace (location obj) next-step)))))))))
|
(url-replace (location body) next-step)))))))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
;; make-token ;;
|
;; make-token ;;
|
||||||
|
|
|
||||||
|
|
@ -1155,6 +1155,7 @@ element."
|
||||||
(dolist (item (second drop-down))
|
(dolist (item (second drop-down))
|
||||||
(when (third item)
|
(when (third item)
|
||||||
(set-on-new-window (third item) :path (second item))))))
|
(set-on-new-window (third item) :path (second item))))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
;; base-url-p ;;
|
;; base-url-p ;;
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue