Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

On logging in, keep the user on the same page [#6]

  • Loading branch information...
commit 88068af7545d6aaac5a00d88c74b76629d64585f 1 parent 4c6fabf
@gigasquid authored
View
17 resources/public/js/refheap.js
@@ -7,10 +7,19 @@ $(document).ready(function(){
$("#signin").click(function(event) {
navigator.id.getVerifiedEmail(function(assertion) {
if (assertion) {
- $.post('/user/verify',
- { assertion: assertion },
- function(data) { $("body").html(data) })
- }
+ $.ajax({type: "POST",
+ url: "/user/verify",
+ data: { assertion: assertion},
+ dataType: "json",
+ success: function(data) {
+ if (data) {
+ console.log("Hi there" + data);
+ $("#useri").html(data["login-html"]);
+ $("#language").after(data["private-html"])
+ }
+ },
+ });
+ }
})
})
View
32 src/refheap/views/common.clj
@@ -20,7 +20,7 @@
})();"))
(defn header []
- [:head
+ [:head
[:title "RefHeap"]
[:link {:rel "shortcut icon" :href "/img/favicon.ico"}]
(ph/include-css "http://fonts.googleapis.com/css?family=Open+Sans")
@@ -31,6 +31,28 @@
(ph/include-js "/js/refheap.js")
(analytics)])
+(defn logged-in [username]
+ (if-let [user (or username
+ (and (bound? #'session/*noir-session*)
+ (:username (session/get :user))))]
+ [:div
+ [:b (ph/link-to (str "/users/" user) user)]
+ (ph/link-to "/users/logout" "logout")]
+ [:img#signin.imgbutton {:src "/img/browserid.png"}]))
+
+(defn layout [& content]
+ (ph/html5
+ [:head
+ [:title "RefHeap"]
+ [:link {:rel "shortcut icon" :href "/img/favicon.ico"}]
+ (ph/include-css "http://fonts.googleapis.com/css?family=Open+Sans")
+ (ph/include-css "/css/refheap.css")
+ (ph/include-css "/css/native.css")
+ (ph/include-js "/js/jquery-1.7.1.min.js")
+ (ph/include-js "https://browserid.org/include.js")
+ (ph/include-js "/js/refheap.js")
+ (analytics)])
+
(defn layout [& content]
(ph/html5
(header)
@@ -41,13 +63,7 @@
[:div.headerlinks
(ph/link-to "/pastes" "Latest")
(ph/link-to "http://blog.refheap.com" "Blog")
- [:div#useri
- (if-let [user (and (bound? #'session/*noir-session*)
- (:username (session/get :user)))]
- [:div
- [:b (ph/link-to (str "/users/" user) user)]
- (ph/link-to "/users/logout" "logout")]
- [:img#signin.imgbutton {:src "/img/browserid.png"}])]]]
+ [:div#useri (logged-in nil)]]]
[:div#content
[:div#container content]
[:div#footer
View
13 src/refheap/views/login.clj
@@ -1,8 +1,10 @@
(ns refheap.views.login
(:use [hiccup.form-helpers :only [text-field submit-button form-to]]
- [refheap.views.common :only [layout]]
+ [refheap.views.common :only [layout logged-in]]
[noir.core :only [defpage]]
- [noir.response :only [redirect]])
+ [noir.response :only [redirect json]]
+ [hiccup.core :only [html]]
+ [refheap.views.paste :only [private-checkbox]])
(:require [refheap.models.login :as login]
[noir.session :as session]))
@@ -36,6 +38,7 @@
(defpage [:post "/user/verify"] {:keys [assertion]}
(when-let [{:keys [email]} (login/verify-assertion assertion)]
- (if (login/user-exists email)
- (redirect "/paste")
- (create-user-page email))))
+ (if-let [username (login/user-exists email)]
+ (json {:login-html (html (logged-in username))
+ :private-html (html (private-checkbox {:private false}))})
+ (create-user-page))))
View
8 src/refheap/views/paste.clj
@@ -9,6 +9,11 @@
[hiccup.form-helpers :as fh]
[hiccup.page-helpers :as ph]))
+
+(defn private-checkbox [old]
+ (list (fh/check-box :private (:private old))
+ (fh/label :private "Private")))
+
(defn create-paste-page [lang & [old]]
(layout
[:div#main-container
@@ -23,8 +28,7 @@
(keys paste/lexers))
(or lang (:language old "Clojure")))
(when (session/get :user)
- (list (fh/check-box :private (:private old))
- (fh/label :private "Private")))
+ (private-checkbox old))
(fh/submit-button (if old "Edit!" "Paste!"))]
(fh/text-area :paste (:raw-contents old)))]
[:div#main-right
Please sign in to comment.
Something went wrong with that request. Please try again.