Compare commits
3 Commits
master
...
password-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c922ed596d | ||
|
|
cd30c937f0 | ||
|
|
6c262a03d9 |
@@ -33,8 +33,8 @@ const isFunction = (functionToCheck) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const requireAuth = (nextState, replace, next) => {
|
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)
|
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('/ride') > -1 && replace.params.ride_uuid !== undefined && replace.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();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +74,7 @@ const rootRoute = {
|
|||||||
require('./routes/500'),
|
require('./routes/500'),
|
||||||
require('./routes/confirmEmail'),
|
require('./routes/confirmEmail'),
|
||||||
require('./routes/forgotPassword'),
|
require('./routes/forgotPassword'),
|
||||||
|
require('./routes/resetPassword'),
|
||||||
require('./routes/lockScreen'),
|
require('./routes/lockScreen'),
|
||||||
require('./routes/login'),
|
require('./routes/login'),
|
||||||
require('./routes/signUp'),
|
require('./routes/signUp'),
|
||||||
|
|||||||
@@ -2,13 +2,33 @@ import React from 'react';
|
|||||||
import APPCONFIG from 'constants/Config';
|
import APPCONFIG from 'constants/Config';
|
||||||
import TextField from 'material-ui/TextField';
|
import TextField from 'material-ui/TextField';
|
||||||
import QueueAnim from 'rc-queue-anim';
|
import QueueAnim from 'rc-queue-anim';
|
||||||
|
import RaisedButton from 'material-ui/RaisedButton';
|
||||||
|
import Instance from '../../../components/Connection';
|
||||||
|
|
||||||
class ForgotPassowrd extends React.Component {
|
class ForgotPassowrd extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
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() {
|
render() {
|
||||||
@@ -24,6 +44,7 @@ class ForgotPassowrd extends React.Component {
|
|||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<TextField
|
<TextField
|
||||||
floatingLabelText="Email"
|
floatingLabelText="Email"
|
||||||
|
onChange={this.handleEmail}
|
||||||
type="email"
|
type="email"
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@@ -36,7 +57,12 @@ class ForgotPassowrd extends React.Component {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-action no-border text-right">
|
<div className="card-action no-border text-right">
|
||||||
<a href="/#/confirm-password" className="color-primary">Reset</a>
|
<RaisedButton
|
||||||
|
label="Reset"
|
||||||
|
primary={true}
|
||||||
|
onClick={this.clickEvent}
|
||||||
|
disabled={this.state.email===''}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
132
src/routes/resetPassword/components/ResetPassword.js
Normal file
132
src/routes/resetPassword/components/ResetPassword.js
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
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);
|
||||||
|
this.handlePass = this.handlePass.bind(this);
|
||||||
|
this.handleConfirmationPass = this.handleConfirmationPass.bind(this);
|
||||||
|
this.clickEvent = this.clickEvent.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonValidated = () => {
|
||||||
|
let validated = true;
|
||||||
|
if (!this.state.password_validated || !this.state.pass || this.state.pass === null || this.state.pass === "") validated = false;
|
||||||
|
|
||||||
|
this.setState(Object.assign(this.state, { validated: validated }));
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePass = (event) => {
|
||||||
|
this.setState(Object.assign(this.state, { pass: btoa(event.target.value) }));
|
||||||
|
this.setState(Object.assign(this.state, { password_validated: this.state.pass === this.state.passConfirmation }));
|
||||||
|
};
|
||||||
|
|
||||||
|
handleConfirmationPass = (event) => {
|
||||||
|
this.setState(Object.assign(this.state, { passConfirmation: btoa(event.target.value) }));
|
||||||
|
this.setState(Object.assign(this.state, { password_validated: this.state.pass === this.state.passConfirmation }));
|
||||||
|
};
|
||||||
|
|
||||||
|
clickEvent = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const state = this;
|
||||||
|
|
||||||
|
let user = {
|
||||||
|
"pass": this.state.pass,
|
||||||
|
};
|
||||||
|
|
||||||
|
Instance.setToken(null).post('/v1/passwordreset/complete/' + state.state.token, user).then(function (res) {
|
||||||
|
localStorage.removeItem('loggedUser');
|
||||||
|
location.href = '/#/login';
|
||||||
|
}).catch(function (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';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="body-inner">
|
||||||
|
<div className="card bg-white">
|
||||||
|
<div className="card-content">
|
||||||
|
<section className="logo text-center">
|
||||||
|
<h1><a href="#/">Reset Password</a></h1>
|
||||||
|
</section>
|
||||||
|
<form>
|
||||||
|
<fieldset>
|
||||||
|
<div className="form-group">
|
||||||
|
<TextField
|
||||||
|
floatingLabelText="Choose New Password"
|
||||||
|
type="password"
|
||||||
|
onChange={this.handlePass}
|
||||||
|
onBlur={this.buttonValidated}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
floatingLabelText="Verify New Password"
|
||||||
|
type="password"
|
||||||
|
onChange={this.handleConfirmationPass}
|
||||||
|
onBlur={this.buttonValidated}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div className="card-action no-border text-right">
|
||||||
|
<RaisedButton
|
||||||
|
label="Reset"
|
||||||
|
primary={true}
|
||||||
|
onClick={this.clickEvent}
|
||||||
|
disabled={!this.state.validated}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Page = () => (
|
||||||
|
<div className="page-forgot">
|
||||||
|
<div className="main-body">
|
||||||
|
<QueueAnim type="bottom" className="ui-animate">
|
||||||
|
<div key="1">
|
||||||
|
<ResetPassowrd />
|
||||||
|
</div>
|
||||||
|
</QueueAnim>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = Page;
|
||||||
|
|
||||||
8
src/routes/resetPassword/index.js
Normal file
8
src/routes/resetPassword/index.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
path: 'reset-password/:token',
|
||||||
|
getComponent(nextState, cb) {
|
||||||
|
require.ensure([], (require) => {
|
||||||
|
cb(null, require('./components/ResetPassword'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user