This file contains hidden or 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
(ns frontend.routes.home | |
(:require [frontend.layout :as layout] | |
[frontend.util :as util] | |
[compojure.core :refer :all] | |
[noir.response :refer [edn]] | |
[clojure.pprint :refer [pprint]] | |
[clj-http.client :as client] | |
[environ.core :refer [env]] | |
[clojure.data.json :as json])) | |
(defn home-page [] |
This file contains hidden or 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
(defn welcome-page-component | |
"Show the welcome page" | |
[] | |
[:div | |
[:div.page-header [:h2 "Welcome page"]] | |
[:p "Congratulations! This is your welcome page:"] | |
[:p [:strong (:text @decrypted_message)]]]) |
This file contains hidden or 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
{% script "/js/functions.js" %} |
This file contains hidden or 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
//Decrypt message using OpenPGP.js | |
function decrypt_message(privkey, passphrase, encoded_message) { | |
jQuery("#keyerror").addClass("hide"); | |
var openpgp = window.openpgp; | |
var privKeys = openpgp.key.readArmored(privkey); | |
var privKey = privKeys.keys[0]; | |
if(!privKey) { | |
jQuery("#keyerror").removeClass("hide"); | |
jQuery("#keyerror").html("Error: your private key is wrong."); | |
return ""; |
This file contains hidden or 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
(defn decrypt-welcome-page | |
"Decrypt the welcome page with OpenPGP.js" | |
[doc] | |
(fn [] | |
(reset! show-errors? true) | |
(if-not (or (empty? (trim @private_key)) (empty? (trim @passphrase))) | |
(do | |
(def dec_msg (js/decrypt_message @private_key @passphrase (:text @encrypted-message))) | |
(if-not (empty? dec_msg) | |
(do |
This file contains hidden or 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
(defn welcome-page-form-component [doc] | |
[:div | |
[atom-text-input :passphrase "Passphrase" passphrase] | |
[atom-text-area :private_key "Private key" private_key] | |
[:button { :type "button" | |
:class "btn btn-default" | |
:onClick (decrypt-welcome-page doc) | |
} | |
"Show my welcome page!"]]) |
This file contains hidden or 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
(swap! state assoc :saved? true) |
This file contains hidden or 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
(defn save-doc [doc] | |
(fn [] | |
(reset! show-errors? true) | |
(if-not (or (empty? (trim @username)) (empty? (trim @public-key)) ) | |
(POST (str js/context "/save") | |
{:params {:doc {:username @username :public_key @public-key}} | |
:handler (fn [response] | |
(swap! encrypted-message assoc :text response) | |
(if-not (= "user-exists" (:text @encrypted-message)) | |
(do |
This file contains hidden or 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
(defn home | |
"Draw the home component" | |
[] | |
(let [doc (atom {})] | |
(fn [] | |
(if (:saved? @state) | |
;Welcome page form | |
[:div | |
[:div.page-header [:h2 "Signup form: Step 2"]] | |
[:p "To finish the signup and view your welcome page, please enter your private key and passphrase:"] |
This file contains hidden or 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
(defn home [] | |
[:div | |
[:h2 "Welcome to ClojureScript"]]) |
NewerOlder