From 9f8cc50f821fab7e1a419392878f9f5e80b79d4e Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Tue, 18 Sep 2018 22:04:04 +0000 Subject: [PATCH 1/4] Password reset flow for auth IDP --- ...tePasswordOverlay.js => updatePassword.js} | 119 +++++++----------- .../{passwordOverlay.js => updatePassword.js} | 40 +++--- imports/plugins/core/accounts/client/index.js | 4 +- .../updatePassword/updatePassword.html | 4 +- .../updatePassword/updatePassword.js | 22 +--- imports/plugins/core/accounts/register.js | 7 ++ .../server/methods/sendResetPasswordEmail.js | 4 + private/data/i18n/en.json | 4 +- 8 files changed, 93 insertions(+), 111 deletions(-) rename imports/plugins/core/accounts/client/components/{updatePasswordOverlay.js => updatePassword.js} (55%) rename imports/plugins/core/accounts/client/containers/{passwordOverlay.js => updatePassword.js} (76%) diff --git a/imports/plugins/core/accounts/client/components/updatePasswordOverlay.js b/imports/plugins/core/accounts/client/components/updatePassword.js similarity index 55% rename from imports/plugins/core/accounts/client/components/updatePasswordOverlay.js rename to imports/plugins/core/accounts/client/components/updatePassword.js index bb595cffc4e..90681491d21 100644 --- a/imports/plugins/core/accounts/client/components/updatePasswordOverlay.js +++ b/imports/plugins/core/accounts/client/components/updatePassword.js @@ -3,7 +3,7 @@ import PropTypes from "prop-types"; import classnames from "classnames"; import { Components } from "@reactioncommerce/reaction-components"; -class UpdatePasswordOverlay extends Component { +class UpdatePassword extends Component { static propTypes = { isDisabled: PropTypes.bool, isOpen: PropTypes.bool, @@ -93,30 +93,27 @@ class UpdatePasswordOverlay extends Component { if (type === "setPassword") { return ( -
- -
- ); - } - - return ( -
-
+ ); + } + + return ( + ); } @@ -152,64 +149,42 @@ class UpdatePasswordOverlay extends Component { return (
{this.props.isOpen === true && -
-
-
-
- {showSpinner ? this.renderSpinnerOnLoad() : -
-
-

- {this.renderPasswordResetText()} -

-
- -
-
- - {this.renderFormMessages()} - -
- - {this.renderPasswordErrors()} -
- -
-
- -
- {this.renderSpinnerOnWait()} - -
- -
+
+ {showSpinner ? this.renderSpinnerOnLoad() : + +
+

+ {this.renderPasswordResetText()} +

+
+
+ + {this.renderFormMessages()} + +
+ + {this.renderPasswordErrors()}
+
- - } -
+
+ {this.renderSpinnerOnWait()} +
+ + }
-
} + }
); } } -export default UpdatePasswordOverlay; +export default UpdatePassword; diff --git a/imports/plugins/core/accounts/client/containers/passwordOverlay.js b/imports/plugins/core/accounts/client/containers/updatePassword.js similarity index 76% rename from imports/plugins/core/accounts/client/containers/passwordOverlay.js rename to imports/plugins/core/accounts/client/containers/updatePassword.js index 5cc3e42ae52..b7895fbb618 100644 --- a/imports/plugins/core/accounts/client/containers/passwordOverlay.js +++ b/imports/plugins/core/accounts/client/containers/updatePassword.js @@ -5,17 +5,16 @@ import Random from "@reactioncommerce/random"; import { Accounts } from "meteor/accounts-base"; import { Meteor } from "meteor/meteor"; import { Components, registerComponent } from "@reactioncommerce/reaction-components"; -import { Reaction } from "/client/api"; +import { Router, i18next } from "/client/api"; import { LoginFormValidation } from "/lib/api"; -import UpdatePasswordOverlay from "../components/updatePasswordOverlay"; +import UpdatePassword from "../components/updatePassword"; const wrapComponent = (Comp) => ( - class UpdatePasswordOverlayContainer extends Component { + class UpdatePasswordContainer extends Component { static propTypes = { callback: PropTypes.func, formMessages: PropTypes.object, isOpen: PropTypes.bool, - token: PropTypes.string, type: PropTypes.string, uniqueId: PropTypes.string } @@ -64,8 +63,8 @@ const wrapComponent = (Comp) => ( }); return; } - - Accounts.resetPassword(this.props.token, password, (error) => { + const { token } = Router.current().params; + Accounts.resetPassword(token, password, (error) => { if (error) { this.setState({ isDisabled: false, @@ -76,15 +75,7 @@ const wrapComponent = (Comp) => ( } else { // Now that Meteor.users is verified, we should do the same with the Accounts collection Meteor.call("accounts/verifyAccount"); - - this.props.callback(); - - this.setState({ - isOpen: !this.state.isOpen - }); - - const shopId = Reaction.getUserPreferences("reaction", "activeShopId"); - Reaction.setShopId(shopId); + Router.go(`${Router.current().route.fullPath}/completed`); } }); } @@ -111,6 +102,21 @@ const wrapComponent = (Comp) => ( } render() { + const { status } = Router.current().params; + if (status === "completed") { + return ( +
+
+

+ {i18next.t("accountsUI.info.passwordResetDone")} +

+
+

+ {i18next.t("accountsUI.info.passwordResetDoneText")} +

+
+ ); + } return ( ( } ); -registerComponent("UpdatePasswordOverlay", UpdatePasswordOverlay, wrapComponent); +registerComponent("UpdatePassword", UpdatePassword, wrapComponent); -export default wrapComponent(UpdatePasswordOverlay); +export default wrapComponent(UpdatePassword); diff --git a/imports/plugins/core/accounts/client/index.js b/imports/plugins/core/accounts/client/index.js index 489f74301fa..a6aca83c6e2 100644 --- a/imports/plugins/core/accounts/client/index.js +++ b/imports/plugins/core/accounts/client/index.js @@ -20,7 +20,7 @@ export { default as PermissionsList } from "./components/permissionsList"; export { default as SignIn } from "./components/signIn"; export { default as SignUp } from "./components/signUp"; export { default as UpdateEmail } from "./containers/updateEmail"; -export { default as UpdatePasswordOverlay } from "./components/updatePasswordOverlay"; +export { default as UpdatePassword } from "./components/updatePassword"; export { default as LoginInline } from "./components/loginInline"; export { default as AccountsDashboardContainer } from "./containers/accountsDashboardContainer"; @@ -31,7 +31,7 @@ export { default as EditGroupContainer } from "./containers/editGroupContainer"; export { default as ForgotPasswordContainer } from "./containers/forgotPassword"; export { default as MainDropdownContainer } from "./containers/mainDropdown"; export { default as MessagesContainer } from "./containers/messages"; -export { default as UpdatePasswordOverlayContainer } from "./containers/passwordOverlay"; +export { default as UpdatePasswordContainer } from "./containers/updatePassword"; export { default as LoginInlineContainer } from "./containers/loginInline"; export { default as VerifyAccount } from "./containers/verifyAccount"; diff --git a/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.html b/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.html index 8ceba9961fc..5ab5c3b7909 100644 --- a/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.html +++ b/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.html @@ -1,5 +1,5 @@ -