From d98fd76032b0afa6a84bd613418b9011257689c0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 19 Jan 2023 12:41:06 +0100 Subject: [PATCH] :tada: Add namespace with a set of helpers for access throught the BREPL --- backend/src/app/srepl.clj | 1 + backend/src/app/srepl/ext.clj | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 backend/src/app/srepl/ext.clj diff --git a/backend/src/app/srepl.clj b/backend/src/app/srepl.clj index cd5838a76..5885fa369 100644 --- a/backend/src/app/srepl.clj +++ b/backend/src/app/srepl.clj @@ -10,6 +10,7 @@ [app.common.logging :as l] [app.common.spec :as us] [app.config :as cf] + [app.srepl.ext] [app.srepl.main] [app.util.json :as json] [app.util.locks :as locks] diff --git a/backend/src/app/srepl/ext.clj b/backend/src/app/srepl/ext.clj new file mode 100644 index 000000000..739491257 --- /dev/null +++ b/backend/src/app/srepl/ext.clj @@ -0,0 +1,44 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns app.srepl.ext + "PREPL API for external usage (CLI or ADMIN)" + (:require + [app.auth :as auth] + [app.common.uuid :as uuid] + [app.db :as db] + [app.rpc.commands.auth :as cmd.auth])) + +(defn- get-current-system + [] + (or (deref (requiring-resolve 'app.main/system)) + (deref (requiring-resolve 'user/system)))) + +(defn derive-password + [password] + (auth/derive-password password)) + +(defn create-profile + [fullname, email, password] + (when-let [system (get-current-system)] + (db/with-atomic [conn (:app.db/pool system)] + (let [params {:id (uuid/next) + :email email + :fullname fullname + :is-active true + :password password + :props {}} + + profile (->> (cmd.auth/create-profile conn params) + (cmd.auth/create-profile-relations conn))] + + (str (:id profile)))))) + + + + + +