From 70745dcf2447ee777d3718e4395d742918e590d1 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 23 Apr 2024 12:25:29 -0500 Subject: [PATCH] Website: update "Get your license" link & login/register pages. (#18489) Closes: https://github.com/fleetdm/confidential/issues/6199 Changes: - Updated view-new-license to redirect non-logged-in users to the /register page (it was previously doing this, but had a policy applied, so non-logged-in users were always redirected to the signup page.) - Updated the /register page to support a new input: `purchaseLicense`. If this query string is provided, the register page will redirect users who sign up to the /new-license page. - Updated the /login page to support a new input: `purchaseLicense`. If this query string is provided, the login page will redirect users who log in to the /new-license page. - Updated policies to bypass the is-logged-in policy for the /new-license page. - Updated the "get your license" link in the website nav menu to go to the /new-license page. --- .../api/controllers/customers/view-new-license.js | 2 +- website/api/controllers/entrance/view-login.js | 14 ++++++++++++-- website/api/controllers/entrance/view-signup.js | 14 ++++++++++++-- website/assets/js/pages/entrance/login.page.js | 10 +++++++++- website/assets/js/pages/entrance/signup.page.js | 11 +++++++++-- website/config/policies.js | 1 + website/views/layouts/layout.ejs | 6 +++--- website/views/pages/entrance/login.ejs | 2 +- website/views/pages/entrance/signup.ejs | 2 +- 9 files changed, 49 insertions(+), 13 deletions(-) diff --git a/website/api/controllers/customers/view-new-license.js b/website/api/controllers/customers/view-new-license.js index 7825b48113..1cc188d242 100644 --- a/website/api/controllers/customers/view-new-license.js +++ b/website/api/controllers/customers/view-new-license.js @@ -25,7 +25,7 @@ module.exports = { // if the user isn't logged in, we'll redirect them to the register page. if (!this.req.me) { - throw {redirect: '/customers/register'}; + throw {redirect: '/register?purchaseLicense'}; } // If the user is a super admin, we'll redirect them to the generate-license page. if(this.req.me.isSuperAdmin) { diff --git a/website/api/controllers/entrance/view-login.js b/website/api/controllers/entrance/view-login.js index cba099dbca..74198f8d7e 100644 --- a/website/api/controllers/entrance/view-login.js +++ b/website/api/controllers/entrance/view-login.js @@ -6,6 +6,14 @@ module.exports = { description: 'Display "Login" page.', + inputs: { + purchaseLicense: { + type: 'boolean', + description: 'If this query string is provided, this user will be taken directly to the /new-license page after they login.', + extendedDescription: 'This value is only present when a user navigates to this page from the /register page if they were redirected to that page from the /new-license page.', + defaultsTo: false, + } + }, exits: { @@ -21,7 +29,7 @@ module.exports = { }, - fn: async function () { + fn: async function ({purchaseLicense}) { if (this.req.me) { if(this.req.me.isSuperAdmin){ @@ -31,7 +39,9 @@ module.exports = { } } - return {}; + return { + redirectToLicenseDispenser: purchaseLicense, + }; } diff --git a/website/api/controllers/entrance/view-signup.js b/website/api/controllers/entrance/view-signup.js index 33ed78da56..140ffc98cd 100644 --- a/website/api/controllers/entrance/view-signup.js +++ b/website/api/controllers/entrance/view-signup.js @@ -6,6 +6,14 @@ module.exports = { description: 'Display "Signup" page.', + inputs: { + purchaseLicense: { + type: 'boolean', + description: 'If this query string is provided, this user will be taken directly to the /new-license page after they signup.', + extendedDescription: 'This value will only be present if the user is redirected to this page from the customers/view-new-license', + defaultsTo: false, + } + }, exits: { @@ -21,13 +29,15 @@ module.exports = { }, - fn: async function () { + fn: async function ({purchaseLicense}) { if (this.req.me) { throw {redirect: '/start'}; } - return {}; + return { + redirectToLicenseDispenser: purchaseLicense, + }; } diff --git a/website/assets/js/pages/entrance/login.page.js b/website/assets/js/pages/entrance/login.page.js index c31e25faac..4e278eeeab 100644 --- a/website/assets/js/pages/entrance/login.page.js +++ b/website/assets/js/pages/entrance/login.page.js @@ -25,6 +25,9 @@ parasails.registerPage('login', { // Server error state for the form cloudError: '', showCustomerLogin: true, + // For redirecting users coming from the "Get your license" link to the license dispenser. + registerSlug: '/register', + pageToRedirectToAfterLogin: '/start', }, // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗ @@ -34,6 +37,11 @@ parasails.registerPage('login', { if(window.location.search === '?admin') { this.showCustomerLogin = false; } + // If we're redirecting this user to the license dispenser after they log in, modify the link to the /register page and the pageToRedirectToAfterLogin. + if(this.redirectToLicenseDispenser){ + this.loginSlug = '/register?purchaseLicense'; + this.pageToRedirectToAfterLogin = '/new-license'; + } }, mounted: async function() { //… @@ -49,7 +57,7 @@ parasails.registerPage('login', { // > (Note that we re-enable the syncing state here. This is on purpose-- // > to make sure the spinner stays there until the page navigation finishes.) this.syncing = true; - window.location = '/start'; + window.location = this.pageToRedirectToAfterLogin; }, } diff --git a/website/assets/js/pages/entrance/signup.page.js b/website/assets/js/pages/entrance/signup.page.js index 1543e4c6f4..8521e3bb8d 100644 --- a/website/assets/js/pages/entrance/signup.page.js +++ b/website/assets/js/pages/entrance/signup.page.js @@ -24,13 +24,20 @@ parasails.registerPage('signup', { cloudError: '', // For displaying the full signup form. showFullForm: false, + // For redirecting users coming from the "Get your license" link to the license dispenser. + loginSlug: '/login', + pageToRedirectToAfterRegistration: '/start', }, // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗ // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣ // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝ beforeMount: function() { - //… + // If we're redirecting this user to the license dispenser after they sign up, modify the link to the login page and the pageToRedirectToAfterRegistration + if(this.redirectToLicenseDispenser){ + this.loginSlug = '/login?purchaseLicense'; + this.pageToRedirectToAfterRegistration = '/new-license'; + } }, mounted: async function() { //… @@ -60,7 +67,7 @@ parasails.registerPage('signup', { // > (Note that we re-enable the syncing state here. This is on purpose-- // > to make sure the spinner stays there until the page navigation finishes.) this.syncing = true; - window.location = '/start'; + window.location = this.pageToRedirectToAfterRegistration;// « / start if the user came here from the start now button, or customers/new-license if the user came here from the "Get your license" link. } diff --git a/website/config/policies.js b/website/config/policies.js index 6f9d53471a..ebecbbea74 100644 --- a/website/config/policies.js +++ b/website/config/policies.js @@ -53,4 +53,5 @@ module.exports.policies = { 'try-fleet/view-explore-data': true, 'try-fleet/view-query-report': true, 'deliver-talk-to-us-form-submission': true, + 'customers/view-new-license': true, }; diff --git a/website/views/layouts/layout.ejs b/website/views/layouts/layout.ejs index 9825336ecc..66e8709841 100644 --- a/website/views/layouts/layout.ejs +++ b/website/views/layouts/layout.ejs @@ -178,7 +178,7 @@ Chat Hosting Release notes - Get your license + Get your license Contribute @@ -237,7 +237,7 @@ Chat Hosting Release notes - Get your license + Get your license Contribute @@ -318,7 +318,7 @@ Support Docs REST API - Get your license + Get your license Contribute
diff --git a/website/views/pages/entrance/login.ejs b/website/views/pages/entrance/login.ejs index a5b15cfca4..7ed6d7b471 100644 --- a/website/views/pages/entrance/login.ejs +++ b/website/views/pages/entrance/login.ejs @@ -10,7 +10,7 @@
- Create an account + Create an account