diff --git a/src/uxbox/data/auth.cljs b/src/uxbox/data/auth.cljs index 9cb2e0ae5..4353c8633 100644 --- a/src/uxbox/data/auth.cljs +++ b/src/uxbox/data/auth.cljs @@ -118,3 +118,27 @@ (if errors (udf/assign-errors :register errors) (Register. data)))) + +;; --- Recovery Request + +(defrecord RecoveryRequest [data] + rs/WatchEvent + (-apply-watch [_ state stream] + (letfn [(on-error [{payload :payload}] + (println "on-error" payload) + (->> (:payload payload) + (udf/assign-errors :recovery-request) + (rx/of)))] + (rx/merge + (->> (rp/req :auth/recovery-request data) + (rx/map (constantly ::recovery-requested)) + (rx/catch rp/client-error? on-error)) + (->> stream + (rx/filter #(= % ::recovery-requested)) + (rx/take 1) + (rx/do #(udm/info! (tr "auth.message.recovery-token-sent"))) + (rx/map #(udf/clean :recovery-request))))))) + +(defn recovery-request + [data] + (RecoveryRequest. data)) diff --git a/src/uxbox/locales/en.cljs b/src/uxbox/locales/en.cljs index 7b7ec93e3..a3ec3d961 100644 --- a/src/uxbox/locales/en.cljs +++ b/src/uxbox/locales/en.cljs @@ -44,6 +44,8 @@ "ds.help.circle" "Circle (Ctrl + E)" "ds.help.line" "Line (Ctrl + L)" + "auth.message.recovery-token-sent" "Password recovery link sent to your inbox." + "settings.profile" "PROFILE" "settings.password" "PASSWORD" "settings.notifications" "NOTIFICATIONS" @@ -54,6 +56,7 @@ "errors.api.form.old-password-not-match" "Incorrect old password" "errors.api.form.email-already-exists" "The email is already in use by other user." "errors.api.form.username-already-exists" "The username is already in use by other user." + "errors.api.form.user-not-exists" "Username or email does not matches any existing user." "errors.form.required" "This field is mandatory" "errors.form.string" "Should be string" "errors.form.number" "Invalid number" diff --git a/src/uxbox/repo/auth.cljs b/src/uxbox/repo/auth.cljs index 4189ace27..ca0848de0 100644 --- a/src/uxbox/repo/auth.cljs +++ b/src/uxbox/repo/auth.cljs @@ -37,3 +37,10 @@ :method :post :body data}] (send! params))) + +(defmethod request :auth/recovery-request + [_ data] + (let [params {:url (str url "/auth/recovery") + :method :post + :body data}] + (send! params))) diff --git a/src/uxbox/router.cljs b/src/uxbox/router.cljs index 87d79030e..5d993b25b 100644 --- a/src/uxbox/router.cljs +++ b/src/uxbox/router.cljs @@ -61,7 +61,7 @@ (def routes ["/" [["auth/login" :auth/login] ["auth/register" :auth/register] - ["auth/recover" :auth/recover-password] + ["auth/recovery-request" :auth/recovery-request] ["settings/" [["profile" :settings/profile] ["password" :settings/password] diff --git a/src/uxbox/ui.cljs b/src/uxbox/ui.cljs index e5f973141..7a8b750bd 100644 --- a/src/uxbox/ui.cljs +++ b/src/uxbox/ui.cljs @@ -31,7 +31,11 @@ ;; --- Constants -(def ^:const +unrestricted+ #{:auth/login :auth/register}) +(def ^:const +unrestricted+ + #{:auth/login + :auth/register + :auth/recovery-request + :auth/recovery}) (def ^:const restricted? (complement +unrestricted+)) (def route-l @@ -78,6 +82,8 @@ (case location :auth/login (auth/login-page) :auth/register (auth/register-page) + :auth/recovery-request (auth/recovery-request-page) + ;; :auth/recovery (auth/recovery-page) :dashboard/projects (dashboard/projects-page) :dashboard/elements (dashboard/elements-page) :dashboard/icons (dashboard/icons-page) diff --git a/src/uxbox/ui/auth.cljs b/src/uxbox/ui/auth.cljs index 19f4f2c6f..a577b38fe 100644 --- a/src/uxbox/ui/auth.cljs +++ b/src/uxbox/ui/auth.cljs @@ -6,7 +6,9 @@ (ns uxbox.ui.auth (:require [uxbox.ui.auth.login :as login] - [uxbox.ui.auth.register :as register])) + [uxbox.ui.auth.register :as register] + [uxbox.ui.auth.recovery :as recovery])) (def login-page login/login-page) (def register-page register/register-page) +(def recovery-request-page recovery/recovery-request-page) diff --git a/src/uxbox/ui/auth/login.cljs b/src/uxbox/ui/auth/login.cljs index 9725b6d58..8c38d3710 100644 --- a/src/uxbox/ui/auth/login.cljs +++ b/src/uxbox/ui/auth/login.cljs @@ -71,7 +71,7 @@ :value "Continue" :type "submit"}] [:div.login-links - [:a {:on-click #(rt/go :auth/recover-password)} "Forgot your password?"] + [:a {:on-click #(rt/go :auth/recovery-request)} "Forgot your password?"] [:a {:on-click #(rt/go :auth/register)} "Don't have an account?"]]]]]]))) (defn- login-page-will-mount diff --git a/src/uxbox/ui/auth/register.cljs b/src/uxbox/ui/auth/register.cljs index 791c5b8cd..ab463298c 100644 --- a/src/uxbox/ui/auth/register.cljs +++ b/src/uxbox/ui/auth/register.cljs @@ -23,7 +23,6 @@ [uxbox.ui.mixins :as mx] [uxbox.util.dom :as dom])) - ;; --- Constants (def form-data