I am using Meteor 1.3 with React and react-router
so I have a customized Accounts package. I am trying to confirm a user’s registration through an admin, and have the admin send the user an email with a link to set the user’s password. I take it I need to render the enrollAccount template but I’m not sure what data it needs (params
, etc.). I am currently rendering the at_form
template through React by called AccountsTemplates.setState(‘enrollAccount’), etc. What params
would I need for this to work properly? I am creating the user server-side with Meteor.createUser
, without a password, so I have the user’s userId
Basically, Accounts.sendEnrollmentEmail
will set a Random.secret()
within the user’s 'services.password.reset.token'
field. You search for a user with a specified token to get the person who is supposed to be registered.
The route will probably look like /enroll-account/:token
, where token
is this secret that was set on the user. You can subscribe with this parameter
Meteor.users.find({
'services.password.reset.token': params.token
});
2 Likes
So what I ended up doing is this:
- on the server, after the user is created, call
Accounts.sendEnrollmentEmail(userId)
- configure mail settings to give the correct URL - this is because the default URL doesn’t look nice in
react-router
-
Accounts.emailTemplates.enrollAccount.text = function(user, url) { var id = url.substring(url.lastIndexOf('/') + 1) return `Click this link to set your password and start using the service: ${process.env.BASE_URL}/enroll-account/${id}` }
- Then create a component
EnrollAccount
and link to it throughreact-router
-
import React from 'react'; import ReactDOM from 'react-dom'; import {browserHistory, Link,} from 'react-router'; import AccountsWrapper from './accounts_wrapper.jsx'; class EnrollAccount extends React.Component{ componentWillMount(){ let {nextPath, location,} = this.props; let nextPathProps = location.state ? location.state.nextPath : nextPath; Accounts._resetPasswordToken = this.props.params.token; AccountsTemplates.setState('enrollAccount') } render(){ let {nextPath, location,} = this.props; let nextPathProps = location.state ? location.state.nextPath : nextPath; if (this.state.loggedIn == true || this.props.loggingIn || !!this.props.currentUser || !! Meteor.userId()) { browserHistory.push(nextPathProps); } return () } } module.exports = EnrollAccount;
- Finally, wrap the AccountsTemplates
import React from 'react'; import ReactDOM from 'react-dom'; import ReactMixin from 'react-mixin'; import {Navigation,} from 'react-router'; class AccountsWrapper extends React.Component{ componentDidMount(){ this.view = Blaze.renderWithData(Template.atForm, {token: this.props.token ? this.props.token : ''}, ReactDOM.findDOMNode(this.refs.container)) } componentWillUnmount(){ Blaze.remove(this.view); } render(){ return; } } let styles = { formContainer: { backgroundColor: 'white', width: 'inherit', maxWidth: '30rem', paddingLeft: 20, paddingRight: 20, marginTop: 20, marginLeft: 'auto', marginRight: 'auto', paddingTop: '1rem', paddingBottom: '1rem', borderRadius: 4, } } module.exports = AccountsWrapper;
1 Like