From b6c8013cbcd0100266f1bda436aa4075f70beee6 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 16 Sep 2022 08:59:41 -0500 Subject: Add: assert-logged-in --- lib/client.lisp | 14 +++++++++----- lib/state.lisp | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/client.lisp b/lib/client.lisp index e6324aa..527a300 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -319,6 +319,7 @@ running the body. If such a oneliner can be found." ;;; ACCOUNT AND INVITE STUFF (defun request-invite-code () + (assert-logged-in) (let ((invite (jonathan:parse (api:post-invite (api-token) *host*)))) @@ -338,18 +339,21 @@ running the body. If such a oneliner can be found." (config-file)))) (defun change-pw (current new repeated) + (assert-logged-in) (unless (equal new repeated) (error "The new password doesn't match the repeated value. Double check.")) (api:put-contributor/who/password (handle) new repeated current (api-token) *host*)) (defun change-signature () + (assert-logged-in) (let ((new-sig (prompt-for-signature))) - (ensure-config) - (api:put-contributor/who/signature (handle) (api-token) *host* - :%content-type "application/json" - :%body (jonathan:to-json (list :signature new-sig))) - (format t "Your signature was changed.~%"))) + (when new-sig + (ensure-config) + (api:put-contributor/who/signature (handle) (api-token) *host* + :%content-type "application/json" + :%body (jonathan:to-json (list :signature new-sig))) + (format t "Your signature was changed.~%")))) (defun show-contributor (name) diff --git a/lib/state.lisp b/lib/state.lisp index 9a80245..37fb06f 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -39,6 +39,11 @@ (defun (setf api-token) (newvalue) (setf (config-api-token *config*) newvalue)) +(defun assert-logged-in () + "throws an error if no plausbile api token is part of the current + config." + (api-token)) + (defun handle () (config-handle *config*)) -- cgit v1.2.3