Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
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
13 changes: 11 additions & 2 deletions packages/marko-web-identity-x/browser/download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<h5 class="content-page-gate__title">
{{ title }}
</h5>
<p v-if="!didSubmit" v-html="callToAction" />
<form v-if="!didSubmit" @submit.prevent="handleSubmit">
<p v-if="!didSubmit && displayForm" v-html="callToAction" />
<form v-if="!didSubmit && displayForm" @submit.prevent="handleSubmit">
<fieldset :disabled="isLoading">
<div v-for="(row, ridx) in fieldRows" :key="ridx" class="row">
<custom-column
Expand Down Expand Up @@ -135,6 +135,14 @@ export default {
type: String,
default: 'To download this content, please enter your email address below.',
},
cookie: {
type: Object,
required: true,
},
displayForm: {
type: Boolean,
default: true,
},

/**
* profile/login props
Expand Down Expand Up @@ -324,6 +332,7 @@ export default {
const { entity } = await post('/download', {
contentId: content.id,
contentType: content.type,
cookie: this.cookie,
companyId: company.id,
userId: this.user.id,
additionalEventData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ const callToActionLoggedOut = defaultValue(input.callToAction, `${ctaPrefix},
$ const buttonLabel = defaultValue(input.buttonLabel, "Submit & Access");
$ const title = defaultValue(input.title, "Complete the form to access this content");
$ const updateProfileOnSubmit = defaultValue(input.updateProfileOnSubmit, true);
$ const { displayForm, cookie } = getAsObject(out, "global.contentIdxFormState");
$ const { displayForm, cookie } = getAsObject(out, "global.contentAccessState");
$ const consentPolicy = defaultValue(form.consentPolicy, get(application, "organization.consentPolicy"));
$ const emailConsentRequest = defaultValue(form.emailConsentRequest, get(application, "organization.emailConsentRequest"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { get, getAsObject } = require('@parameter1/base-cms-object-path');

const cookieNamePrefix = '__idx_form';
// default is one day
const maxAge = process.env.IDX_CONTENT_ACCESS_MAXAGE
? Number(process.env.IDX_CONTENT_ACCESS_MAXAGE)
: (24 * 60 * 60 * 1000);

const contentAccessState = ({ res, content }) => {
// Handle setting of contentAccessState Object
const { surveyType, surveyId } = getAsObject(content, 'gating');
const cookieName = `${cookieNamePrefix}_${surveyId}_${content.id}`;

const setFormDisplay = ({ req }) => {
res.locals.contentAccessState.displayForm = !get(req, `cookies.${cookieName}`);
};
res.locals.contentAccessState = {
displayForm: false,
setFormDisplay,
};

if (surveyType === 'idx') {
const cookie = { name: cookieName, maxAge };
res.locals.contentAccessState.formId = surveyId;
res.locals.contentAccessState.cookie = cookie;
}
};

module.exports = {
contentAccessState,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { get } = require('@parameter1/base-cms-object-path');

const cookieNamePrefix = '__idx_form';
const maxAge = process.env.IDX_CONTENT_DOWNLOAD_MAXAGE
? Number(process.env.IDX_CONTENT_DOWNLOAD_MAXAGE)
: 0;

const contentDownloadState = ({ res, content }) => {
// Handle setting of contentDownloadState Object
const surveyId = 'content-download';
const cookieName = `${cookieNamePrefix}_${surveyId}_${content.id}`;

const setFormDisplay = ({ req }) => {
res.locals.contentDownloadState.displayForm = !get(req, `cookies.${cookieName}`);
};
res.locals.contentDownloadState = {
displayForm: false,
setFormDisplay,
};
const cookie = { name: cookieName, maxAge };
res.locals.contentDownloadState.formId = surveyId;
res.locals.contentDownloadState.cookie = cookie;
};

module.exports = {
contentDownloadState,
};
4 changes: 3 additions & 1 deletion packages/marko-web-identity-x/routes/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const mutation = gql`
module.exports = asyncRoute(async (req, res) => {
/** @type {import('../middleware').IdentityXRequest} */
const { body, apollo, identityX } = req;
const { contentId, payload } = body;
const { contentId, payload, cookie } = body;
const input = {
contentId,
payload,
ipAddress: req.ip,
};
const { name: COOKIE_NAME, maxAge } = cookie;
await apollo.mutate({ mutation, variables: { input } });
res.cookie(COOKIE_NAME, true, { maxAge, httpOnly: false });
const entity = await identityX.generateEntityId();
res.json({
ok: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@

import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value";
import { get } from "@parameter1/base-cms-object-path";
import { get, getAsObject } from "@parameter1/base-cms-object-path";

$ const { req: { identityX } } = out.global;
$ const { req } = out.global;
$ const { identityX } = req;
$ const { content, formId } = input;
$ const form = identityX.config.getAsObject(`forms.${formId}`);
$ const additionalEventData = defaultValue(input.additionalEventData, {});
$ const ctaPrefix = `To download "${content.name}"`;
$ const callToAction = defaultValue(input.callToAction, `${ctaPrefix}, please fill out the form below.`);
$ const callToActionLoggedOut = defaultValue(input.callToAction, `${ctaPrefix}, please enter your email address below. You will receive an email containing a verification link.`);
$ const contentDownloadState = getAsObject(out, "global.contentDownloadState");
$ contentDownloadState.setFormDisplay({ req });
$ const { cookie, displayForm } = contentDownloadState;
$ const buttonLabel = defaultValue(input.buttonLabel, "Submit & Download");
$ const title = defaultValue(input.title, "Complete the form to download this content");

Expand All @@ -22,6 +26,8 @@ $ const title = defaultValue(input.title, "Complete the form to download this co
fieldRows: form.fieldRows,
loginSource: "contentDownload",
title: title,
cookie,
displayForm,
callToAction: callToAction,
callToActionLoggedOut: callToActionLoggedOut,

Expand Down