validate command's name (#235)
This commit is contained in:
parent
5a68b1d646
commit
ac199ba2fa
|
@ -9,7 +9,8 @@
|
||||||
[status-im.utils.types :refer [json->clj]]
|
[status-im.utils.types :refer [json->clj]]
|
||||||
[status-im.commands.utils :refer [reg-handler]]
|
[status-im.commands.utils :refer [reg-handler]]
|
||||||
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.utils.homoglyph :as h]))
|
||||||
|
|
||||||
(def commands-js "commands.js")
|
(def commands-js "commands.js")
|
||||||
|
|
||||||
|
@ -36,8 +37,8 @@
|
||||||
(dispatch [::validate-hash identity (slurp "resources/commands.js")])
|
(dispatch [::validate-hash identity (slurp "resources/commands.js")])
|
||||||
#_(http-get (s/join "/" [url commands-js])
|
#_(http-get (s/join "/" [url commands-js])
|
||||||
|
|
||||||
#(dispatch [::validate-hash identity %])
|
#(dispatch [::validate-hash identity %])
|
||||||
#(dispatch [::loading-failed! identity ::file-was-not-found])))))
|
#(dispatch [::loading-failed! identity ::file-was-not-found])))))
|
||||||
|
|
||||||
(defn dispatch-loaded!
|
(defn dispatch-loaded!
|
||||||
[db [identity file]]
|
[db [identity file]]
|
||||||
|
@ -75,17 +76,27 @@
|
||||||
(map (fn [[k v]] [k (assoc v :type as)]))
|
(map (fn [[k v]] [k (assoc v :type as)]))
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
|
(defn filter-forbidden-names [id commands]
|
||||||
|
(->> commands
|
||||||
|
(remove (fn [[n]]
|
||||||
|
(and
|
||||||
|
(not (= console-chat-id id))
|
||||||
|
(h/matches (name n) "password"))))
|
||||||
|
(into {})))
|
||||||
|
|
||||||
(defn add-commands
|
(defn add-commands
|
||||||
[db [id _ {:keys [commands responses autorun] :as data}]]
|
[db [id _ {:keys [commands responses autorun]}]]
|
||||||
(-> db
|
(let [commands' (filter-forbidden-names id commands)
|
||||||
(update-in [id :commands] merge (mark-as :command commands))
|
responses' (filter-forbidden-names id responses)]
|
||||||
(update-in [id :responses] merge (mark-as :response responses))
|
(-> db
|
||||||
(assoc-in [id :commands-loaded] true)
|
(update-in [id :commands] merge (mark-as :command commands'))
|
||||||
(assoc-in [id :autorun] autorun)))
|
(update-in [id :responses] merge (mark-as :response responses'))
|
||||||
|
(assoc-in [id :commands-loaded] true)
|
||||||
|
(assoc-in [id :autorun] autorun))))
|
||||||
|
|
||||||
(defn save-commands-js!
|
(defn save-commands-js!
|
||||||
[_ [id file]]
|
[_ [id file]]
|
||||||
(commands/save {:chat-id id :file file}))
|
(commands/save {:chat-id id :file file}))
|
||||||
|
|
||||||
(defn loading-failed!
|
(defn loading-failed!
|
||||||
[db [id reason details]]
|
[db [id reason details]]
|
||||||
|
|
|
@ -2,17 +2,16 @@
|
||||||
(:require [cljs.spec :as s]
|
(:require [cljs.spec :as s]
|
||||||
[status-im.utils.phone-number :refer [valid-mobile-number?]]
|
[status-im.utils.phone-number :refer [valid-mobile-number?]]
|
||||||
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[status-im.utils.homoglyph :as h]))
|
||||||
(def homoglyph-finder (js/require "homoglyph-finder"))
|
|
||||||
|
|
||||||
(defn not-illegal-name? [username]
|
(defn not-illegal-name? [username]
|
||||||
(let [username (some-> username (str/trim))]
|
(let [username (some-> username (str/trim))]
|
||||||
(and (not (.isMatches homoglyph-finder username console-chat-id))
|
(and (not (h/matches username console-chat-id))
|
||||||
(not (.isMatches homoglyph-finder username wallet-chat-id)))))
|
(not (h/matches username wallet-chat-id)))))
|
||||||
|
|
||||||
(s/def ::not-empty-string (s/and string? not-empty))
|
(s/def ::not-empty-string (s/and string? not-empty))
|
||||||
(s/def ::not-illegal-name not-illegal-name?)
|
(s/def ::not-illegal-name not-illegal-name?)
|
||||||
|
|
||||||
(s/def ::name (s/and ::not-empty-string
|
(s/def ::name (s/and ::not-empty-string
|
||||||
::not-illegal-name))
|
::not-illegal-name))
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
(ns status-im.profile.validations
|
(ns status-im.profile.validations
|
||||||
(:require [cljs.spec :as s]
|
(:require [cljs.spec :as s]
|
||||||
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[status-im.utils.homoglyph :as h]))
|
||||||
(def homoglyph-finder (js/require "homoglyph-finder"))
|
|
||||||
|
|
||||||
(defn correct-name? [username]
|
(defn correct-name? [username]
|
||||||
(let [username (some-> username (str/trim))]
|
(let [username (some-> username (str/trim))]
|
||||||
(and (not (.isMatches homoglyph-finder username console-chat-id))
|
(and (not (h/matches username console-chat-id))
|
||||||
(not (.isMatches homoglyph-finder username wallet-chat-id)))))
|
(not (h/matches username wallet-chat-id)))))
|
||||||
|
|
||||||
(defn correct-email? [email]
|
(defn correct-email? [email]
|
||||||
(let [pattern #"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"]
|
(let [pattern #"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"]
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
(ns status-im.utils.homoglyph
|
||||||
|
(:require [status-im.utils.utils :as u]))
|
||||||
|
|
||||||
|
(def homoglyph-finder (u/require "homoglyph-finder"))
|
||||||
|
|
||||||
|
(defn matches [s1 s2]
|
||||||
|
(.isMatches homoglyph-finder s1 s2))
|
Loading…
Reference in New Issue