Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 404 from invite email link #4919

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
});
Expand Down
8 changes: 8 additions & 0 deletions imports/plugins/core/accounts/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion imports/plugins/core/accounts/server/init.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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]
});
});
6 changes: 6 additions & 0 deletions imports/plugins/core/accounts/server/util/getDataForEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down