Fork me on GitHub
#liberator
<
2019-01-16
>
ordnungswidrig11:01:34

@kwladyka you can. Just return false from :new?

👍 5
kwladyka13:01:25

Thank you. I know but it is not so obviously as it looks when I don’t know deeply liberator 😉

ordnungswidrig13:01:56

That’s true. Still it’s the quickes way to “backtrace” from the desired outcome handler and look at the decisions on the way 🙂

kwladyka16:01:16

{:allowed-methods [:post]
                              :new? false
                              :handle-no-content (fn [{:keys [request] :as ctx}]
                                                (let [{:keys [params]} request
                                                      {:keys [email password]} params]
                                                  (if-let [uuid (auth/?login->uuid email password)]
                                                    (ring-response {
                                                                    :session {:uuid uuid}})
                                                    (ring-response {:status 401
                                                                    :session nil}))))}
@ordnungswidrig so you are saying it is less weird now 😉 So somebody try to login and get HTTP 204 😉 Unless I return :status 200 which is not less weird.

kwladyka16:01:15

How do you analyse decision graph? It is too small in Safari and I can’t use cmd+f. Any trick for that to make life easier in simple way?

kwladyka16:01:43

zooming doesn’t work like I wish

ordnungswidrig16:01:45

hmmm, there was an issue with the svg viewpoint in the graph which I don’t remember. You can save a copy and remove the size declaration at the very top.

ordnungswidrig16:01:19

On the other hand you should not explicitly set the status from a handler here but make use if :authorized?to handle the login case.

kwladyka16:01:01

but then I can’t return :session in :authorized?

kwladyka16:01:15

it is ok when I check if somebody is autorized, but when somebody login I feel confuse about that

ordnungswidrig16:01:40

you can assoc the session to the context and later return:

ordnungswidrig16:01:14

:authorized (fn [ctx] (if ... {:session {:uuid uuid}})

ordnungswidrig16:01:24

This will set the key session in the ctx:

ordnungswidrig16:01:00

:handle-no-content (fn [ctx] (ring-response :session (:session ctx))

ordnungswidrig16:01:20

I think you can make use of :as-response to retrieve the session for all handler.

kwladyka16:01:28

hmm in the there is :authorized?, there is not :authorized http://clojure-liberator.github.io/liberator/doc/decisions.html

kwladyka16:01:38

ok I don’t know how to use it, le me think

ordnungswidrig16:01:41

Regarding the decision graph the debugging wrapper might be helpful too :http://clojure-liberator.github.io/liberator/tutorial/debugging.html btw.

ordnungswidrig16:01:16

Need to leave now, I will have a look at the chat later today.

kwladyka16:01:28

Thanks, see you!

kwladyka16:01:44

Eventually maybe you have best practice code to login to paste here?

ordnungswidrig16:01:47

I don’t have code at hand but I can craft an example for session handling later.

kwladyka17:01:06

Hmm it could be silly a question, but maybe I shouldn’t use liberator for login request?