diff --git a/jam-ui/src/components/auth/ForgetPasswordForm.js b/jam-ui/src/components/auth/ForgetPasswordForm.js index bdbbf95f1..225c7ce94 100644 --- a/jam-ui/src/components/auth/ForgetPasswordForm.js +++ b/jam-ui/src/components/auth/ForgetPasswordForm.js @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'; import { toast } from 'react-toastify'; import { Button, Form, FormGroup, Input } from 'reactstrap'; import withRedirect from '../../hoc/withRedirect'; +import { resetPassword } from '../../helpers/rest'; const ForgetPasswordForm = ({ setRedirect, setRedirectUrl, layout }) => { // State @@ -13,8 +14,14 @@ const ForgetPasswordForm = ({ setRedirect, setRedirectUrl, layout }) => { const handleSubmit = e => { e.preventDefault(); if (email) { - toast.success(`An email is sent to ${email} with password reset link`); - setRedirect(true); + resetPassword(email) + .then(() => { + toast.success(`An email is sent to ${email} with password reset link`); + setRedirect(true); + }) + .catch(error => { + toast.error(error.message); + }); } }; diff --git a/jam-ui/src/helpers/rest.js b/jam-ui/src/helpers/rest.js index 518419498..2b944bf5d 100644 --- a/jam-ui/src/helpers/rest.js +++ b/jam-ui/src/helpers/rest.js @@ -298,9 +298,9 @@ export const requestPasswordReset = userId => { }); }; -export const resetPassword = (userId, email) => { +export const resetPassword = email => { return new Promise((resolve, reject) => { - apiFetch(`/users/${userId}/reset_password`, { + apiFetch(`/users/reset_password`, { method: 'POST', body: JSON.stringify({ email }) }) diff --git a/web/app/controllers/api_sessions_controller.rb b/web/app/controllers/api_sessions_controller.rb index ae4a67fc2..5fe58f10a 100644 --- a/web/app/controllers/api_sessions_controller.rb +++ b/web/app/controllers/api_sessions_controller.rb @@ -17,4 +17,14 @@ class ApiSessionsController < ApiController render :json => {}, :status => :ok end end + + def request_reset_password + begin + User.reset_password(params[:email], ApplicationHelper.base_uri(request)) + rescue JamRuby::JamArgumentError + render :json => {:message => ValidationMessages::EMAIL_NOT_FOUND}, :status => 403 + end + render :json => {}, :status => 204 + end + end diff --git a/web/config/routes.rb b/web/config/routes.rb index 1137f301c..022ffe75a 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -31,6 +31,8 @@ Rails.application.routes.draw do post '/signin', to: 'sessions#create' delete '/signout', to: 'sessions#destroy' get '/passthrough', to: 'sessions#passthrough' + + post '/request_reset_password', to: 'api_sessions#request_reset_password' match '/redeem_giftcard', to: 'landings#redeem_giftcard', via: :get match '/account/activate/code_old', to: 'landings#account_activate', via: :get