wip forgot password
This commit is contained in:
parent
8b350ca3b6
commit
33d0de6f0c
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue