Browse files

Change default post-login redirect from "/" to the originally request…

…ed uri.
  • Loading branch information...
1 parent c34b1b8 commit 4ee9d78e6b17376fb63a6c45368336c2509183e6 @duelinmarkers committed Aug 17, 2009
Showing with 13 additions and 9 deletions.
  1. +10 −7 src/appengine_clj/users.clj
  2. +3 −2 test/appengine_clj/users_test.clj
View
17 src/appengine_clj/users.clj
@@ -21,10 +21,13 @@
(application (assoc request :appengine-clj/user-info (user-info)))))
(defn wrap-requiring-login
- ([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)}})))))
+ ([application] (wrap-requiring-login application nil))
+ ([application destination-uri]
+ (let [uri-fn (if destination-uri
+ (fn [_] destination-uri)
+ (fn [request] (:uri request)))]
+ (fn [request]
+ (let [{:keys [user-service]} (user-info request)]
+ (if (.isUserLoggedIn user-service)
+ (application request)
+ {:status 302 :headers {"Location" (.createLoginURL user-service (uri-fn request))}}))))))
View
5 test/appengine_clj/users_test.clj
@@ -13,12 +13,13 @@
(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}}]
+ request {:uri "/requested_path"
+ :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=/"}}
+ (is (= {:status 302 :headers {"Location" "/login?then=/requested_path"}}
(wrapped-app-with-no-url request))))))
(testing "allows request to pass when user is logged in"
(let [fake-user-service (proxy [com.google.appengine.api.users.UserService] []

0 comments on commit 4ee9d78

Please sign in to comment.