forked from Raynes/refheap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some basic authentication stuff with BrowserID. Not very pretty…
… yet.
- Loading branch information
Showing
11 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{:db-name "refheap" | ||
:db-port 27017 | ||
:db-host "localhost"} | ||
:db-host "localhost" | ||
:host "localhost"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(ns refheap.config | ||
(:require [clj-config.core :as cfg])) | ||
|
||
(def config | ||
"Some external configuration." | ||
(cfg/safely cfg/read-config "config.clj")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(ns refheap.models.login | ||
(:use [refheap.config :only [config]]) | ||
(:require [somnium.congomongo :as mongo] | ||
[clj-http.client :as http] | ||
[noir.session :as session] | ||
[cheshire.core :as json])) | ||
|
||
(defn create-user [email name] | ||
(let [qmap {:email email | ||
:username name}] | ||
(when-not (mongo/fetch-one :users :where {:email email}) | ||
(mongo/insert! | ||
:users | ||
qmap) | ||
(session/put! :user qmap)))) | ||
|
||
(defn user-exists [email] | ||
(when-let [user (:username | ||
(mongo/fetch-one | ||
:users | ||
:where {:email email}))] | ||
(session/put! :user {:email email | ||
:username user}) | ||
user)) | ||
|
||
(defn verify-assertion [assertion] | ||
(let [verified (json/parse-string | ||
(:body | ||
(http/post "https://browserid.org/verify" | ||
{:query-params {:assertion assertion | ||
:audience (:host config)}})) | ||
true)] | ||
(when (= "okay" (:status verified)) | ||
verified))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(ns refheap.views.login | ||
(:use [hiccup.form-helpers :only [text-field submit-button form-to]] | ||
[refheap.views.common :only [layout]] | ||
[noir.core :only [defpage]] | ||
[noir.response :only [redirect]]) | ||
(:require [refheap.models.login :as login] | ||
[noir.session :as session])) | ||
|
||
(defn create-user-page [email] | ||
(session/flash-put! :email email) | ||
(layout | ||
(when-let [error (session/flash-get :error)] | ||
[:p.error error]) | ||
(form-to | ||
[:post "/user/create"] | ||
[:p "You're almost there! Just enter a username and you'll be on your way."] | ||
(text-field :name) | ||
(submit-button "submit")))) | ||
|
||
(defpage [:post "/user/create"] {:keys [name]} | ||
(let [email (session/flash-get :email)] | ||
(if (login/create-user email name) | ||
(redirect "/paste") | ||
(do (session/flash-put! :error "Username already exists.") | ||
(create-user-page email))))) | ||
|
||
(defpage [:post "/user/login"] {:keys [email]} | ||
(if-let [username (login/user-exists email)] | ||
(redirect "/paste") | ||
(do (session/flash-put! :email email) | ||
(redirect "/user/create")))) | ||
|
||
(defpage [:post "/user/verify"] {:keys [assertion]} | ||
(when-let [{:keys [email]} (login/verify-assertion assertion)] | ||
(prn email) | ||
(if (login/user-exists email) | ||
(do (prn (session/get :user)) | ||
(redirect "/paste")) | ||
(create-user-page email)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters