From 5d43242cdb739ed2d6cc071fef2495a430564246 Mon Sep 17 00:00:00 2001 From: Todd Humphrey Date: Tue, 7 Jun 2016 11:44:04 -0400 Subject: [PATCH 1/2] Revert "add onPostResetPasswordHook and onPostEnrollAccountHook" This reverts commit 650e958b2773dc0d0ceb8f12f0c0dc7deb97699e. --- imports/accounts_ui.js | 13 +++---------- imports/ui/components/LoginForm.jsx | 14 +------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/imports/accounts_ui.js b/imports/accounts_ui.js index 0f81aa1..8e60b3d 100644 --- a/imports/accounts_ui.js +++ b/imports/accounts_ui.js @@ -28,10 +28,7 @@ Accounts.ui._options = { onResetPasswordHook: () => redirect(`${Accounts.ui._options.loginPath}`), onVerifyEmailHook: () => redirect(`${Accounts.ui._options.profilePath}`), onSignedInHook: () => null, - onSignedOutHook: () => null, - onPostResetPasswordHook: () => null, - onPostEnrollAccountHook: () => null - + onSignedOutHook: () => null }; /** @@ -65,9 +62,7 @@ Accounts.ui.config = function(options) { 'onResetPasswordHook', 'onVerifyEmailHook', 'onSignedInHook', - 'onSignedOutHook', - 'onPostResetPasswordHook', - 'onPostEnrollAccountHook' + 'onSignedOutHook' ]; _.each(_.keys(options), function (key) { @@ -194,9 +189,7 @@ Accounts.ui.config = function(options) { 'onResetPasswordHook', 'onVerifyEmailHook', 'onSignedInHook', - 'onSignedOutHook', - 'onPostResetPasswordHook', - 'onPostEnrollAccountHook' ]) { + 'onSignedOutHook']) { if (options[hook]) { if (typeof options[hook] == 'function') { Accounts.ui._options[hook] = options[hook]; diff --git a/imports/ui/components/LoginForm.jsx b/imports/ui/components/LoginForm.jsx index eac273c..15ae8f2 100644 --- a/imports/ui/components/LoginForm.jsx +++ b/imports/ui/components/LoginForm.jsx @@ -35,9 +35,7 @@ export class LoginForm extends Tracker.Component { onSignedInHook: props.onSignedInHook || Accounts.ui._options.onSignedInHook, onSignedOutHook: props.onSignedOutHook || Accounts.ui._options.onSignedOutHook, onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook, - onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook, - onPostResetPasswordHook: props.onPostResetPasswordHook || Accounts.ui._options.onPostResetPasswordHook, - onPostEnrollAccountHook: props.onPostEnrollAccountHook || Accounts.ui._options.onPostEnrollAccountHook + onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook }; // Listen for the user to login/logout. @@ -767,18 +765,8 @@ export class LoginForm extends Tracker.Component { else { this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000); this.setState({ formState: STATES.PROFILE }); - - //Determin what hook to call after password set / reset - let hookFunction = () => null; - if (Accounts._loginButtonsSession.get('resetPasswordToken')) { - hookFunction = this.state.onPostResetPasswordHook; - } else if (Accounts._loginButtonsSession.get('enrollAccountToken')){ - hookFunction = this.state.onPostEnrollAccountHook; - } - Accounts._loginButtonsSession.set('resetPasswordToken', null); Accounts._loginButtonsSession.set('enrollAccountToken', null); - hookFunction(); } }); } From 57606af5995e66bbd8ac48c41507213866cd2359 Mon Sep 17 00:00:00 2001 From: Todd Humphrey Date: Fri, 6 Jan 2017 08:51:08 -0500 Subject: [PATCH 2/2] Re-apply changes to add enroll form state --- imports/helpers.js | 3 ++- imports/ui/components/LoginForm.jsx | 32 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) 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']; }