diff --git a/src/client.js b/src/client.js index 6c5e912..68a92e4 100644 --- a/src/client.js +++ b/src/client.js @@ -33,8 +33,8 @@ const isFunction = (functionToCheck) => { }; const requireAuth = (nextState, replace, next) => { - if (nextState.location.pathname === '/login' || nextState.location.pathname === '/sign-up' || nextState.location.pathname.toLowerCase() === '/selfregister' || (nextState.location.pathname.indexOf('/ride') > -1 && nextState.params.ride_uuid !== undefined && nextState.params.user_uuid !== undefined) - || (!isFunction(replace) && (replace.location.pathname === '/login' || replace.location.pathname === '/sign-up' || nextState.location.pathname.toLowerCase() === '/selfRegister' || (replace.location.pathname.indexOf('/ride') > -1 && replace.params.ride_uuid !== undefined && replace.params.user_uuid !== undefined)))) { + if (nextState.location.pathname === '/login' || nextState.location.pathname === '/sign-up' || nextState.location.pathname.toLowerCase() === '/selfregister' || (nextState.location.pathname.indexOf('/reset-password') > -1 && nextState.params.token !== undefined) || (nextState.location.pathname.indexOf('/ride') > -1 && nextState.params.ride_uuid !== undefined && nextState.params.user_uuid !== undefined) + || (!isFunction(replace) && (replace.location.pathname === '/login' || replace.location.pathname === '/sign-up' || nextState.location.pathname.toLowerCase() === '/selfRegister' || (replace.location.pathname.indexOf('/reset-password') > -1 && replace.params.token !== undefined) || (replace.location.pathname.indexOf('/ride') > -1 && replace.params.ride_uuid !== undefined && replace.params.user_uuid !== undefined)))) { next(); } diff --git a/src/routes/forgotPassword/components/ForgotPassword.js b/src/routes/forgotPassword/components/ForgotPassword.js index d1c0184..ef0d936 100644 --- a/src/routes/forgotPassword/components/ForgotPassword.js +++ b/src/routes/forgotPassword/components/ForgotPassword.js @@ -2,13 +2,33 @@ import React from 'react'; import APPCONFIG from 'constants/Config'; import TextField from 'material-ui/TextField'; import QueueAnim from 'rc-queue-anim'; +import RaisedButton from 'material-ui/RaisedButton'; +import Instance from '../../../components/Connection'; class ForgotPassowrd extends React.Component { constructor() { super(); this.state = { - brand: APPCONFIG.brand + brand: APPCONFIG.brand, + email: '', }; + + this.handleEmail = this.handleEmail.bind(this); + } + + handleEmail = (event) => { + this.setState(Object.assign(this.state, { email: event.target.value })); + }; + + clickEvent = (event) => { + event.preventDefault(); + + Instance.setToken(null).post('/v1/passwordreset/request/' + this.state.email).then(function (res) { + location.href = '/#/confirm-email'; + }).catch(function (err) { + location.href = '/#/confirm-email'; + }); + } render() { @@ -24,6 +44,7 @@ class ForgotPassowrd extends React.Component {
@@ -36,7 +57,12 @@ class ForgotPassowrd extends React.Component {
- Reset +
diff --git a/src/routes/resetPassword/components/ResetPassword.js b/src/routes/resetPassword/components/ResetPassword.js index 8218738..06d98b1 100644 --- a/src/routes/resetPassword/components/ResetPassword.js +++ b/src/routes/resetPassword/components/ResetPassword.js @@ -2,12 +2,17 @@ import React from 'react'; import TextField from 'material-ui/TextField'; import QueueAnim from 'rc-queue-anim'; import RaisedButton from 'material-ui/RaisedButton'; +import Instance from '../../../components/Connection'; class ResetPassowrd extends React.Component { constructor() { super(); this.state = { validated:false, + token:'', + pass:'', + passConfirmation:'', + password_validated:false, }; this.buttonValidated = this.buttonValidated.bind(this); @@ -34,41 +39,38 @@ class ResetPassowrd extends React.Component { }; clickEvent = (event) => { - location.href = '/#/login'; - /* event.preventDefault(); const state = this; let user = { - "provider": - { - "org_name": this.state.provider_name, - "internal_id": this.state.provider_npi - }, - "name": this.state.first + ' ' + this.state.last, - "first": this.state.first, - "last": this.state.last, - "email": this.state.email, - "phonenumber": this.state.phone_number, "pass": this.state.pass, }; - Instance.setToken(null).post('/v1/selfregister/', user).then(function (res) { + Instance.setToken(null).post('/v1/passworddreset/complete' + state.state.token, user).then(function (res) { localStorage.removeItem('loggedUser'); location.href = '/#/login'; }).catch(function (err) { - if (err.response.status === 422) { - //Unprocessable Entity (validation failed) - state.setState(Object.assign(state.state, { - showValidationErrors: true, - validationErrors: err.response.data.data - })); - } else { - alert('Error to log in: ' + err.message); - } - console.error(err); + console.log(err); + }); + } + + componentWillMount(){ + let urlParts = location.href.split('/'); + let token = urlParts[urlParts.length - 1]; + if (token.length < 1) { + token = urlParts[urlParts.length - 2] + } + + let state = this; + + + Instance.setToken(null).post('/v1/passwordreset/open/' + token).then(res=>{ + state.setState(Object.assign(state.state, { + token:token + })); + }).catch(err=>{ + location.href = '/#/404'; }); - */ } diff --git a/src/routes/resetPassword/index.js b/src/routes/resetPassword/index.js index 80ee4c1..fbeb0e9 100644 --- a/src/routes/resetPassword/index.js +++ b/src/routes/resetPassword/index.js @@ -1,5 +1,5 @@ module.exports = { - path: 'reset-password', + path: 'reset-password/:token', getComponent(nextState, cb) { require.ensure([], (require) => { cb(null, require('./components/ResetPassword'));