From 53f24f7cd8dda42d2655ea08c04e4f31723d865d Mon Sep 17 00:00:00 2001 From: George Crawford Date: Wed, 17 Aug 2016 10:52:12 +0100 Subject: [PATCH 1/2] Clarify access mock instructions, and ensure cookies are immediately applied --- scss/style.scss | 9 +++++++++ server/controllers/access-mock.js | 22 +++++++++++++++++++--- server/controllers/amp-page.js | 27 ++++++++++++++++++++------- views/article.html | 12 +++++++++++- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/scss/style.scss b/scss/style.scss index 93ed849f..a21bf9fb 100644 --- a/scss/style.scss +++ b/scss/style.scss @@ -437,6 +437,15 @@ body { min-width: 90px; right: 0; z-index: 1; + + ul { + padding: 0; + margin: 0 0 0 10px; + } + + li { + margin-bottom: 10px; + } } .amp-access-login { diff --git a/server/controllers/access-mock.js b/server/controllers/access-mock.js index 67756305..660e8d6f 100644 --- a/server/controllers/access-mock.js +++ b/server/controllers/access-mock.js @@ -16,9 +16,12 @@ module.exports = (req, res) => { const signedIn = !!req.cookies['amp-access-mock-logged-in']; const fcf = !!req.cookies['amp-access-mock-fcf']; - const hasAccess = fcf || signedIn && !req.cookies['amp_access_mock-no-access']; + const noAccess = !!req.cookies['amp-access-mock-no-access']; + const hasAccess = !noAccess && (fcf || signedIn); setTimeout(() => { + const returnUrl = req.header('Referer'); + switch(req.query.type) { case 'access': @@ -43,32 +46,45 @@ module.exports = (req, res) => { case 'enable': res.cookie('amp-access-mock', '1'); + if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock cookie was set. Please revisit the ' + 'previous page.'); break; case 'clear': res.clearCookie('amp-access-mock'); + if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock cookie was cleared. Please revisit the ' + 'previous page.'); break; case 'enable-fcf': res.cookie('amp-access-mock-fcf', '1'); + if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock-fcf cookie was set. Please revisit the ' + 'previous page.'); break; case 'clear-fcf': res.clearCookie('amp-access-mock-fcf'); + if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock-fcf cookie was cleared. Please revisit the ' + 'previous page.'); break; case 'prevent-access': res.cookie('amp-access-mock-no-access', '1'); - res.status(200).send('Your amp_access_mock-no-access cookie was set. You will not be able to access' + - 'content, even when signed-in. Please revisit the previous page.'); + if(returnUrl) return res.redirect(303, returnUrl); + res.status(200).send('Your amp_access_mock-no-access cookie was set. You will not be able to access ' + + 'content, even when signed-in. Please revisit the ' + + 'previous page.'); + break; + + case 'allow-access': + res.clearCookie('amp-access-mock-no-access'); + if(returnUrl) return res.redirect(303, returnUrl); + res.status(200).send('Your amp-access-mock-no-access cookie was cleared. Please revisit the ' + + 'previous page.'); break; default: diff --git a/server/controllers/amp-page.js b/server/controllers/amp-page.js index db7f3acc..b7a6248c 100644 --- a/server/controllers/amp-page.js +++ b/server/controllers/amp-page.js @@ -44,28 +44,32 @@ function getAndRender(uuid, options) { .then(() => article)) ) .then(article => { - article.AUTH_AUTHORIZATION_URL = options.accessMock ? + article.AUTH_AUTHORIZATION_URL = options.accessMocked ? `//${options.host}/amp-access-mock?type=access&` : `https://${liveAccessHost}/amp-access?`; - article.AUTH_PINGBACK_URL = options.accessMock ? + article.AUTH_PINGBACK_URL = options.accessMocked ? `//${options.host}/amp-access-mock?type=pingback&` : `https://${liveAccessHost}/amp-pingback?`; - article.AUTH_LOGIN_URL = options.accessMock ? + article.AUTH_LOGIN_URL = options.accessMocked ? `//${options.host}/amp-access-mock?type=login&` : 'https://accounts.ft.com/login?'; - article.AUTH_LOGOUT_URL = options.accessMock ? + article.AUTH_LOGOUT_URL = options.accessMocked ? `//${options.host}/amp-access-mock?type=logout&` : `https://${liveAccessHost}/amp-logout?`; article.SOURCE_PORT = options.production ? '' : ':5000'; article.freeArticle = !!options.alwaysFree; - article.accessMocked = !!options.accessMock; article.enableSidebarMenu = !!options.enableSidebarMenu; + article.accessMocked = !!options.accessMocked; + article.accessMockLoggedIn = !!options.accessMockLoggedIn; + article.accessMockFcf = !!options.accessMockFcf; + article.accessMockPreventAccess = !!options.accessMockPreventAccess; + article.nextUrl = `https://next.ft.com/content/${uuid}`; return article; @@ -81,7 +85,10 @@ module.exports = (req, res, next) => { ip: req.ip, ua: req.get('User-Agent'), relatedArticleDeduper: [req.params.uuid], - accessMock: req.cookies['amp-access-mock'], + accessMocked: req.cookies['amp-access-mock'], + accessMockLoggedIn: req.cookies['amp-access-mock-logged-in'], + accessMockFcf: req.cookies['amp-access-mock-fcf'], + accessMockPreventAccess: req.cookies['amp-access-mock-no-access'], lightSignupUrl: process.env.LIGHT_SIGNUP_URL || 'https://distro-light-signup-prod.herokuapp.com', lightSignupProduct: encodeURIComponent(lightSignupProduct), lightSignupMailinglist: encodeURIComponent(lightSignupMailinglist), @@ -90,7 +97,13 @@ module.exports = (req, res, next) => { uuid: req.params.uuid, }) .then(content => { - res.setHeader('cache-control', 'public, max-age=30, no-transform'); + if(req.cookies['amp-access-mock']) { + // No caching, to allow access mock cookies to be applied immediately + res.setHeader('Cache-Control', 'private, no-cache, no-store, must-revalidate'); + } else { + res.setHeader('cache-control', 'public, max-age=30, no-transform'); + } + res.send(content); }) .catch(next); diff --git a/views/article.html b/views/article.html index 852b2f0e..d4ea4231 100644 --- a/views/article.html +++ b/views/article.html @@ -88,7 +88,17 @@ {{/if}} {{#if accessMocked}} -
You are currently mocking membership access. Click here to return to live membership access.
+
+ +
{{/if}}
From 643e1af1a37f5a21329122dac93e40bf2d4ca607 Mon Sep 17 00:00:00 2001 From: George Crawford Date: Wed, 17 Aug 2016 10:56:17 +0100 Subject: [PATCH 2/2] Add warning to refresh page --- server/controllers/access-mock.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/controllers/access-mock.js b/server/controllers/access-mock.js index 660e8d6f..8d872f2d 100644 --- a/server/controllers/access-mock.js +++ b/server/controllers/access-mock.js @@ -48,28 +48,32 @@ module.exports = (req, res) => { res.cookie('amp-access-mock', '1'); if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock cookie was set. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; case 'clear': res.clearCookie('amp-access-mock'); if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock cookie was cleared. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; case 'enable-fcf': res.cookie('amp-access-mock-fcf', '1'); if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock-fcf cookie was set. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; case 'clear-fcf': res.clearCookie('amp-access-mock-fcf'); if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock-fcf cookie was cleared. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; case 'prevent-access': @@ -77,14 +81,16 @@ module.exports = (req, res) => { if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp_access_mock-no-access cookie was set. You will not be able to access ' + 'content, even when signed-in. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; case 'allow-access': res.clearCookie('amp-access-mock-no-access'); if(returnUrl) return res.redirect(303, returnUrl); res.status(200).send('Your amp-access-mock-no-access cookie was cleared. Please revisit the ' + - 'previous page.'); + 'previous page and then ' + + 'refresh to apply the new settings.'); break; default: