Permalink
Browse files

Overload wrap-requiring-login to allow specifying a url to send the u…

…ser to after login.
  • Loading branch information...
1 parent 2cfe33e commit 241b8fc7d2aa3876e1fa0a31f7e258e773e1a085 @duelinmarkers committed Aug 17, 2009
Showing with 14 additions and 10 deletions.
  1. +7 −6 src/appengine_clj/users.clj
  2. +7 −4 test/appengine_clj/users_test.clj
@@ -21,9 +21,10 @@
(application (assoc request :appengine-clj/user-info (user-info)))))
(defn wrap-requiring-login
- [application]
- (fn [request]
- (let [{:keys [user-service]} (user-info request)]
- (if (.isUserLoggedIn user-service)
- (application request)
- {:status 302 :headers {"Location" (.createLoginURL user-service "/")}}))))
+ ([application] (wrap-requiring-login application "/"))
+ ([application url]
+ (fn [request]
+ (let [{:keys [user-service]} (user-info request)]
+ (if (.isUserLoggedIn user-service)
+ (application request)
+ {:status 302 :headers {"Location" (.createLoginURL user-service url)}})))))
@@ -13,8 +13,11 @@
(let [fake-user-service (proxy [com.google.appengine.api.users.UserService] []
(isUserLoggedIn [] false)
(createLoginURL [dest] (str "/login?then=" dest)))
- request {:appengine-clj/user-info {:user nil :user-service fake-user-service}}
- wrapped-app (users/wrap-requiring-login #(throw (Exception.)))]
- (is (= {:status 302 :headers {"Location" "/login?then=/"}}
- (wrapped-app request))))))
+ request {:appengine-clj/user-info {:user nil :user-service fake-user-service}}]
+ (let [wrapped-app-with-url (users/wrap-requiring-login #(throw (Exception.)) "/the_path")]
+ (is (= {:status 302 :headers {"Location" "/login?then=/the_path"}}
+ (wrapped-app-with-url request))))
+ (let [wrapped-app-with-no-url (users/wrap-requiring-login #(throw (Exception.)))]
+ (is (= {:status 302 :headers {"Location" "/login?then=/"}}
+ (wrapped-app-with-no-url request)))))))

0 comments on commit 241b8fc

Please sign in to comment.