diff --git a/src/source/routes/google_user.clj b/src/source/routes/google_user.clj index e24c311..69fad54 100644 --- a/src/source/routes/google_user.clj +++ b/src/source/routes/google_user.clj @@ -31,24 +31,57 @@ (let [{:keys [uuid _uri]} body email (google/google-session-user uuid (:params req)) + _ (prn "email from google" email) user (hon/find-one ds {:tname :users :where [:= :email email]}) - user-type (get-in req [:cookies "user_type" :value])] + _ (prn "try find user, got:" user) + user-type (get-in req [:cookies "user_type" :value]) + _ (prn "user-type" user-type)] (if (some? user) (let [payload (dissoc user :password) session (auth/create-session payload)] + (prn "found a user, sending response") (res/response (merge {:user payload} session))) (do + (prn "no user, inserting user with email hash" email (pw/hash-password email) user-type) (hon/insert! ds {:tname :users :data {:email email + :email-hash (pw/hash-password email) :type user-type}}) + (prn "inserted user") (let [new-user (hon/find-one ds {:tname :users :where [:= :email email]}) + _ (prn "retrieved new user" new-user) payload (dissoc new-user :password) + _ (prn "user without password" payload) session (auth/create-session payload)] + (prn "session" session) + (prn "going to send email with" (pw/hash-password email) "to" email) (gmail/send-email {:to email :subject "Source - Verify your email" :body (templates/email-verification {:email-hash (pw/hash-password email)}) :type :text/html}) + (prn "sent email with" (pw/hash-password email) "to" email) (res/response (merge {:user payload} session))))))) + +(comment + (require '[source.db.util :as db.util]) + + (def ds (db.util/conn)) + (hon/insert! ds {:tname :users + :data {:email "merv@simply.co.za" + :email-hash (pw/hash-password "merv@simply.co.za") + :type "creator"}}) + (hon/find-one ds {:tname :users + :where [:= :email "merv@simply.co.za"]}) + (let [new-user (hon/find-one ds {:tname :users + :where [:= :email "merv@simply.co.za"]}) + payload (dissoc new-user :password) + session (auth/create-session payload)] + #_(gmail/send-email {:to email + :subject "Source - Verify your email" + :body (templates/email-verification {:email-hash (pw/hash-password email)}) + :type :text/html}) + (res/response (merge {:user payload} session))) + ()) diff --git a/src/source/routes/user.clj b/src/source/routes/user.clj index 173f48c..cb60f9c 100644 --- a/src/source/routes/user.clj +++ b/src/source/routes/user.clj @@ -74,14 +74,19 @@ 403 {:body (api/response-schema)}}} [{:keys [ds path-params]}] (let [email-hash (:hash path-params) + _ (prn "email hash from path params" email-hash) user (hon/find-one ds {:tname :users - :where [:= :email-hash email-hash]})] + :where [:= :email-hash email-hash]}) + _ (prn "found user by email hash" user)] (if (some? user) (do + (prn "a user exists, updating user details") (hon/update! ds {:tname :users :where [:= :id (:id user)] :data {:email-verified 1 :email-hash ""}}) + (prn "user has been updated") + (prn "running redirect") (-> (conf/read-value :cors-origin) (str "/dashboard/onboarding") (res/redirect)))