On Jan 25, 1:02 pm, Brenton <
bashw...@gmail.com> wrote:
> Kevin,
>
> Sandbar does not support "out of the box" AJAX authentication. You
> will need to create your own route for this. This shouldn't be too
> hard to do. Take a look at the code in form_authentication.clj for
> ideas. The problem with using that code via AJAX is that it always
> wants to redirect you.
>
> I think you want to do something like this (untested code):
>
> (POST "/login" req
> (if-let [valid-user (authenticate-user req)]
> (do (session-put! :current-user
> {:name (:username valid-user)
> :roles (:roles valid-user)})
> (json-response {:authenticated true}))
> (json-response {:authenticated false})))
>
> where authenticate-user is a function that you write which would get
> the user information from the request and then ensure this this is a
> valid user with valid credentials. It would return nil if this is not
> true. By storing :current-user in the session, the (with-security)
> middleware will recognize that the user as been authenticated. Note
> that in the :current-user map :name must be a string and :roles must
> be a set of keywords.
>
> This library will be extended in the future to make such things
> easier. If you come up with good solution, let me know.
>