From cd8eceb44c134b2b21cc9655746b53e180f88d97 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 16 Jan 2019 15:08:22 +0100 Subject: [PATCH 1/4] feat: Update enrollAccount email url Signed-off-by: Seun Martins --- .../plugins/core/accounts/server/util/getDataForEmail.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imports/plugins/core/accounts/server/util/getDataForEmail.js b/imports/plugins/core/accounts/server/util/getDataForEmail.js index 5fa6cdd3b2f..56d43d93d9d 100644 --- a/imports/plugins/core/accounts/server/util/getDataForEmail.js +++ b/imports/plugins/core/accounts/server/util/getDataForEmail.js @@ -4,6 +4,12 @@ import { Accounts as MeteorAccounts } from "meteor/accounts-base"; import { Shops } from "/lib/collections"; import Reaction from "/imports/plugins/core/core/server/Reaction"; +export const ENROLL_URI_BASE = "account/enroll"; + +MeteorAccounts.urls.enrollAccount = function (token) { + return Reaction.absoluteUrl(`${ENROLL_URI_BASE}/${token}`); +}; + /** * @name getDataForEmail * @memberof Accounts/Methods From d2463c15e631204e06eb319484334378a5018e8b Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 16 Jan 2019 15:11:18 +0100 Subject: [PATCH 2/4] feat: Add enrollAccount path to resgistry Signed-off-by: Seun Martins --- imports/plugins/core/accounts/register.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/imports/plugins/core/accounts/register.js b/imports/plugins/core/accounts/register.js index ee19aab7a0d..b32686eca1a 100644 --- a/imports/plugins/core/accounts/register.js +++ b/imports/plugins/core/accounts/register.js @@ -3,6 +3,7 @@ import mutations from "./server/no-meteor/mutations"; import queries from "./server/no-meteor/queries"; import resolvers from "./server/no-meteor/resolvers"; import schemas from "./server/no-meteor/schemas"; +import { ENROLL_URI_BASE } from "./server/util/getDataForEmail"; /** * @file Accounts core plugin: Manage how members sign into your shop @@ -72,6 +73,13 @@ Reaction.registerPackage({ meta: { noAdminControls: true }, name: "reset-password", label: "reset-password" + }, { + route: `/${ENROLL_URI_BASE}/:token/:status?`, + template: "loginFormUpdatePassword", + workflow: "none", + meta: { noAdminControls: true }, + name: ENROLL_URI_BASE, + label: "Account Enroll" }], layout: [{ layout: "coreLayout", From 529a495a6ebabc6093919f9f7c89da971720c9c0 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 16 Jan 2019 15:15:13 +0100 Subject: [PATCH 3/4] fix: Update password template settings to fix render error Signed-off-by: Seun Martins --- .../client/containers/updatePassword.js | 3 +- .../updatePassword/updatePassword.js | 33 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/imports/plugins/core/accounts/client/containers/updatePassword.js b/imports/plugins/core/accounts/client/containers/updatePassword.js index 5ce089f9f1c..490aecb23d0 100644 --- a/imports/plugins/core/accounts/client/containers/updatePassword.js +++ b/imports/plugins/core/accounts/client/containers/updatePassword.js @@ -15,6 +15,7 @@ const wrapComponent = (Comp) => ( callback: PropTypes.func, formMessages: PropTypes.object, isOpen: PropTypes.bool, + onCompleteRoute: PropTypes.string, type: PropTypes.string, uniqueId: PropTypes.string } @@ -75,7 +76,7 @@ const wrapComponent = (Comp) => ( } else { // Now that Meteor.users is verified, we should do the same with the Accounts collection Meteor.call("accounts/verifyAccount"); - Router.go(`${Router.current().route.fullPath}/completed`); + Router.go(this.props.onCompleteRoute); } }); } diff --git a/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.js b/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.js index 1f78fc4d6f7..645197d6544 100644 --- a/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.js +++ b/imports/plugins/core/accounts/client/templates/updatePassword/updatePassword.js @@ -2,36 +2,37 @@ import Random from "@reactioncommerce/random"; import { Accounts } from "meteor/accounts-base"; import { Template } from "meteor/templating"; import { $ } from "meteor/jquery"; -import { Blaze } from "meteor/blaze"; import { ReactiveVar } from "meteor/reactive-var"; -import { i18next } from "/client/api"; +import { Reaction, i18next } from "/client/api"; import { LoginFormSharedHelpers } from "../../helpers"; import { getComponent } from "/imports/plugins/core/components/lib"; import { LoginFormValidation } from "/lib/api"; -/** - * Accounts Event: onEnrollmentLink When a user uses an enrollment link - */ -Accounts.onEnrollmentLink((token, done) => { - Blaze.renderWithData(Template.loginFormUpdatePasswordOverlay, { - token, - callback: done, - isOpen: true, - type: "setPassword" - }, $("body").get(0)); -}); - - // ---------------------------------------------------------------------------- // /** // * Helpers: Login Form Update Password // */ Template.loginFormUpdatePassword.helpers({ component() { + const routeName = Reaction.Router.current().route.name; + const formTypeProps = { + "account/enroll": { + type: "setPassword", + onCompleteRoute: "/" + }, + "reset-password": { + type: "updatePassword", + onCompleteRoute: `${Reaction.Router.current().route.fullPath}/completed` + } + }; + + const { type, onCompleteRoute } = formTypeProps[routeName]; + return { component: getComponent("UpdatePassword"), isOpen: true, - type: "updatePassword" + type, + onCompleteRoute }; } }); From 1cecfbed62a73ff94efc32fca65c605a26fc7427 Mon Sep 17 00:00:00 2001 From: Seun Martins Date: Wed, 16 Jan 2019 15:15:44 +0100 Subject: [PATCH 4/4] fix: Add enrollAccount role for users Signed-off-by: Seun Martins --- imports/plugins/core/accounts/server/init.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imports/plugins/core/accounts/server/init.js b/imports/plugins/core/accounts/server/init.js index 7662e5523cd..8569bc8eaf0 100644 --- a/imports/plugins/core/accounts/server/init.js +++ b/imports/plugins/core/accounts/server/init.js @@ -1,6 +1,7 @@ import Hooks from "@reactioncommerce/hooks"; import Reaction from "/imports/plugins/core/core/server/Reaction"; import { Accounts, Groups } from "/lib/collections"; +import { ENROLL_URI_BASE } from "./util/getDataForEmail"; // set default admin user's account as "owner" Hooks.Events.add("afterCreateDefaultAdminUser", (user) => { @@ -16,6 +17,6 @@ Hooks.Events.add("afterCoreInit", () => { Reaction.addRolesToGroups({ allShops: true, groups: ["guest", "customer"], - roles: ["account/verify", "reset-password"] + roles: ["account/verify", "reset-password", ENROLL_URI_BASE] }); });