fleet/website/api/controllers/view-fleetctl-preview.js
Eric c915c258b9
Website: Remove account requirement for /try-fleet page. (#29904)
Closes: https://github.com/fleetdm/confidential/issues/10921

Changes:
- Updated the registration form to direct users who don't have a work
email or don't want to create an account to the /try-fleet page.
- Updated the try-fleet page to have a box directing users who want to
demo Fleet Premium features to sign up for an account.
- Updated the try-fleet page's view action to generate trial licenses
for logged-in users who do not have a trial license key.
2025-06-11 09:06:38 -05:00

70 lines
1.9 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'View fleetctl preview',
description: 'Display "fleetctl preview" page.',
inputs: {
start: {
type: 'boolean',
description: 'A boolean flag that will hide the "next steps" buttons on the page if set to true',
defaultsTo: false,
}
},
exits: {
success: {
viewTemplatePath: 'pages/fleetctl-preview'
}
},
fn: async function ({start}) {
let userHasTrialLicense = false;
let trialLicenseKey;
let userHasExpiredTrialLicense = false;
if(this.req.me) {
userHasTrialLicense = this.req.me.fleetPremiumTrialLicenseKey;
// Check to see if this user has a Fleet premium trial license key.
if(userHasTrialLicense) {
if(this.req.me.fleetPremiumTrialLicenseKeyExpiresAt < Date.now()) {
userHasExpiredTrialLicense = true;
}
trialLicenseKey = this.req.me.fleetPremiumTrialLicenseKey;
} else {
// If this user is logged in and does not have a trial license key, generate a new one for them.
let thirtyDaysFromNowAt = Date.now() + (1000 * 60 * 60 * 24 * 30);
let trialLicenseKeyForThisUser = await sails.helpers.createLicenseKey.with({
numberOfHosts: 10,
organization: this.req.me.organization,
expiresAt: thirtyDaysFromNowAt,
});
// Save the trial license key to the DB record for this user.
await User.updateOne({id: this.req.me.id})
.set({
fleetPremiumTrialLicenseKey: trialLicenseKeyForThisUser,
fleetPremiumTrialLicenseKeyExpiresAt: thirtyDaysFromNowAt,
});
trialLicenseKey = trialLicenseKeyForThisUser;
userHasTrialLicense = true;
}
}
// Respond with view.
return {
hideNextStepsButtons: start,
trialLicenseKey,
userHasTrialLicense,
userHasExpiredTrialLicense,
};
}
};