diff --git a/README.md b/README.md index 589d377..1e2731f 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,18 @@ The admin api only allows the creating of users using the email/password sign-in ;; :disabled false ;;} +(charm-admin/create-user "email@domain.com" "superstrong6characterpassword" "my-very-own-custom-uuid") +;;{ +;; :email email@domain.com +;; :email-verified false +;; :uid my-very-own-custom-uuid +;; :provider-id firebase +;; :photo-url nil +;; :phone-number nil +;; :display-name nil +;; :disabled false +;;} + (charm-admin/get-user "vMnMJvS28kWr5pb6sByHULMLelJ3") ;;{ ;; :email email@domain.com diff --git a/project.clj b/project.clj index 066968c..f5fc65c 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject alekcz/charmander "1.0.4" +(defproject alekcz/charmander "1.0.5" :description "Charmander: a set of libraries to make working with firebase easier in clojure" :url "https://github.com/alekcz/charmander" :license {:name "Eclipse Public License" diff --git a/src/charmander/admin.clj b/src/charmander/admin.clj index e2c3918..b5443a5 100644 --- a/src/charmander/admin.clj +++ b/src/charmander/admin.clj @@ -42,13 +42,22 @@ (catch Exception e (println "\nError: FIREBASE_CONFIG/GOOGLE_APPLICATION_CREDENTIALS AND GOOGLE_CLOUD_PROJECT environment variables must both be set"))))) -(defn- build-create-user-request [email password] - (let [create-request (new UserRecord$CreateRequest)] - (doto create-request ;doto mutates the object. Use it when you're going to return the object - (.setEmail email) - (.setPassword password) - (.setEmailVerified false) - (.setDisabled false)))) +(defn- build-create-user-request + ([email password] + (let [create-request (new UserRecord$CreateRequest)] + (doto create-request ;doto mutates the object. Use it when you're going to return the object + (.setEmail email) + (.setPassword password) + (.setEmailVerified false) + (.setDisabled false)))) + ([email password uid] + (let [create-request (new UserRecord$CreateRequest)] + (doto create-request ;doto mutates the object. Use it when you're going to return the object + (.setUid uid) + (.setEmail email) + (.setPassword password) + (.setEmailVerified false) + (.setDisabled false))))) (defn- convert-user-record-to-map [^UserRecord user-record] { :email (. user-record getEmail) @@ -84,12 +93,19 @@ ; user management api -(defn create-user [email password] - (try - (let [firebase-auth (. FirebaseAuth getInstance) - create-request (build-create-user-request email password)] - (convert-user-record-to-map (. firebase-auth createUser create-request))) - (catch Exception e {:error true :error-data (format-error e)}))) +(defn create-user + ([email password] + (try + (let [firebase-auth (. FirebaseAuth getInstance) + create-request (build-create-user-request email password)] + (convert-user-record-to-map (. firebase-auth createUser create-request))) + (catch Exception e {:error true :error-data (format-error e)}))) + ([email password uid] + (try + (let [firebase-auth (. FirebaseAuth getInstance) + create-request (build-create-user-request email password uid)] + (convert-user-record-to-map (. firebase-auth createUser create-request))) + (catch Exception e {:error true :error-data (format-error e)})))) (defn delete-user [uuid] (try diff --git a/test/charmander/admin_test.clj b/test/charmander/admin_test.clj index a6e1c30..316030a 100644 --- a/test/charmander/admin_test.clj +++ b/test/charmander/admin_test.clj @@ -15,7 +15,7 @@ "Template for tests" (deftest test-tempate - (testing "Testing functionname" + (testing "Testing function name" (let [data "" other ""] (do (is (= (#'charmander.admin/privatefunction inputs) answer)) @@ -40,7 +40,17 @@ (is (= (:email response) (str unique "@domain.com"))) (is (not (= response response2))) (#'charmander.admin/delete-user (:uid response))))))) - + +(deftest test-create-user-with-uid + (testing "Testing the creating of new users with uid" + (let [unique (str (uuid/v1) "-" (uuid/v1))] + (let [response (#'charmander.admin/create-user (str unique "@domain.com") "superDuperSecure" unique) + response2 (#'charmander.admin/create-user (str unique "+other@domain.com") "superDuperSecure" unique)] + (do + (is (= (:email response) (str unique "@domain.com"))) + (is (not (= response response2))) + (#'charmander.admin/delete-user unique)))))) + (deftest test-all-get-users (testing "Testing the retrieval of user by uid or by email" (let [unique (str (uuid/v1))] diff --git a/test/charmander/admin_test_2.clj b/test/charmander/admin_test_2.clj index b6aedf3..a8a9cf7 100644 --- a/test/charmander/admin_test_2.clj +++ b/test/charmander/admin_test_2.clj @@ -15,7 +15,7 @@ "Template for tests" (deftest test-tempate - (testing "Testing functionname" + (testing "Testing function name" (let [data "" other ""] (do (is (= (#'charmander.admin/privatefunction inputs) answer)) @@ -40,7 +40,17 @@ (is (= (:email response) (str unique "@domain.com"))) (is (not (= response response2))) (#'charmander.admin/delete-user (:uid response))))))) - + +(deftest test-create-user-with-uid + (testing "Testing the creating of new users with uid" + (let [unique (str (uuid/v1) "-" (uuid/v1))] + (let [response (#'charmander.admin/create-user (str unique "@domain.com") "superDuperSecure" unique) + response2 (#'charmander.admin/create-user (str unique "+other@domain.com") "superDuperSecure" unique)] + (do + (is (= (:email response) (str unique "@domain.com"))) + (is (not (= response response2))) + (#'charmander.admin/delete-user unique)))))) + (deftest test-all-get-users (testing "Testing the retrieval of user by uid or by email" (let [unique (str (uuid/v1))]