-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/forget-password' into dev
- Loading branch information
Showing
24 changed files
with
553 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router'; | ||
import { Field, reduxForm } from 'redux-form'; | ||
import Alert from 'react-bootstrap/lib/Alert'; | ||
import Button from 'react-bootstrap/lib/Button'; | ||
// import validator from 'validator'; | ||
import userAPI from '../../../api/user'; | ||
import { validateForm } from '../../../actions/formActions'; | ||
import { pushErrors } from '../../../actions/errorActions'; | ||
import { Form, FormField, FormFooter } from '../../utils/BsForm'; | ||
import configs from '../../../../../configs/project/client'; | ||
|
||
export let validate = (values) => { | ||
let errors = {}; | ||
|
||
// if (values.email && !validator.isEmail(values.email)) { | ||
// errors.email = 'Not an email'; | ||
// } | ||
|
||
if (!values.email) { | ||
errors.email = 'Required'; | ||
} | ||
|
||
if (configs.recaptcha && !values.recaptcha) { | ||
errors.recaptcha = 'Required'; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
let asyncValidate = (values, dispatch) => { | ||
return dispatch(validateForm('userForgetPassword', 'email', values.email)) | ||
.then((json) => { | ||
let validationError = {}; | ||
if (!json.isPassed) { | ||
validationError.email = json.message; | ||
throw validationError; | ||
} | ||
}); | ||
}; | ||
|
||
class ForgetPasswordForm extends Component { | ||
constructor() { | ||
super(); | ||
this.handleSubmit = this._handleSubmit.bind(this); | ||
} | ||
|
||
_handleSubmit(formData) { | ||
let { dispatch, apiEngine, initialize } = this.props; | ||
|
||
return userAPI(apiEngine) | ||
.requestResetPassword(formData) | ||
.catch((err) => { | ||
dispatch(pushErrors(err)); | ||
throw err; | ||
}) | ||
.then((json) => { | ||
initialize({ | ||
email: '', | ||
}); | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
handleSubmit, | ||
submitSucceeded, | ||
submitFailed, | ||
error, | ||
pristine, | ||
submitting, | ||
invalid, | ||
} = this.props; | ||
|
||
return ( | ||
<Form horizontal onSubmit={handleSubmit(this.handleSubmit)}> | ||
{submitSucceeded && ( | ||
<Alert bsStyle="success">A reset link is sent</Alert> | ||
)} | ||
{submitFailed && error && (<Alert bsStyle="danger">{error}</Alert>)} | ||
<Field | ||
label="Email" | ||
name="email" | ||
component={FormField} | ||
type="text" | ||
placeholder="Email" | ||
/> | ||
<Field | ||
label=" " | ||
name="recaptcha" | ||
component={FormField} | ||
type="recaptcha" | ||
/> | ||
<FormFooter> | ||
<Button type="submit" disabled={pristine || submitting || invalid}> | ||
Request An Email to Reset My Password | ||
</Button> | ||
<Link to="/user/login"> | ||
<Button bsStyle="link">Cancel</Button> | ||
</Link> | ||
</FormFooter> | ||
</Form> | ||
); | ||
} | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'userForgetPassword', | ||
validate, | ||
asyncValidate, | ||
asyncBlurFields: ['email'], | ||
})(connect(state => ({ | ||
apiEngine: state.apiEngine, | ||
}))(ForgetPasswordForm)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router'; | ||
import { Field, reduxForm } from 'redux-form'; | ||
import Alert from 'react-bootstrap/lib/Alert'; | ||
import Button from 'react-bootstrap/lib/Button'; | ||
import userAPI from '../../../api/user'; | ||
import { pushErrors } from '../../../actions/errorActions'; | ||
import { Form, FormField, FormFooter } from '../../utils/BsForm'; | ||
|
||
export const validate = (values) => { | ||
const errors = {}; | ||
|
||
if ( | ||
values.newPasswordConfirm && | ||
values.newPassword !== values.newPasswordConfirm | ||
) { | ||
errors.newPassword = errors.newPasswordConfirm = 'Password Not Matched'; | ||
} | ||
|
||
if (!values.newPassword) { | ||
errors.newPassword = 'Required'; | ||
} | ||
|
||
if (!values.newPasswordConfirm) { | ||
errors.newPasswordConfirm = 'Required'; | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
class ChangePasswordForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleSubmit = this._handleSubmit.bind(this); | ||
} | ||
|
||
_handleSubmit(formData) { | ||
let { dispatch, apiEngine, routing, initialize } = this.props; | ||
let location = routing.locationBeforeTransitions; | ||
|
||
return userAPI(apiEngine) | ||
.resetPassword({ | ||
...formData, | ||
token: location.query.token, | ||
}) | ||
.catch((err) => { | ||
dispatch(pushErrors(err)); | ||
throw err; | ||
}) | ||
.then((json) => { | ||
initialize({ | ||
newPassword: '', | ||
newPasswordConfirm: '', | ||
}); | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
handleSubmit, | ||
submitSucceeded, | ||
submitFailed, | ||
error, | ||
pristine, | ||
submitting, | ||
invalid, | ||
} = this.props; | ||
|
||
return ( | ||
<Form horizontal onSubmit={handleSubmit(this.handleSubmit)}> | ||
{submitSucceeded && ( | ||
<Alert bsStyle="success"> | ||
Password Changed. | ||
Go to <Link to="/user/login">login page</Link> now. | ||
</Alert> | ||
)} | ||
{submitFailed && error && (<Alert bsStyle="danger">{error}</Alert>)} | ||
<Field | ||
label="New Password" | ||
name="newPassword" | ||
component={FormField} | ||
type="password" | ||
disabled={submitSucceeded} | ||
placeholder="New Password" | ||
/> | ||
<Field | ||
label="New Password Confirm" | ||
name="newPasswordConfirm" | ||
component={FormField} | ||
type="password" | ||
disabled={submitSucceeded} | ||
placeholder="New Password Confirm" | ||
/> | ||
<FormFooter> | ||
<Button type="submit" disabled={pristine || submitting || invalid}> | ||
Reset | ||
{submitting && ( | ||
<i className="fa fa-spinner fa-spin" aria-hidden="true" /> | ||
)} | ||
</Button> | ||
</FormFooter> | ||
</Form> | ||
); | ||
} | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'userResetPassword', | ||
validate, | ||
})(connect(state => ({ | ||
apiEngine: state.apiEngine, | ||
routing: state.routing, | ||
}))(ChangePasswordForm)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import PageHeader from 'react-bootstrap/lib/PageHeader'; | ||
import PageLayout from '../../layouts/PageLayout'; | ||
import ForgetPasswordForm from '../../forms/user/ForgetPasswordForm'; | ||
|
||
let ForgetPasswordPage = () => ( | ||
<PageLayout> | ||
<PageHeader>Forget Password</PageHeader> | ||
<ForgetPasswordForm /> | ||
</PageLayout> | ||
); | ||
|
||
export default ForgetPasswordPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import PageHeader from 'react-bootstrap/lib/PageHeader'; | ||
import PageLayout from '../../layouts/PageLayout'; | ||
import ResetPasswordForm from '../../forms/user/ResetPasswordForm'; | ||
|
||
let ResetPasswordPage = (props) => ( | ||
<PageLayout> | ||
<PageHeader>Reset Password</PageHeader> | ||
<ResetPasswordForm /> | ||
</PageLayout> | ||
); | ||
|
||
export default ResetPasswordPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default (store) => ({ | ||
path: 'password/forget', | ||
getComponent(nextState, cb) { | ||
require.ensure([], (require) => { | ||
cb( | ||
null, | ||
require('../../components/pages/user/ForgetPasswordPage').default | ||
); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default (store) => ({ | ||
path: 'password/reset', | ||
getComponent(nextState, cb) { | ||
require.ensure([], (require) => { | ||
cb( | ||
null, | ||
require('../../components/pages/user/ResetPasswordPage').default | ||
); | ||
}); | ||
}, | ||
}); |
4 changes: 2 additions & 2 deletions
4
src/common/routes/user/verification.js → src/common/routes/user/verifyEmail.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export default (store) => ({ | ||
path: 'verification', | ||
path: 'email/verify', | ||
getComponent(nextState, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, require('../../components/pages/user/VerificationPage').default); | ||
cb(null, require('../../components/pages/user/VerifyEmailPage').default); | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.