diff options
author | Colin Okay <okay@toyful.space> | 2022-02-28 12:50:26 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-28 12:50:26 -0600 |
commit | 65bf3a5a5f00b40d3f219a469cea1eaa86e1aa95 (patch) | |
tree | 7633c7c64713f456cdaaaf990f5209499484abe4 | |
parent | 042237c1db504e733a41e99cd7ee913023e136ec (diff) |
recording contributor handle
-rw-r--r-- | oneliners.api-client.lisp | 66 | ||||
-rw-r--r-- | src/lib.lisp | 22 |
2 files changed, 55 insertions, 33 deletions
diff --git a/oneliners.api-client.lisp b/oneliners.api-client.lisp index e8e1d28..bd7ba72 100644 --- a/oneliners.api-client.lisp +++ b/oneliners.api-client.lisp @@ -5,7 +5,8 @@ (defpackage #:ONELINERS.API-CLIENT (:use :cl :lazybones-client.shared) (:export #:*host* #:*body* #:*headers* #:*cookies* #:request-with - #:GET--ONELINERS + #:PUT--CONTRIBUTOR-WHO-PASSWORD +#:GET--ONELINERS #:GET--ONELINERS-ALL-FLAGGED #:GET--ONELINERS-NEWEST #:PUT--ONELINER-ENTRY-FLAG @@ -18,7 +19,6 @@ #:POST--ACCESS #:POST--INVITE-REDEEM-CODE #:PUT--CONTRIBUTOR-WHO-SIGNATURE -#:PUT--CONTRIBUTOR-WHO-PASSWORD #:PUT--CONTRIBUTOR-WHO-LOCKED #:GET--CONTRIBUTOR-WHO)) (in-package :ONELINERS.API-CLIENT) @@ -69,6 +69,39 @@ COOKIES should be an instance of CL-COOKIE:COOKIE-JAR. Defaults to (dex:response-body ,http-error-var))))))) +(DEFUN PUT--CONTRIBUTOR-WHO-PASSWORD (WHO &KEY VALUE REPEATED CURRENT TOKEN) + "Change a contributor's password." + (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING + (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" + (FORMAT NIL "/contributor/~a/password" WHO) + (WHEN (OR VALUE REPEATED CURRENT TOKEN) + (LIST "?" + (IF VALUE + (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" + (FORMAT NIL "~a" VALUE)) + "") + (IF REPEATED + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'REPEATED) + "=" (FORMAT NIL "~a" REPEATED)) + "") + (IF CURRENT + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'CURRENT) "=" + (FORMAT NIL "~a" CURRENT)) + "") + (IF TOKEN + (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" + (FORMAT NIL "~a" TOKEN)) + "")))))) + (IF LAZYBONES-CLIENT.SHARED:*BODY* + (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT + LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*) + (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR + LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS + LAZYBONES-CLIENT.SHARED:*HEADERS*)))) + + (DEFUN GET--ONELINERS (&KEY TAGS LIMIT NOTFLAGGED) "A search endpoint returning a JSON encoded array of Oneliner Entries. TAGS cannot be empty. Returns a [Search @@ -324,35 +357,6 @@ Result](#search-result) object." LAZYBONES-CLIENT.SHARED:*HEADERS*)))) -(DEFUN PUT--CONTRIBUTOR-WHO-PASSWORD (WHO &KEY VALUE REPEATED TOKEN) - NIL - (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING - (APPLY #'CONCATENATE 'STRING LAZYBONES-CLIENT.SHARED:*HOST* "/api" - (FORMAT NIL "/contributor/~a/password" WHO) - (WHEN (OR VALUE REPEATED TOKEN) - (LIST "?" - (IF VALUE - (CONCATENATE 'STRING (SYMBOL-NAME 'VALUE) "=" - (FORMAT NIL "~a" VALUE)) - "") - (IF REPEATED - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'REPEATED) - "=" (FORMAT NIL "~a" REPEATED)) - "") - (IF TOKEN - (CONCATENATE 'STRING "&" (SYMBOL-NAME 'TOKEN) "=" - (FORMAT NIL "~a" TOKEN)) - "")))))) - (IF LAZYBONES-CLIENT.SHARED:*BODY* - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :CONTENT - LAZYBONES-CLIENT.SHARED:*BODY* :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*) - (DEXADOR:PUT LAZYBONES-CLIENT.SHARED::REQ-STRING :COOKIE-JAR - LAZYBONES-CLIENT.SHARED:*COOKIES* :HEADERS - LAZYBONES-CLIENT.SHARED:*HEADERS*)))) - - (DEFUN PUT--CONTRIBUTOR-WHO-LOCKED (WHO &KEY VALUE TOKEN) NIL (LET ((LAZYBONES-CLIENT.SHARED::REQ-STRING diff --git a/src/lib.lisp b/src/lib.lisp index fb2217b..3df4006 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -60,6 +60,9 @@ (setf (getf *config* :api-token) newval)) (defun get-shell () (getf *config* :shell)) +(defun contributor-handle () (getf *config* :handle)) +(defun (setf contributor-handle) (newval) + (setf (getf *config* :handle) newval)) (defun config-file () (merge-pathnames ".config/oneliners.config" (user-homedir-pathname))) @@ -363,9 +366,23 @@ the directories that appear in the value of that variable." :body (jonathan:to-json (list :password pass :handle user)) :content-type "application/json") (api:post--access)))) - (setf (api-token) (getf response :token)) + (setf (api-token) (getf response :token) + (contributor-handle) handle) (write-config-to-disk) - (format t "Access token written to ~a~%" (config-file)))) + (format t "Access token written to ~a~%You may now make contributions to the wiki!.~%" + (config-file)))) + +(defun change-pw (current new repeated) + (unless (equal new repeated) + (error "The new password doesn't match the repeated value. Double check.")) + (ensure-config) + (api:request-with + (:host (host)) + (api:put--contributor-who-password (contributor-handle) + :token (api-token) + :value new + :repeated new + :current current))) (defparameter +agree-to-the-unlicense+ "By creating this contributor account, I agree that my contributions @@ -394,6 +411,7 @@ the directories that appear in the value of that variable." (api:post--invite-redeem-code token) (format t "Account made for ~a. You may log in now~%" name)))) +;;TODO: check this .. shouldnt access be a username??? (defun revoke-access () (ensure-config) (api:request-with |