diff --git a/source/clog-web-dbi.lisp b/source/clog-web-dbi.lisp index f1d3a5a..d2cd3ab 100644 --- a/source/clog-web-dbi.lisp +++ b/source/clog-web-dbi.lisp @@ -21,6 +21,7 @@ (get-profile function) (sign-up function) (change-password function) + (reset-password function) (make-token function) (load-content function) (create-base-tables function)) @@ -76,6 +77,7 @@ if one is present and login fails." (defun sign-up (body sql-connection &key (title "Sign Up") (next-step "/login")) + "Setup a sign-up form and process a new sign-up" (check-type body clog-body) (clog-web-form body title @@ -128,6 +130,7 @@ if one is present and login fails." (defun change-password (body sql-connection &key (title "Change Password") (next-step "/")) + "Setup a change password form and handle change of password" (check-type body clog-body) (clog-web-form body title @@ -170,11 +173,28 @@ if one is present and login fails." :time-out 3 :place-top t))))))))) +;;;;;;;;;;;;;;;;;;;; +;; reset-password ;; +;;;;;;;;;;;;;;;;;;;; + +(defun reset-password (sql-connection username &key (new-password "password")) + "Reset USERNAME's password to :NEW-PASSWORD" + (print username) + + (dbi:do-sql + sql-connection + (sql-update + "users" + `(:password ,new-password) + "username=?") + (list username))) + ;;;;;;;;;;;;;;;; ;; make-token ;; ;;;;;;;;;;;;;;;; (defun make-token () + "Create a unique token used to associate a browser with a user" (get-universal-time)) ;;;;;;;;;;;;;;;;;;;;;;; @@ -182,6 +202,7 @@ if one is present and login fails." ;;;;;;;;;;;;;;;;;;;;;;; (defun create-base-tables (sql-connection &key (sql-timestamp-func *sqlite-timestamp*)) + "Create default tables" (dbi:do-sql sql-connection "create table config (key varchar, value varchar)") diff --git a/tutorial/32-tutorial.lisp b/tutorial/32-tutorial.lisp index c201a4b..e129c2f 100644 --- a/tutorial/32-tutorial.lisp +++ b/tutorial/32-tutorial.lisp @@ -161,7 +161,17 @@ *sql-connection* "select * from users"))))) (dolist (user users) - (create-div body :content (getf user :|username|)))))) + (let* ((box (create-div body)) + (suser (create-span box :content (getf user :|username|))) + (rbut (create-button box :content "Reset Password" + :class "w3-margin-left"))) + (declare (ignore suser)) + (set-on-click rbut (lambda (obj) + (declare (ignore obj)) + (reset-password *sql-connection* + (getf user :|username|)) + (setf (disabledp rbut) t) + (setf (text rbut) "Done")))))))) :authorize t)) (defun on-new-pass (body)