fleet/website/api/controllers/customers/view-new-license.js
Eric 48f86b21b1
Website: Add admin tool for generating Fleet Premium licenses. (#8478)
* create admin/generate-license page

* create generate-license-key action, update routes, policies, importer, regenerate cloud-sdk

* update layouts

* use moment

* Update view-generate-license.js

* Fixing lint errors

* Update generate-license-key.js

* Update redirects in is-super-admin policy

* redirect super admins to the license generator

* Update login form

* requested changes from mike-j-thomas

* Update generate-license.page.js

* Update is-super-admin.js

* Update view-login.js

* Update generate-license-key.js

* Update generate-license-key.js

* use naming convention for js timestamps

* validTo » expiresAt

Co-authored-by: Mike McNeil <[email protected]>
2022-12-05 14:53:16 -06:00

46 lines
1.1 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'View new license',
description: 'Display "New license" page.',
exits: {
success: {
viewTemplatePath: 'pages/customers/new-license'
},
redirect: {
description: 'The requesting user already has a subscription, or does not exist',
responseType: 'redirect',
}
},
fn: async function () {
// if the user isn't logged in, we'll redirect them to the register page.
if (!this.req.me) {
throw {redirect: '/customers/register'};
}
// If the user is a super admin, we'll redirect them to the generate-license page.
if(this.req.me.isSuperAdmin) {
throw {redirect: '/admin/generate-license'};
}
// If the user has a license key, we'll redirect them to the customer dashboard.
let userHasExistingSubscription = await Subscription.findOne({user: this.req.me.id});
if (userHasExistingSubscription) {
throw {redirect: '/customers/dashboard?login'};
}
// Respond with view.
return { stripePublishableKey: sails.config.custom.stripePublishableKey};
}
};