From 4e271603c2b795b1173c2dad407de4a0ae8d3bc1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 Jan 2021 14:34:20 +0100 Subject: [PATCH] :tada: Add helper to devenv for properly reset passwords. --- backend/src/app/rpc/mutations/profile.clj | 4 ++-- backend/src/app/srepl/dev.clj | 16 ++++++++++++++++ backend/src/app/srepl/main.clj | 7 ++++--- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 backend/src/app/srepl/dev.clj diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 48189798c..72461a407 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -140,7 +140,7 @@ :code :email-already-exists)) params)) -(defn- derive-password +(defn derive-password [password] (hashers/derive password {:alg :argon2id @@ -148,7 +148,7 @@ :iterations 20 :parallelism 2})) -(defn- verify-password +(defn verify-password [attempt password] (try (hashers/verify attempt password) diff --git a/backend/src/app/srepl/dev.clj b/backend/src/app/srepl/dev.clj new file mode 100644 index 000000000..0e1045f1d --- /dev/null +++ b/backend/src/app/srepl/dev.clj @@ -0,0 +1,16 @@ +(ns app.srepl.dev + #_:clj-kondo/ignore + (:require + [app.db :as db] + [app.config :as cfg] + [app.rpc.mutations.profile :refer [derive-password]] + [app.main :refer [system]])) + +(defn reset-passwords + [system] + (when (not= "devenv" (:host cfg/config)) + (throw (ex-info "Can't proceed, only allowed this operation on devenv" {}))) + (db/with-atomic [conn (:app.db/pool system)] + (let [password (derive-password "123123")] + (db/exec! conn ["update profile set password=?" password])))) + diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index aeded7b49..7225bbf5d 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -2,12 +2,13 @@ "A main namespace for server repl." #_:clj-kondo/ignore (:require - [clojure.pprint :refer [pprint]] + [app.common.pages :as cp] + [app.common.pages.migrations :as pmg] [app.db :as db] [app.main :refer [system]] - [app.common.pages.migrations :as pmg] + [app.srepl.dev :as dev] [app.util.blob :as blob] - [app.common.pages :as cp])) + [clojure.pprint :refer [pprint]])) (defn update-file ([id f] (update-file id f false))