I am trying to encode a login page where:
the user fills out the form with the post method
if the form has a destination URL starting with "/ auth-", the user will be redirected to the "/ login" page
user will fill in username and password, etc.
if authorization is provided, all information will be, say, inserted into the database
If the username or password is incorrect, all information will be saved for a second chance.
The intention is not much different from as described here , if my purpose is not yet clear.
This method, based on this question , allows me to redirect any link, starting with "auth-", to redirect to the login page, as well as get parameters:
(defmethod hunchentoot:acceptor-dispatch-request :around
((acceptor hunchentoot:easy-acceptor) request)
(let* ((address-bar (cl-ppcre:split "\\?" (hunchentoot:request-uri* request)))
(just-url (first address-bar))
(query-params (second address-bar)))
(if (cl-ppcre:scan "^/auth-" just-url)
(hunchentoot:redirect (if query-params
(format nil "/login?~A" query-params)
"/login"))
(call-next-method))))
But how can I redirect with post parameters instead?
I thought line by line:
(defmethod hunchentoot:acceptor-dispatch-request :around
((acceptor hunchentoot:easy-acceptor) request)
(let* ((just-url (car (cl-ppcre:split "\\?" (hunchentoot:request-uri* request)))))
(if (cl-ppcre:scan "^/auth-" just-url)
(hunchentoot:redirect "/login")
(call-next-method))))
(hunchentoot:define-easy-handler (login :uri "/login") ()
(with-html-output (*standard-output* nil :prologue t)
(:html
(:body
(dolist (post (hunchentoot:post-parameters*))
(format t "<div>~A ~A</div>" (car post) (cadr post)))))))
will work, but the / login page will not be able to show anything. I assume that the problem is that you cannot redirect messages with data, as suggested by the link above .
My previous attempt was to create a function that saved the url (with get parameters) in a hidden login, allowing the user to log in and then redirect to the saved url. This is very similar to the second sentence of this answer and works for me. I just can't dry it.
, around "auth-" .
:
, , , , , cookie. , ?
http status code 307 .
, , restas caveman, lisp . , . - . script, , , .
(hunchentoot:redirect "/login") (drakma:http-request "http://127.0.0.1:4242/login" :method :post :parameters (hunchentoot:post-parameters* request)), " 200". , , drakma , .
.