mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Updated redirect logic to handle tier based urls
refs https://github.com/TryGhost/Team/issues/1168 This makes the actual switch to use a Tiers redirect URL rather than the settings when the Tiers feature is enabled.
This commit is contained in:
parent
4f5257859d
commit
0e866aaa1e
1 changed files with 20 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
const membersService = require('./service');
|
const membersService = require('./service');
|
||||||
|
const models = require('../../models');
|
||||||
const offersService = require('../offers/service');
|
const offersService = require('../offers/service');
|
||||||
const urlUtils = require('../../../shared/url-utils');
|
const urlUtils = require('../../../shared/url-utils');
|
||||||
const ghostVersion = require('@tryghost/version');
|
const ghostVersion = require('@tryghost/version');
|
||||||
|
@ -199,10 +200,26 @@ const createSessionFromMagicLink = async function (req, res, next) {
|
||||||
|
|
||||||
if (action === 'signup') {
|
if (action === 'signup') {
|
||||||
let customRedirect = '';
|
let customRedirect = '';
|
||||||
if (subscriptions.find(sub => ['active', 'trialing'].includes(sub.status))) {
|
const mostRecentActiveSubscription = subscriptions
|
||||||
customRedirect = settingsCache.get('members_paid_signup_redirect') || '';
|
.sort((a, b) => {
|
||||||
|
const aStartDate = new Date(a.start_date);
|
||||||
|
const bStartDate = new Date(b.start_date);
|
||||||
|
return bStartDate.valueOf() - aStartDate.valueOf();
|
||||||
|
})
|
||||||
|
.find(sub => ['active', 'trialing'].includes(sub.status));
|
||||||
|
if (mostRecentActiveSubscription) {
|
||||||
|
if (labsService.isSet('multipleProducts')) {
|
||||||
|
customRedirect = mostRecentActiveSubscription.tier.welcome_page_url;
|
||||||
|
} else {
|
||||||
|
customRedirect = settingsCache.get('members_paid_signup_redirect') || '';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
customRedirect = settingsCache.get('members_free_signup_redirect') || '';
|
if (labsService.isSet('multipleProducts')) {
|
||||||
|
const freeTier = await models.Product.findOne({type: 'free'});
|
||||||
|
customRedirect = freeTier && freeTier.get('welcome_page_url') || '';
|
||||||
|
} else {
|
||||||
|
customRedirect = settingsCache.get('members_free_signup_redirect') || '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customRedirect && customRedirect !== '/') {
|
if (customRedirect && customRedirect !== '/') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue