Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
peer server script uses memory database
`make peer-server`
  • Loading branch information
robert-stuttaford committed Mar 17, 2018
1 parent eecc314 commit 39d3d95
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -23,4 +23,7 @@ uberjar:
serve-jar:
source bridge.env && java -jar bridge.jar -m bridge.service

peer-server:
source bridge.env && bash script/datomic-peer-server.sh

pack: clean compile uberjar
24 changes: 16 additions & 8 deletions dev/bridge/dev/repl.clj
Expand Up @@ -3,22 +3,30 @@
[bridge.data.datomic :as datomic]
[integrant.core :as ig]))

;; uses Datomic Peer library

(defn init-datomic []
(ig/init-key :datomic/connection
(:datomic/connection (config/system))))

(defn set-datomic-mode! [mode]
(alter-var-root datomic/*DATOMIC-MODE* (constantly mode)))
(alter-var-root (var datomic/*DATOMIC-MODE*) (constantly mode)))

(defn conn []
(when (nil? datomic/*DATOMIC-MODE*)
(throw (ex-info (str "Set `bridge.data.datomic/*DATOMIC-MODE*` first."
"You can use `bridge.dev.repl/set-datomic-mode!` "
"to do so at the repl.")
{})))
(:datomic/conn (init-datomic)))
(-> (ig/init-key :datomic/connection
(-> (:datomic/connection (config/system))
(assoc :datomic/mode datomic/*DATOMIC-MODE*)))
:datomic/conn))

(defn db []
(datomic/db (conn)))

(comment

(set-datomic-mode! :client)
(set-datomic-mode! :peer)

(conn)

(datomic/pull (db) '[*] [:person/email "test@cb.org"])

)
2 changes: 1 addition & 1 deletion resources/system.edn
@@ -1,5 +1,5 @@
{:datomic/connection
{:datomic/mode :peer ;; or :client
{:datomic/mode :peer ;; :peer or :client

;; for :peer
:uri #dyn/prop BRIDGE_DATOMIC_URI
Expand Down
2 changes: 1 addition & 1 deletion script/datomic-peer-server.sh
Expand Up @@ -2,4 +2,4 @@

# requires Datomic Pro

$DATOMIC_PATH/runtime/bin/run -m datomic.peer-server -h localhost -p 8998 -a $BRIDGE_DATOMIC_CLIENT_KEY,$BRIDGE_DATOMIC_CLIENT_SECRET -d $BRIDGE_DATOMIC_DB,datomic:free://localhost:4334/$BRIDGE_DATOMIC_DB
$DATOMIC_PATH/runtime/bin/run -m datomic.peer-server -h localhost -p 8998 -a $BRIDGE_DATOMIC_CLIENT_KEY,$BRIDGE_DATOMIC_CLIENT_SECRET -d $BRIDGE_DATOMIC_DB,datomic:mem://localhost:4334/$BRIDGE_DATOMIC_DB
5 changes: 1 addition & 4 deletions src/bridge/data/dev_data.clj
Expand Up @@ -5,10 +5,7 @@

(defn add-person! [conn {:person/keys [email] :as new-person}]
(when (nil? (person.data/person-id-by-email (datomic/db conn) email))
(let [new-person-tx (person.data/new-person-tx new-person
#:person{:name "Test Name"
:email "test@cb.org"
:password "secret"})]
(let [new-person-tx (person.data/new-person-tx new-person)]
(person.data/save-new-person! conn new-person-tx)
(person.data/confirm-email! conn
(person.data/person-id-by-email (datomic/db conn) email)
Expand Down
10 changes: 5 additions & 5 deletions src/bridge/person/access/reset_password.clj
Expand Up @@ -40,12 +40,13 @@
[:p.has-text-grey
[:a {:href "/help"} "Need Help?"]]))

(defn reset-password [{:keys [request-method]
{:keys [reset-password-token password confirm-password]} :params
(defn reset-password [{[_ token] :ataraxy/result
:keys [request-method]
{:keys [password confirm-password]} :params
:datomic/keys [conn db]}]
(or (when (= :post request-method)
(let [person-id (person.data/person-id-by-reset-password-token
db reset-password-token)
db token)
password-error (person.data/valid-password? password confirm-password)]
(cond (nil? person-id)
(reset-password-page :invalid-token)
Expand All @@ -55,8 +56,7 @@

:else
(try
(person.data/reset-password! conn person-id reset-password-token
password)
(person.data/reset-password! conn person-id token password)

(response/redirect (access.common/login-uri "/"))

Expand Down
2 changes: 1 addition & 1 deletion src/bridge/person/data.clj
Expand Up @@ -57,7 +57,7 @@

(defn save-new-person! [conn person-tx]
(datomic/transact! conn [person-tx])
(let [{:person/keys [email email-confirm-token]} (:person/email person-tx)]
(let [{:person/keys [email email-confirm-token]} person-tx]
(send-email! email (str "your email confirm token: " email-confirm-token))))

(defn confirm-email! [conn person-id token]
Expand Down

0 comments on commit 39d3d95

Please sign in to comment.