[#7192] fix autologin switch behaviour on wrong password
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
0002218a6f
commit
cdf8dc043a
|
@ -25,7 +25,7 @@
|
||||||
;; - `:callback/login` event is dispatched, account is changed in datastore, web-data is cleared
|
;; - `:callback/login` event is dispatched, account is changed in datastore, web-data is cleared
|
||||||
;; - `:init.callback/account-change-success` event is dispatched
|
;; - `:init.callback/account-change-success` event is dispatched
|
||||||
|
|
||||||
(defn login! [address password save-password?]
|
(defn login! [address password]
|
||||||
(status/login address password #(re-frame/dispatch [:accounts.login.callback/login-success %])))
|
(status/login address password #(re-frame/dispatch [:accounts.login.callback/login-success %])))
|
||||||
|
|
||||||
(defn verify! [address password realm-error]
|
(defn verify! [address password realm-error]
|
||||||
|
@ -48,8 +48,8 @@
|
||||||
|
|
||||||
;;;; Handlers
|
;;;; Handlers
|
||||||
(fx/defn login [cofx]
|
(fx/defn login [cofx]
|
||||||
(let [{:keys [address password save-password?]} (accounts.db/credentials cofx)]
|
(let [{:keys [address password]} (accounts.db/credentials cofx)]
|
||||||
{:accounts.login/login [address password save-password?]}))
|
{:accounts.login/login [address password]}))
|
||||||
|
|
||||||
(fx/defn initialize-wallet [cofx]
|
(fx/defn initialize-wallet [cofx]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
|
@ -58,17 +58,14 @@
|
||||||
(transactions/start-sync)))
|
(transactions/start-sync)))
|
||||||
|
|
||||||
(fx/defn user-login [{:keys [db] :as cofx} create-database?]
|
(fx/defn user-login [{:keys [db] :as cofx} create-database?]
|
||||||
(let [{:keys [address password save-password?]} (accounts.db/credentials cofx)]
|
(let [{:keys [address password]} (accounts.db/credentials cofx)]
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
(merge
|
{:db (-> db
|
||||||
{:db (-> db
|
(assoc-in [:accounts/login :processing] true)
|
||||||
(assoc-in [:accounts/login :processing] true)
|
(assoc :node/on-ready :login))
|
||||||
(assoc :node/on-ready :login))
|
:accounts.login/clear-web-data nil
|
||||||
:accounts.login/clear-web-data nil
|
:data-store/change-account [address password create-database?]})))
|
||||||
:data-store/change-account [address password create-database?]}
|
|
||||||
(when save-password?
|
|
||||||
{:keychain/save-user-password [address password]})))))
|
|
||||||
|
|
||||||
(fx/defn account-and-db-password-do-not-match
|
(fx/defn account-and-db-password-do-not-match
|
||||||
[{:keys [db] :as cofx} error]
|
[{:keys [db] :as cofx} error]
|
||||||
|
@ -76,6 +73,7 @@
|
||||||
cofx
|
cofx
|
||||||
{:db
|
{:db
|
||||||
(update db :accounts/login assoc
|
(update db :accounts/login assoc
|
||||||
|
:save-password? false
|
||||||
:error error
|
:error error
|
||||||
:processing false)
|
:processing false)
|
||||||
|
|
||||||
|
@ -90,7 +88,8 @@
|
||||||
(let [data (types/json->clj login-result)
|
(let [data (types/json->clj login-result)
|
||||||
error (:error data)
|
error (:error data)
|
||||||
success (empty? error)
|
success (empty? error)
|
||||||
address (get-in db [:account/account :address])]
|
{:keys [address password save-password?]}
|
||||||
|
(accounts.db/credentials cofx)]
|
||||||
;; check if logged into account
|
;; check if logged into account
|
||||||
(when address
|
(when address
|
||||||
(if success
|
(if success
|
||||||
|
@ -101,6 +100,9 @@
|
||||||
:web3/fetch-node-version [web3
|
:web3/fetch-node-version [web3
|
||||||
#(re-frame/dispatch
|
#(re-frame/dispatch
|
||||||
[:web3/fetch-node-version-callback %])]}
|
[:web3/fetch-node-version-callback %])]}
|
||||||
|
(fn [_]
|
||||||
|
(when save-password?
|
||||||
|
{:keychain/save-user-password [address password]}))
|
||||||
(protocol/initialize-protocol)
|
(protocol/initialize-protocol)
|
||||||
#(when-not platform/desktop?
|
#(when-not platform/desktop?
|
||||||
(initialize-wallet %)))
|
(initialize-wallet %)))
|
||||||
|
@ -143,50 +145,68 @@
|
||||||
:error error
|
:error error
|
||||||
:processing false)})))))
|
:processing false)})))))
|
||||||
|
|
||||||
|
(fx/defn migrations-failed
|
||||||
|
[{:keys [db]} {:keys [realm-error erase-button]}]
|
||||||
|
(let [{:keys [message details]} realm-error
|
||||||
|
address (get-in db [:accounts/login :address])]
|
||||||
|
{:ui/show-confirmation
|
||||||
|
{:title (i18n/label :migrations-failed-title)
|
||||||
|
:content (i18n/label
|
||||||
|
:migrations-failed-content
|
||||||
|
(merge
|
||||||
|
{:message message
|
||||||
|
:erase-accounts-data-button-text erase-button}
|
||||||
|
details))
|
||||||
|
:confirm-button-text erase-button
|
||||||
|
:on-cancel #(re-frame/dispatch
|
||||||
|
[:init.ui/data-reset-cancelled ""])
|
||||||
|
:on-accept #(re-frame/dispatch
|
||||||
|
[:init.ui/account-data-reset-accepted address])}}))
|
||||||
|
|
||||||
|
(fx/defn verify-account
|
||||||
|
[{:keys [db] :as cofx} {:keys [realm-error]}]
|
||||||
|
(fx/merge cofx
|
||||||
|
{:db (-> db
|
||||||
|
(assoc :node/on-ready :verify-account)
|
||||||
|
(assoc :realm-error realm-error))}
|
||||||
|
(node/initialize nil)))
|
||||||
|
|
||||||
|
(fx/defn unknown-realm-error
|
||||||
|
[cofx {:keys [realm-error erase-button]}]
|
||||||
|
(let [{:keys [message]} realm-error
|
||||||
|
{:keys [address]} (accounts.db/credentials cofx)]
|
||||||
|
{:ui/show-confirmation
|
||||||
|
{:title (i18n/label :unknown-realm-error)
|
||||||
|
:content (i18n/label
|
||||||
|
:unknown-realm-error-content
|
||||||
|
{:message message
|
||||||
|
:erase-accounts-data-button-text erase-button})
|
||||||
|
:confirm-button-text (i18n/label :invalid-key-confirm)
|
||||||
|
:on-cancel #(re-frame/dispatch
|
||||||
|
[:init.ui/data-reset-cancelled ""])
|
||||||
|
:on-accept #(re-frame/dispatch
|
||||||
|
[:init.ui/account-data-reset-accepted address])}}))
|
||||||
|
|
||||||
(fx/defn handle-change-account-error
|
(fx/defn handle-change-account-error
|
||||||
[{:keys [db] :as cofx} error]
|
[{:keys [db] :as cofx} error]
|
||||||
(let [{:keys [error message details] :as realm-error}
|
(let [{:keys [error] :as realm-error}
|
||||||
(if (map? error)
|
(if (map? error)
|
||||||
error
|
error
|
||||||
{:message (str error)})
|
{:message (str error)})
|
||||||
{:keys [address]} (accounts.db/credentials cofx)
|
|
||||||
erase-button (i18n/label :migrations-erase-accounts-data-button)]
|
erase-button (i18n/label :migrations-erase-accounts-data-button)]
|
||||||
(case error
|
(fx/merge
|
||||||
:migrations-failed
|
cofx
|
||||||
(let [{:keys [message]} realm-error
|
{:db (assoc-in db [:accounts/login :save-password?] false)}
|
||||||
address (get-in db [:accounts/login :address])]
|
(case error
|
||||||
{:ui/show-confirmation
|
:migrations-failed
|
||||||
{:title (i18n/label :migrations-failed-title)
|
(migrations-failed {:realm-error realm-error
|
||||||
:content (i18n/label
|
:erase-button erase-button})
|
||||||
:migrations-failed-content
|
|
||||||
(merge
|
|
||||||
{:message message
|
|
||||||
:erase-accounts-data-button-text erase-button}
|
|
||||||
details))
|
|
||||||
:confirm-button-text erase-button
|
|
||||||
:on-cancel #(re-frame/dispatch
|
|
||||||
[:init.ui/data-reset-cancelled ""])
|
|
||||||
:on-accept #(re-frame/dispatch
|
|
||||||
[:init.ui/account-data-reset-accepted address])}})
|
|
||||||
|
|
||||||
(:database-does-not-exist :decryption-failed)
|
(:database-does-not-exist :decryption-failed)
|
||||||
(fx/merge cofx
|
(verify-account {:realm-error realm-error})
|
||||||
{:db (-> db
|
|
||||||
(assoc :node/on-ready :verify-account)
|
|
||||||
(assoc :realm-error realm-error))}
|
|
||||||
(node/initialize nil))
|
|
||||||
|
|
||||||
{:ui/show-confirmation
|
(unknown-realm-error {:realm-error realm-error
|
||||||
{:title (i18n/label :unknown-realm-error)
|
:erase-button erase-button})))))
|
||||||
:content (i18n/label
|
|
||||||
:unknown-realm-error-content
|
|
||||||
{:message message
|
|
||||||
:erase-accounts-data-button-text erase-button})
|
|
||||||
:confirm-button-text (i18n/label :invalid-key-confirm)
|
|
||||||
:on-cancel #(re-frame/dispatch
|
|
||||||
[:init.ui/data-reset-cancelled ""])
|
|
||||||
:on-accept #(re-frame/dispatch
|
|
||||||
[:init.ui/account-data-reset-accepted address])}})))
|
|
||||||
|
|
||||||
(fx/defn open-login [{:keys [db]} address photo-path name]
|
(fx/defn open-login [{:keys [db]} address photo-path name]
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
|
@ -212,8 +232,8 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:accounts.login/login
|
:accounts.login/login
|
||||||
(fn [[address password save-password?]]
|
(fn [[address password]]
|
||||||
(login! address (security/safe-unmask-data password) save-password?)))
|
(login! address (security/safe-unmask-data password))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:accounts.login/verify
|
:accounts.login/verify
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
(re-frame/inject-cofx :data-store/all-browsers)
|
(re-frame/inject-cofx :data-store/all-browsers)
|
||||||
(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
||||||
(fn [{:keys [db] :as cofx} [_ address]]
|
(fn [{:keys [db] :as cofx} [_ address]]
|
||||||
(let [{:node/keys [status]} db]
|
(let [{:node/keys [status on-ready]} db]
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
(if (= status :started)
|
(if (= status :started)
|
||||||
|
|
|
@ -144,7 +144,7 @@
|
||||||
:hardwallet-setup hardwallet-setup
|
:hardwallet-setup hardwallet-setup
|
||||||
:hardwallet-success hardwallet-success)))
|
:hardwallet-success hardwallet-success)))
|
||||||
(cond-> {:headerMode "none"}
|
(cond-> {:headerMode "none"}
|
||||||
(#{:intro :login} view-id)
|
(#{:intro :login :progress} view-id)
|
||||||
(assoc :initialRouteName (name view-id))))}
|
(assoc :initialRouteName (name view-id))))}
|
||||||
:chat-stack
|
:chat-stack
|
||||||
{:screen
|
{:screen
|
||||||
|
@ -403,7 +403,7 @@
|
||||||
(when (and
|
(when (and
|
||||||
platform/android?
|
platform/android?
|
||||||
(not js/goog.DEBUG)
|
(not js/goog.DEBUG)
|
||||||
(not (contains? #{:intro :login} @view-id)))
|
(not (contains? #{:intro :login :progress} @view-id)))
|
||||||
(navigation/navigate-to @view-id)))
|
(navigation/navigate-to @view-id)))
|
||||||
;; see https://reactnavigation.org/docs/en/state-persistence.html#development-mode
|
;; see https://reactnavigation.org/docs/en/state-persistence.html#development-mode
|
||||||
:persistenceKey (when js/goog.DEBUG rand-label)}]))})))
|
:persistenceKey (when js/goog.DEBUG rand-label)}]))})))
|
||||||
|
|
Loading…
Reference in New Issue