Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #465 from solocommand/idx-enl-consent
Browse files Browse the repository at this point in the history
IdentityX fixes, newsletter signup consent
  • Loading branch information
solocommand authored Oct 27, 2022
2 parents c22c9f7 + e9fb865 commit e1b8fa0
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 42 deletions.
12 changes: 12 additions & 0 deletions packages/marko-web-identity-x/browser/authenticate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
:default-country-code="defaultCountryCode"
:boolean-questions-label="booleanQuestionsLabel"
:consent-policy="consentPolicy"
:consent-policy-enabled="consentPolicyEnabled"
:email-consent-request="emailConsentRequest"
:email-consent-request-enabled="emailConsentRequestEnabled"
:regional-consent-policies="regionalConsentPolicies"
:button-label="buttonLabel"
:call-to-action="callToAction"
Expand Down Expand Up @@ -90,10 +92,18 @@ export default {
type: String,
default: null,
},
consentPolicyEnabled: {
type: Boolean,
default: false,
},
emailConsentRequest: {
type: String,
default: null,
},
emailConsentRequestEnabled: {
type: Boolean,
default: false,
},
regionalConsentPolicies: {
type: Array,
default: () => [],
Expand Down Expand Up @@ -207,6 +217,8 @@ export default {
.some(({ hasAnswered, field }) => field.required && !hasAnswered);
this.emit('authenticated', {
id: this.activeUser.id,
email: this.activeUser.email,
mustReVerifyProfile: this.mustReVerifyProfile,
isProfileComplete: this.isProfileComplete,
requiresCustomFieldAnswers: this.requiresCustomFieldAnswers,
Expand Down
25 changes: 22 additions & 3 deletions packages/marko-web-identity-x/browser/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@
:disabled="loading"
:label="loginEmailLabel"
/>

<small
v-if="consentPolicy"
class="text-muted mb-3"
v-if="emailConsentRequestEnabled && emailConsentRequest"
class="text-muted mb-1 d-block"
v-html="emailConsentRequest"
/>

<small
v-if="consentPolicyEnabled && consentPolicy"
class="text-muted mb-1 d-block"
v-html="consentPolicy"
/>
<button
Expand Down Expand Up @@ -106,6 +113,18 @@ export default {
type: String,
default: null,
},
consentPolicyEnabled: {
type: Boolean,
default: false,
},
emailConsentRequest: {
type: String,
default: null,
},
emailConsentRequestEnabled: {
type: Boolean,
default: false,
},
redirect: {
type: String,
default: null,
Expand Down Expand Up @@ -217,7 +236,7 @@ export default {
const data = await res.json();
if (!res.ok) throw new FormError(data.message, res.status);
this.complete = true;
this.emit('login-link-sent', { data, source: this.source });
this.emit('login-link-sent', { data, email: this.email, source: this.source });
} catch (e) {
this.error = e;
this.emit('login-errored', { message: e.message });
Expand Down
20 changes: 15 additions & 5 deletions packages/marko-web-identity-x/browser/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@
:endpoints="endpoints"
:app-context-id="appContextId"
:consent-policy="consentPolicy"
:consent-policy-enabled="consentPolicyEnabled"
:email-consent-request="emailConsentRequest"
:email-consent-request-enabled="emailConsentRequestEnabled"
:regional-consent-policies="regionalConsentPolicies"
:required-fields="requiredLoginFields"
/>
</div>
</template>
Expand Down Expand Up @@ -271,6 +273,18 @@ export default {
type: String,
default: null,
},
consentPolicyEnabled: {
type: Boolean,
default: false,
},
emailConsentRequest: {
type: String,
default: null,
},
emailConsentRequestEnabled: {
type: Boolean,
default: false,
},
appContextId: {
type: String,
default: null,
Expand All @@ -279,10 +293,6 @@ export default {
type: String,
default: 'Submit',
},
emailConsentRequest: {
type: String,
default: null,
},
regionalConsentPolicies: {
type: Array,
default: () => [],
Expand Down
1 change: 1 addition & 0 deletions packages/marko-web-identity-x/components/form-login.marko
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $ const additionalEventData = defaultValue(input.additionalEventData, {});
redirect: input.redirect,
loginEmailPlaceholder: input.loginEmailPlaceholder,
consentPolicy: get(application, "organization.consentPolicy"),
emailConsentRequest: get(application, "organization.emailConsentRequest"),
regionalConsentPolicies: get(application, "organization.regionalConsentPolicies"),
appContextId: identityX.config.get("appContextId"),
};
Expand Down
12 changes: 11 additions & 1 deletion packages/marko-web-identity-x/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ module.exports = (app, config, {
config.endpointTypes.forEach((type) => {
const endpoint = config.getEndpointFor(type);
const template = templates[type];
if (template) app.get(endpoint, (_, res) => res.marko(template));
if (!template) return;

app.get(endpoint, (req, res) => {
const { token } = req.identityX;
// Redirect to profile if a user token is already present (refresh after link click)
if (type === 'authenticate' && token) {
const redirectTo = req.query.redirectTo || config.getEndpointFor('profile');
res.redirect(302, redirectTo);
}
res.marko(template);
});
});
};
5 changes: 1 addition & 4 deletions packages/marko-web-identity-x/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class IdentityX {
*
* @returns {Promise<object>}
*/
async loadActiveContext({ forceQuery = false, useIps = false } = {}) {
// Require a token/cookie to check active context. This disables team context from IP/CIDR.
if (!this.token && !useIps) return {};

async loadActiveContext({ forceQuery = false } = {}) {
// Only run the active context query once
if (!this.activeContextQuery || forceQuery) {
this.activeContextQuery = this.client.query({ query: getActiveContext });
Expand Down
15 changes: 0 additions & 15 deletions packages/marko-web-omeda-identity-x/add-integration-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const props = require('./validation/props');
const {
onAuthenticationSuccess,
onLoginLinkSent,
onLogout,
onUserProfileUpdate,
} = require('./integration-hooks');

Expand Down Expand Up @@ -114,19 +113,5 @@ module.exports = (params = {}) => {
}),
});

idxConfig.addHook({
name: 'onLogout',
shouldAwait: true,
fn: async args => onLogout({
...args,
...appendDataFor('onLogout'),
behavior: buildBehaviorFor('onLogout', {
actionSource: get(args, 'actionSource'),
newsletterSignupType: get(args, 'newsletterSignupType'),
contentGateType: get(args, 'contentGateType'),
}),
}),
});

return idxConfig;
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const onAuthenticationSuccess = require('./on-authentication-success');
const onLoginLinkSent = require('./on-login-link-sent');
const onLogout = require('./on-logout');
const onUserProfileUpdate = require('./on-user-profile-update');

module.exports = {
onAuthenticationSuccess,
onLoginLinkSent,
onLogout,
onUserProfileUpdate,
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
:button-labels="buttonLabels"
:redirect="redirect"
:login-email-placeholder="loginEmailPlaceholder"
:consent-policy-enabled="true"
:consent-policy="consentPolicy"
:email-consent-request-enabled="true"
:email-consent-request="emailConsentRequest"
:regional-consent-policies="regionalConsentPolicies"
:app-context-id="appContextId"
:login-email-label="translateEmail"
Expand Down Expand Up @@ -112,6 +115,10 @@ export default {
type: String,
default: null,
},
emailConsentRequest: {
type: String,
default: null,
},
redirect: {
type: String,
default: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
:button-labels="buttonLabels"
:redirect="redirect"
:login-email-placeholder="loginEmailPlaceholder"
:consent-policy-enabled="true"
:consent-policy="consentPolicy"
:email-consent-request-enabled="true"
:email-consent-request="emailConsentRequest"
:regional-consent-policies="regionalConsentPolicies"
:app-context-id="appContextId"
:action-text="actionText"
Expand Down Expand Up @@ -120,6 +123,10 @@ export default {
type: String,
default: null,
},
emailConsentRequest: {
type: String,
default: null,
},
redirect: {
type: String,
default: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ $ const lang = site.config.lang || "en";
redirect: input.redirect,
loginEmailPlaceholder,
loginEmailLabel: input.loginEmailLabel,
consentPolicy: get(application, "organization.consentPolicy"),
consentPolicy: input.consentPolicy || get(application, "organization.consentPolicy"),
emailConsentRequest: get(application, "organization.emailConsentRequest"),
regionalConsentPolicies: get(application, "organization.regionalConsentPolicies"),
appContextId: identityX.config.get("appContextId"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ $ const imageSrcset = imageSrc ? `${imageSrc}&dpr=2 2x` : null;
redirect: input.redirect,
loginEmailPlaceholder,
loginEmailLabel: input.loginEmailLabel,
consentPolicy: get(application, "organization.consentPolicy"),
consentPolicy: input.consentPolicy || get(application, "organization.consentPolicy"),
emailConsentRequest: get(application, "organization.emailConsentRequest"),
regionalConsentPolicies: get(application, "organization.regionalConsentPolicies"),
appContextId: identityX.config.get("appContextId"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ $ const imageSrcset = imageSrc ? `${imageSrc}&dpr=2 2x` : null;
redirect: input.redirect,
loginEmailPlaceholder,
loginEmailLabel: input.loginEmailLabel,
consentPolicy: get(application, "organization.consentPolicy"),
consentPolicy: input.consentPolicy || get(application, "organization.consentPolicy"),
emailConsentRequest: get(application, "organization.emailConsentRequest"),
regionalConsentPolicies: get(application, "organization.regionalConsentPolicies"),
appContextId: identityX.config.get("appContextId"),
}
Expand Down
20 changes: 14 additions & 6 deletions services/example-website/server/components/document.marko
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ $ const { nativeX } = out.global;
</@above-wrapper>
<@above-container>
<marko-web-identity-x-context|{ hasUser, isEnabled }|>
<theme-site-header has-user=hasUser reg-enabled=isEnabled show-search-icon=true menu-btn-position="right"/>
<theme-site-header
has-user=hasUser
reg-enabled=isEnabled
show-search-icon=true
menu-btn-position="right"
newsletter-menu-block-props={
consentPolicy: 'Custom consent policy - <strong>header</strong>'
}
/>
<theme-site-menu has-user=hasUser reg-enabled=isEnabled />
</marko-web-identity-x-context>
<marko-web-leaders-dropdown-portal />
Expand All @@ -53,11 +61,11 @@ $ const { nativeX } = out.global;
</@above-container>
<@below-container>
<${input.belowContainer} />
<theme-site-footer>
<@newsletter-block>
<identity-x-newsletter-form-footer />
</@newsletter-block>
</theme-site-footer>
<theme-site-footer
newsletter-block-props={
consentPolicy: 'Custom consent policy - footer'
}
/>
<marko-web-deferred-script-loader-load />
</@below-container>
</marko-web-document>
2 changes: 1 addition & 1 deletion services/example-website/server/templates/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<@section>
<div class="row">
<div class="col">
<identity-x-newsletter-form-inline />
<identity-x-newsletter-form-inline type="inlineSection" />
</div>
</div>
</@section>
Expand Down
2 changes: 1 addition & 1 deletion services/example-website/server/templates/section.marko
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ const { recaptcha } = out.global;
</div>
<div class="row pt-1">
<div class="col">
<identity-x-newsletter-form-inline type="inlineSection" />
<identity-x-newsletter-form-inline type="inlineSection" consent-policy="custom consent policy - section" />
</div>
</div>
</marko-web-resolve-page>
Expand Down

0 comments on commit e1b8fa0

Please sign in to comment.