 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defn create-user
-  [conn {:keys [username password email] :as data}]
-  (let [sql (str "INSERT INTO users (username, email, password)"
-                 " VALUES (?, ?, ?) RETURNING *;")
-        ;; password (hashers/encrypt password)
-        sqlv [sql username email password]]
+  [conn {:keys [id username password email] :as data}]
+  {:pre [(us/validate! data +user-schema+)]}
+  (let [sql (str "INSERT INTO users (id, username, email, password)"
+                 " VALUES (?, ?, ?, ?) RETURNING *;")
+        id (or id (uuid/v4))
+        sqlv [sql id username email password]]
     (some-> (sc/fetch-one conn sqlv)
             (usc/normalize-attrs))))
 

(ns uxbox.services.auth
  (:require [mount.core :as mount :refer (defstate)]
            [suricatta.core :as sc]
            [buddy.hashers :as hashers]
            [buddy.sign.jwe :as jwe]
            [buddy.core.nonce :as nonce]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(def +user-schema+
  {:id [us/uuid]
   :username [us/required us/string]
   :email [us/required us/email]
   :password [us/required us/string]})

