[#7189] Proper handle of restoring existing account with wrong password

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Roman Volosovskyi 2018-12-26 17:55:02 +02:00 committed by Andrea Maria Piana
parent 15747558fa
commit de5463532b
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 47 additions and 25 deletions

View File

@ -71,15 +71,21 @@
:address address :address address
:photo-path (identicon/identicon pubkey) :photo-path (identicon/identicon pubkey)
:mnemonic ""}] :mnemonic ""}]
(accounts.create/on-account-created cofx account password {:seed-backed-up? true})) (accounts.create/on-account-created
{:db (assoc-in db [:accounts/recover :password-error] :recover-password-invalid)})) cofx account password {:seed-backed-up? true}))
{:db (-> db
(update :accounts/recover assoc
:processing? false
:password ""
:password-error :recover-password-invalid)
(update :accounts/recover dissoc
:password-valid?))
:node/stop nil}))
(fx/defn on-account-recovered (fx/defn on-account-recovered
[{:keys [db] :as cofx} result password] [cofx result password]
(let [data (types/json->clj result)] (let [data (types/json->clj result)]
(fx/merge cofx (validate-recover-result cofx data password)))
{:db (dissoc db :accounts/recover)}
(validate-recover-result data password))))
(fx/defn recover-account (fx/defn recover-account
[{:keys [db random-guid-generator] :as cofx}] [{:keys [db random-guid-generator] :as cofx}]

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.accounts.recover.views (ns status-im.ui.screens.accounts.recover.views
(:require-macros [status-im.utils.views :refer [defview letsubs]]) (:require-macros [status-im.utils.views :refer [defview letsubs]
:as views])
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ui.components.text-input.view :as text-input] [status-im.ui.components.text-input.view :as text-input]
@ -14,7 +15,8 @@
[status-im.react-native.js-dependencies :as js-dependencies] [status-im.react-native.js-dependencies :as js-dependencies]
[status-im.ui.components.common.common :as components.common] [status-im.ui.components.common.common :as components.common]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.utils.platform :as platform])) [status-im.utils.platform :as platform]
[clojure.string :as string]))
(defview passphrase-input [passphrase error warning] (defview passphrase-input [passphrase error warning]
(letsubs [input-ref (reagent/atom nil)] (letsubs [input-ref (reagent/atom nil)]
@ -34,26 +36,40 @@
warning (i18n/label warning))}])) warning (i18n/label warning))}]))
(defview password-input [password error on-submit-editing] (defview password-input [password error on-submit-editing]
[react/view {:style styles/password-input (views/letsubs [inp-ref (atom nil)]
:important-for-accessibility :no-hide-descendants} {:component-will-update
[text-input/text-input-with-label (fn [_ [_ new-password]]
{:label (i18n/label :t/password) (when (and (string? new-password)
:accessibility-label :enter-password (string/blank? new-password)
:placeholder (i18n/label :t/enter-password) @inp-ref)
:default-value password (.clear @inp-ref)))}
:auto-focus false [react/view {:style styles/password-input
:on-change-text #(re-frame/dispatch [:accounts.recover.ui/password-input-changed (security/mask-data %)]) :important-for-accessibility :no-hide-descendants}
:on-blur #(re-frame/dispatch [:accounts.recover.ui/password-input-blured]) [text-input/text-input-with-label
:secure-text-entry true {:label (i18n/label :t/password)
:error (when error (i18n/label error)) :accessibility-label :enter-password
:on-submit-editing on-submit-editing}]]) :placeholder (i18n/label :t/enter-password)
:default-value password
:auto-focus false
:on-change-text #(re-frame/dispatch [:accounts.recover.ui/password-input-changed (security/mask-data %)])
:on-blur #(re-frame/dispatch [:accounts.recover.ui/password-input-blured])
:secure-text-entry true
:error (when error (i18n/label error))
:on-submit-editing on-submit-editing
:ref #(reset! inp-ref %)}]]))
(defview recover [] (defview recover []
(letsubs [recovered-account [:get-recover-account]] (letsubs [recovered-account [:get-recover-account]
(let [{:keys [passphrase password processing passphrase-valid? password-valid? node-status? [:get :node/status]]
(let [{:keys [passphrase password passphrase-valid? password-valid?
password-error passphrase-error passphrase-warning processing?]} recovered-account password-error passphrase-error passphrase-warning processing?]} recovered-account
node-stopped? (or (nil? node-status?)
(= :stopped node-status?))
valid-form? (and password-valid? passphrase-valid?) valid-form? (and password-valid? passphrase-valid?)
disabled? (or (not recovered-account) processing? (not valid-form?)) disabled? (or (not recovered-account)
processing?
(not valid-form?)
(not node-stopped?))
sign-in #(re-frame/dispatch [:accounts.recover.ui/sign-in-button-pressed])] sign-in #(re-frame/dispatch [:accounts.recover.ui/sign-in-button-pressed])]
[react/keyboard-avoiding-view {:style styles/screen-container} [react/keyboard-avoiding-view {:style styles/screen-container}
[status-bar/status-bar] [status-bar/status-bar]
@ -67,7 +83,7 @@
[react/i18n-text {:style styles/recover-release-warning [react/i18n-text {:style styles/recover-release-warning
:key :recover-account-warning}])] :key :recover-account-warning}])]
[react/view components.styles/flex] [react/view components.styles/flex]
(if processing (if processing?
[react/view styles/processing-view [react/view styles/processing-view
[react/activity-indicator {:animating true}] [react/activity-indicator {:animating true}]
[react/i18n-text {:style styles/sign-you-in [react/i18n-text {:style styles/sign-you-in