Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/honza/jordan
Clojure library for Compojure that allows you to specify which routes require the user to be logged in or to be an administrator
https://github.com/honza/jordan
Last synced: about 5 hours ago
JSON representation
Clojure library for Compojure that allows you to specify which routes require the user to be logged in or to be an administrator
- Host: GitHub
- URL: https://github.com/honza/jordan
- Owner: honza
- License: bsd-2-clause
- Created: 2014-01-10T16:20:16.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-24T12:37:15.000Z (over 7 years ago)
- Last Synced: 2024-08-14T21:10:54.204Z (3 months ago)
- Language: Clojure
- Homepage: https://github.com/honza/jordan
- Size: 9.77 KB
- Stars: 14
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Jordan
======Jordan is a Clojure library for Compojure that allows you to specify which
routes require the user to be logged in or to be an administrator.Jordan is a replacement for libraries like [friend][1].
> He lay flat on the brown, pine-needled floor of the forest, his chin on his
> folded arms, and high overhead the wind blew in the tops of the pine trees.
> The mountainside sloped gently where he lay; but below it was steep and he
> could see the dark of the oiled road winding through the pass. There was a
> stream alongside the road and far down the pass he saw a mill beside the
> stream and the falling water of the dam, white in the summer sunlight.
>
> --- For Whom The Bell Tolls, Ernest HemingwayInstallation
------------[![Clojars Project](http://clojars.org/jordan/latest-version.svg)](http://clojars.org/jordan)
Usage
-----Jordan gives you two macros for protecting your routes: `with-login-required`
and `with-admin-required`.``` clojure
(ns xyz.core
(:require [jordan.core :refer :all]))(defroutes routes
(GET "/" req"hello
")
(GET "/account/" req
(with-login-required "hello logged in user
"))
(GET "/admin/" req
(with-admin-required "hello admin
")))```
For a real world example, check out [ansel][2] the self-hosted photo gallery.
### How does Jordan check if a user is logged in?
By default, Jordan checks if the current request map includes a truthy `:user`
key. You can of course specify your own function.``` clojure
;; Always true
(reset! logged-in-fn (fn [req] true))
```### How does Jordan check if a user is an admin?
By default, Jordan checks if the current request map includes a truthy `:admin`
key inside the `:user` object. You can of course specify your own function.``` clojure
;; Always true
(reset! admin-fn (fn [req] true))
```### How can I customize the error page?
Easy
``` clojure
(reset! default-404 (fn [req] {:status 404}))
```License
-------BSD, short and sweet
[1]: https://github.com/cemerick/friend
[2]: https://github.com/honza/ansel