diff --git a/imports/startup/server/accounts.js b/imports/startup/server/accounts.js new file mode 100644 index 0000000..6d7b5ad --- /dev/null +++ b/imports/startup/server/accounts.js @@ -0,0 +1,28 @@ +import { Meteor } from 'meteor/meteor'; +import { Accounts } from 'meteor/accounts-base'; + +const name = 'Application Name'; +const email = ''; +const from = `${name} ${email}`; +const emailTemplates = Accounts.emailTemplates; + +emailTemplates.siteName = name; +emailTemplates.from = from; + +emailTemplates.resetPassword = { + subject() { + return `[${name}] Reset Your Password`; + }, + text(user, url) { + const userEmail = user.emails[0].address; + const urlWithoutHash = url.replace('#/', ''); + + if (Meteor.isDevelopment) console.info(`Reset Password Link: ${urlWithoutHash}`); + + return `A password reset has been requested for the account related to this + address (${userEmail}). To reset the password, visit the following link: + \n\n${urlWithoutHash}\n\n If you did not request this reset, please ignore + this email. If you feel something is wrong, please contact our support team: + ${email}.`; + }, +}; diff --git a/imports/startup/server/index.js b/imports/startup/server/index.js index b4ab10a..9696159 100644 --- a/imports/startup/server/index.js +++ b/imports/startup/server/index.js @@ -1,2 +1,3 @@ +import './accounts'; import './api'; import './fixtures'; diff --git a/imports/ui/pages/ResetPassword/ResetPassword.js b/imports/ui/pages/ResetPassword/ResetPassword.js index e69de29..c6b07e5 100644 --- a/imports/ui/pages/ResetPassword/ResetPassword.js +++ b/imports/ui/pages/ResetPassword/ResetPassword.js @@ -0,0 +1,99 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Row, Col, Alert, FormGroup, ControlLabel, Button } from 'react-bootstrap'; +import { Accounts } from 'meteor/accounts-base'; +import { Bert } from 'meteor/themeteorchef:bert'; +import validate from '../../../modules/validate'; + +class ResetPassword extends React.Component { + constructor(props) { + super(props); + this.handleSubmit = this.handleSubmit.bind(this); + } + + componentDidMount() { + const component = this; + + validate(component.form, { + rules: { + newPassword: { + required: true, + minlength: 6, + }, + repeatNewPassword: { + required: true, + minlength: 6, + equalTo: '[name="newPassword"]', + }, + }, + messages: { + newPassword: { + required: 'Enter a new password, please.', + minlength: 'Use at least six characters, please.', + }, + repeatNewPassword: { + required: 'Repeat your new password, please.', + equalTo: 'Hmm, your passwords don\'t match. Try again?', + }, + }, + submitHandler() { component.handleSubmit(); }, + }); + } + + handleSubmit() { + const { match, history } = this.props; + const token = match.params.token; + + Accounts.resetPassword(token, this.newPassword.value, (error) => { + if (error) { + Bert.alert(error.reason, 'danger'); + } else { + history.push('/documents'); + } + }); + } + + render() { + return (
+ + +

Reset Password

+ + To reset your password, enter a new one below. You will be logged in +with your new password. + +
(this.form = form)} onSubmit={event => event.preventDefault()}> + + New Password + (this.newPassword = newPassword)} + name="newPassword" + placeholder="New Password" + /> + + + Repeat New Password + (this.repeatNewPassword = repeatNewPassword)} + name="repeatNewPassword" + placeholder="Repeat New Password" + /> + + +
+ +
+
); + } +} + +ResetPassword.propTypes = { + match: PropTypes.object.isRequired, + history: PropTypes.object.isRequired, +}; + +export default ResetPassword;