From 1298956d9295aa8c44d72941fb4d7ff82a496698 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 2 Nov 2022 13:14:42 +0100 Subject: [PATCH] :sparkles: Improve srepl helpers for activate profile --- backend/src/app/srepl/main.clj | 37 +++++++++++----------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index 707242f23..224a62333 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -65,31 +65,18 @@ (cmd.auth/send-email-verification! pool sprops profile) :email-sent)) -(defn update-profile! - "Update a limited set of profile attrs." - [system & {:keys [email id active? deleted? blocked?]}] - - (us/verify! - :expr (some? system) - :hint "system should be provided") - - (us/verify! - :expr (or (string? email) (uuid? id)) - :hint "email or id should be provided") - - (let [params (cond-> {} - (true? active?) (assoc :is-active true) - (false? active?) (assoc :is-active false) - (true? deleted?) (assoc :deleted-at (dt/now)) - (true? blocked?) (assoc :is-blocked true) - (false? blocked?) (assoc :is-blocked false)) - opts (cond-> {} - (some? email) (assoc :email (str/lower email)) - (some? id) (assoc :id id))] - - (db/with-atomic [conn (:app.db/pool system)] - (some-> (db/update! conn :profile params opts) - (profile/decode-profile-row))))) +(defn mark-profile-as-active! + "Mark the profile blocked and removes all the http sessiones + associated with the profile-id." + [system email] + (db/with-atomic [conn (:app.db/pool system)] + (when-let [profile (db/get-by-params conn :profile + {:email (str/lower email)} + {:columns [:id :email] + :check-not-found false})] + (when-not (:is-blocked profile) + (db/update! conn :profile {:is-active true} {:id (:id profile)}) + :activated)))) (defn mark-profile-as-blocked! "Mark the profile blocked and removes all the http sessiones