diff --git a/imports/helpers.js b/imports/helpers.js index 7529374..6e552e6 100644 --- a/imports/helpers.js +++ b/imports/helpers.js @@ -4,7 +4,8 @@ export const STATES = { SIGN_UP: Symbol('SIGN_UP'), PROFILE: Symbol('PROFILE'), PASSWORD_CHANGE: Symbol('PASSWORD_CHANGE'), - PASSWORD_RESET: Symbol('PASSWORD_RESET') + PASSWORD_RESET: Symbol('PASSWORD_RESET'), + ENROLL_ACCOUNT: Symbol('ENROLL_ACCOUNT') }; export function getLoginServices() { diff --git a/imports/ui/components/LoginForm.jsx b/imports/ui/components/LoginForm.jsx index fe188d8..0a70817 100644 --- a/imports/ui/components/LoginForm.jsx +++ b/imports/ui/components/LoginForm.jsx @@ -55,6 +55,11 @@ export class LoginForm extends Tracker.Component { let changeState = Session.get(KEY_PREFIX + 'state'); switch (changeState) { case 'enrollAccountToken': + this.setState({ + formState: STATES.ENROLL_ACCOUNT + }); + Session.set(KEY_PREFIX + 'state', null); + break; case 'resetPasswordToken': this.setState({ formState: STATES.PASSWORD_CHANGE @@ -165,6 +170,17 @@ export class LoginForm extends Tracker.Component { }; } + getSetPasswordField() { + return { + id: 'newPassword', + hint: T9n.get('enterPassword'), + label: T9n.get('choosePassword'), + type: 'password', + required: true, + onChange: this.handleChange.bind(this, 'newPassword') + }; + } + getNewPasswordField() { return { id: 'newPassword', @@ -263,13 +279,16 @@ export class LoginForm extends Tracker.Component { } if (this.showPasswordChangeForm()) { - if (Meteor.isClient && !Accounts._loginButtonsSession.get('resetPasswordToken') - && !Accounts._loginButtonsSession.get('enrollAccountToken')) { + if (Meteor.isClient && !Accounts._loginButtonsSession.get('resetPasswordToken')) { loginFields.push(this.getPasswordField()); } loginFields.push(this.getNewPasswordField()); } + if (this.showEnrollAccountForm()) { + loginFields.push(this.getSetPasswordField()); + } + return _.indexBy(loginFields, 'id'); } @@ -370,10 +389,10 @@ export class LoginForm extends Tracker.Component { }); } - if (this.showPasswordChangeForm()) { + if (this.showPasswordChangeForm() || this.showEnrollAccountForm()) { loginButtons.push({ id: 'changePassword', - label: T9n.get('changePassword'), + label: (this.showPasswordChangeForm() ? T9n.get('changePassword') : T9n.get('setPassword')), type: 'submit', disabled: waiting, onClick: this.passwordChange.bind(this) @@ -410,6 +429,11 @@ export class LoginForm extends Tracker.Component { && this.state.formState == STATES.PASSWORD_CHANGE); } + showEnrollAccountForm() { + return(Package['accounts-password'] + && this.state.formState == STATES.ENROLL_ACCOUNT); + } + showCreateAccountLink() { return this.state.formState == STATES.SIGN_IN && !Accounts._options.forbidClientAccountCreation && Package['accounts-password']; }