Send phone-number to server

Former-commit-id: f592babca8
This commit is contained in:
virvar 2016-04-06 18:24:11 +03:00
parent 756b682d68
commit 872dd9a56d
5 changed files with 61 additions and 17 deletions

View File

@ -2,8 +2,8 @@
(def ethereum-rpc-url "http://localhost:8545")
(def server-address "http://rpc0.syng.im:20000/")
;; (def server-address "http://10.0.3.2:3000/")
;; (def server-address "http://rpc0.syng.im:20000/")
(def server-address "http://10.0.3.2:3000/")
(def text-content-type "text/plain")
(def content-type-command "command")

View File

@ -190,9 +190,8 @@
;; -- Sign up --------------------------------------------------------------
(register-handler :sign-up
(fn [db [_ phone-number whisper-identity handler]]
(server/sign-up phone-number whisper-identity handler)
db))
(fn [db [_ phone-number handler]]
(server/sign-up db phone-number handler)))
(register-handler :set-confirmation-code
(fn [db [_ value]]

View File

@ -5,13 +5,14 @@
[syng-im.utils.logging :as log]))
(defn sign-up
[phone-number whisper-identity handler]
[db phone-number handler]
(user-data/save-phone-number phone-number)
(http-post "sign-up" {:phone-number phone-number
:whisper-identity (:public whisper-identity)}
:whisper-identity (get-in db [:user-identity :public])}
(fn [body]
(log body)
(handler))))
(handler)))
db)
(defn sign-up-confirm
[confirmation-code handler]

View File

@ -5,6 +5,7 @@
[syng-im.utils.utils :refer [log on-error http-post toast]]
[syng-im.utils.logging :as log]
[syng-im.utils.random :as random]
[syng-im.utils.phone-number :refer [format-phone-number]]
[syng-im.constants :refer [text-content-type
content-type-command
content-type-command-request]]))
@ -35,7 +36,7 @@
:outgoing false
:from "console"
:to "me"}])
(dispatch [:set-chat-command :keypair-password])
;; (dispatch [:set-chat-command :keypair-password])
db)
(defn send-console-msg [text]
@ -46,6 +47,47 @@
:content-type text-content-type
:outgoing true})
;; ----------
;; server
;; from confirm code view
(comment
(defn sync-contacts [navigator]
(dispatch [:sync-contacts #(show-home-view navigator)]))
(defn on-send-code-response [navigator body]
(log body)
(toast (if (:confirmed body)
"Confirmed"
"Wrong code"))
(if (:confirmed body)
;; TODO user action required
(sync-contacts navigator)
(dispatch [:set-loading false])))
(defn code-valid? [code]
(= 4 (count code)))
(defn send-code [code navigator]
(when (code-valid? code)
(dispatch [:set-loading true])
(dispatch [:sign-up-confirm code (partial on-send-code-response navigator)])))
(defn update-code [value]
(let [formatted value]
(dispatch [:set-confirmation-code formatted]))))
;; from sign up view
;; ----------
;; end server
(defn- handle-password [content]
;; TODO validate and save password
(dispatch [:received-msg
@ -102,9 +144,7 @@
:from "console"
:to "me"}]))
(defn- handle-phone [content]
;; TODO validate and save phone number
;; send phone to server
(defn on-sign-up-response []
(dispatch [:received-msg
{:msg-id "10"
:content (commands/format-command-request-msg-content
@ -116,6 +156,10 @@
:from "console"
:to "me"}]))
(defn- handle-phone [content]
(let [phone-number (format-phone-number content)]
(dispatch [:sign-up phone-number on-sign-up-response])))
(defn- handle-confirmation-code [content]
;; TODO validate confirmation code
;; send code to server

View File

@ -65,11 +65,11 @@
;; -- User data --------------------------------------------------------------
(register-sub
:get-user-phone-number
(fn [db _]
(reaction
(get @db :user-phone-number))))
;; (register-sub
;; :get-user-phone-number
;; (fn [db _]
;; (reaction
;; (get @db :user-phone-number))))
(register-sub
:get-user-identity