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.commands.utils :refer [reg-handler]]
|
||||
[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")
|
||||
|
||||
|
@ -75,13 +76,23 @@
|
|||
(map (fn [[k v]] [k (assoc v :type as)]))
|
||||
(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
|
||||
[db [id _ {:keys [commands responses autorun] :as data}]]
|
||||
[db [id _ {:keys [commands responses autorun]}]]
|
||||
(let [commands' (filter-forbidden-names id commands)
|
||||
responses' (filter-forbidden-names id responses)]
|
||||
(-> db
|
||||
(update-in [id :commands] merge (mark-as :command commands))
|
||||
(update-in [id :responses] merge (mark-as :response responses))
|
||||
(update-in [id :commands] merge (mark-as :command commands'))
|
||||
(update-in [id :responses] merge (mark-as :response responses'))
|
||||
(assoc-in [id :commands-loaded] true)
|
||||
(assoc-in [id :autorun] autorun)))
|
||||
(assoc-in [id :autorun] autorun))))
|
||||
|
||||
(defn save-commands-js!
|
||||
[_ [id file]]
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
(:require [cljs.spec :as s]
|
||||
[status-im.utils.phone-number :refer [valid-mobile-number?]]
|
||||
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(def homoglyph-finder (js/require "homoglyph-finder"))
|
||||
[clojure.string :as str]
|
||||
[status-im.utils.homoglyph :as h]))
|
||||
|
||||
(defn not-illegal-name? [username]
|
||||
(let [username (some-> username (str/trim))]
|
||||
(and (not (.isMatches homoglyph-finder username console-chat-id))
|
||||
(not (.isMatches homoglyph-finder username wallet-chat-id)))))
|
||||
(and (not (h/matches username console-chat-id))
|
||||
(not (h/matches username wallet-chat-id)))))
|
||||
|
||||
(s/def ::not-empty-string (s/and string? not-empty))
|
||||
(s/def ::not-illegal-name not-illegal-name?)
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
(ns status-im.profile.validations
|
||||
(:require [cljs.spec :as s]
|
||||
[status-im.constants :refer [console-chat-id wallet-chat-id]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(def homoglyph-finder (js/require "homoglyph-finder"))
|
||||
[clojure.string :as str]
|
||||
[status-im.utils.homoglyph :as h]))
|
||||
|
||||
(defn correct-name? [username]
|
||||
(let [username (some-> username (str/trim))]
|
||||
(and (not (.isMatches homoglyph-finder username console-chat-id))
|
||||
(not (.isMatches homoglyph-finder username wallet-chat-id)))))
|
||||
(and (not (h/matches username console-chat-id))
|
||||
(not (h/matches username wallet-chat-id)))))
|
||||
|
||||
(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])?"]
|
||||
|
|
|
@ -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