Skip to content

Modular logistics and supply chain operating system (LSOS)

Completed validate and change password flow for account

TemuulenBM09996a4398f0
diff --git a/console/app/controllers/console/account/auth.js b/console/app/controllers/console/account/auth.js
index f4087821..6487943f 100644
--- a/console/app/controllers/console/account/auth.js
+++ b/console/app/controllers/console/account/auth.js
@@ -5,30 +5,135 @@ import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency-decorators';
import getTwoFaMethods from '@fleetbase/console/utils/get-two-fa-methods';
+/**
+ * Controller for managing user authentication and password-related actions in the console.
+ *
+ * @class ConsoleAccountAuthController
+ * @extends Controller
+ */
export default class ConsoleAccountAuthController extends Controller {
+ /**
+ * Service for handling data fetching.
+ *
+ * @type {fetch}
+ */
@service fetch;
+
+ /**
+ * Service for displaying notifications.
+ *
+ * @type {notifications}
+ */
+ @service notifications;
+
+ /**
+ * Service for managing application routing.
+ *
+ * @type {router}
+ */
+ @service router;
+
+ /**
+ * The user's current password.
+ * @type {string}
+ */
@tracked password;
+
+ /**
+ * The user's confirmation of the new password.
+ *
+ * @type {string}
+ */
@tracked confirmPassword;
+
+ /**
+ * The new password the user intends to set.
+ *
+ * @type {string}
+ */
@tracked newPassword;
+
+ /**
+ * The user's confirmation of the new password.
+ *
+ * @type {string}
+ */
+ @tracked newConfirmPassword;
+
+ /**
+ * Flag indicating whether the current password has been validated.
+ *
+ * @type {boolean}
+ */
+ @tracked isPasswordValidated = false;
+
+ /**
+ * System-wide two-factor authentication configuration.
+ *
+ * @type {Object}
+ */
@tracked twoFaConfig = {};
+
+ /**
+ * User-specific two-factor authentication settings.
+ *
+ * @type {Object}
+ */
@tracked twoFaSettings = {};
+
+ /**
+ * Flag indicating whether system-wide two-factor authentication is enabled.
+ *
+ * @type {boolean}
+ */
@tracked isSystemTwoFaEnabled = false;
+
+ /**
+ * Available two-factor authentication methods.
+ *
+ * @type {Array}
+ */
@tracked methods = getTwoFaMethods();
+ /**
+ * Constructor method for the ConsoleAccountAuthController.
+ *
+ * @constructor
+ */
constructor() {
super(...arguments);
this.loadSystemTwoFaConfig.perform();
this.loadUserTwoFaSettings.perform();
}
+ /**
+ * Validates the user's current password.
+ *
+ * @method validatePassword
+ * @param {Event} event - The event object triggering the action.
+ */
@action validatePassword(event) {
event.preventDefault();
+ this.validatePasswordTask.perform();
}
+ /**
+ * Initiates the task to change the user's password asynchronously.
+ *
+ * @method changeUserPasswordTask
+ * @param {Event} event - The event object triggering the action.
+ */
@action changeUserPassword(event) {
event.preventDefault();
+ this.changeUserPasswordTask.perform();
}
+ /**
+ * Handles the event when two-factor authentication is toggled.
+ *
+ * @method onTwoFaToggled
+ * @param {boolean} enabled - Whether two-factor authentication is enabled or not.
+ */
@action onTwoFaToggled(enabled) {
this.twoFaSettings = {
...this.twoFaSettings,
@@ -36,6 +141,12 @@ export default class ConsoleAccountAuthController extends Controller {
};
}
+ /**
+ * Handles the event when a two-factor authentication method is selected.
+ *
+ * @method onTwoFaMethodSelected
+ * @param {string} method - The selected two-factor authentication method.
+ */
@action onTwoFaMethodSelected(method) {
this.twoFaSettings = {
...this.twoFaSettings,
@@ -43,10 +154,21 @@ export default class ConsoleAccountAuthController extends Controller {
};
}
+ /**
+ * Initiates the task to save user-specific two-factor authentication settings asynchronously.
+ *
+ * @method saveTwoFactorAuthSettings
+ */
@action saveTwoFactorAuthSettings() {
this.saveUserTwoFaSettings.perform(this.twoFaSettings);
}
+ /**
+ * Initiates the task to save user-specific two-factor authentication settings asynchronously.
+ *
+ * @method saveUserTwoFaSettings
+ * @param {Object} twoFaSettings - User-specific two-factor authentication settings.
+ */
@task *saveUserTwoFaSettings(twoFaSettings = {}) {
yield this.fetch
.post('users/two-fa', { twoFaSettings })
@@ -58,16 +180,25 @@ export default class ConsoleAccountAuthController extends Controller {
});
}
+ /**
+ * Initiates the task to load user-specific two-factor authentication settings asynchronously.
+ *
+ * @method loadUserTwoFaSettings
+ */
@task *loadUserTwoFaSettings() {
const twoFaSettings = yield this.fetch.get('users/two-fa');
if (twoFaSettings) {
this.twoFaSettings = twoFaSettings;
}
-
return twoFaSettings;
}
+ /**
+ * Initiates the task to load system-wide two-factor authentication configuration asynchronously.
+ *
+ * @method loadSystemTwoFaConfig
+ */
@task *loadSystemTwoFaConfig() {
const twoFaConfig = yield this.fetch.get('two-fa/config');
@@ -75,7 +206,43 @@ export default class ConsoleAccountAuthController extends Controller {
this.isSystemTwoFaEnabled = twoFaConfig.enabled;
this.twoFaConfig = twoFaConfig;
}
-
return twoFaConfig;
}
+
+ /**
+ * Initiates the task to validate the user's current password asynchronously.
+ *
+ * @method validatePasswordTask
+ */
+ @task *validatePasswordTask() {
+ try {
+ yield this.fetch.post('users/validate-password', {
+ current_password: this.password,
+ confirm_password: this.confirmPassword,
+ });
+
+ this.isPasswordValidated = true;
+ } catch (error) {
+ this.notifications.error('Invalid current password.');
+ }
+ }
+
+ /**
+ * Initiates the task to change the user's password asynchronously.
+ *
+ * @method changeUserPasswordTask
+ */
+ @task *changeUserPasswordTask() {
+ try {
+ yield this.fetch.post('users/change-password', {
+ password: this.newPassword,
+ password_confirmation: this.newConfirmPassword,
+ });
+
+ this.notifications.success('Password change successfully.');
+ this.router.transitionTo('console');
+ } catch (error) {
+ this.notifications.error('Failed to change password');
+ }
+ }
}
diff --git a/console/app/controllers/console/settings/auth.js b/console/app/controllers/console/settings/auth.js
index af8e543a..f010a833 100644
--- a/console/app/controllers/console/settings/auth.js
+++ b/console/app/controllers/console/settings/auth.js
@@ -1,3 +1,131 @@
import Controller from '@ember/controller';
+import { tracked } from '@glimmer/tracking';
+import { action } from '@ember/object';
+import { inject as service } from '@ember/service';
+import { task } from 'ember-concurrency-decorators';
+import getTwoFaMethods from '@fleetbase/console/utils/get-two-fa-methods';
-export default class ConsoleSettingsAuthController extends Controller {}
+export default class ConsoleSettingsAuthController extends Controller {
+ /**
+ * Service for handling data fetching.
+ *
+ * @type {fetch}
+ */
+ @service fetch;
+
+ /**
+ * Service for displaying notifications.
+ *
+ * @type {notifications}
+ */
+ @service notifications;
+
+ /**
+ * System-wide two-factor authentication configuration.
+ *
+ * @type {Object}
+ */
+ @tracked twoFaConfig = {};
+
+ /**
+ * User-specific two-factor authentication settings.
+ *
+ * @type {Object}
+ */
+ @tracked twoFaSettings = {};
+
+ /**
+ * Flag indicating whether system-wide two-factor authentication is enabled.
+ *
+ * @type {boolean}
+ */
+ @tracked isSystemTwoFaEnabled = false;
+
+ /**
+ * Available two-factor authentication methods.
+ *
+ * @type {Array}
+ */
+ @tracked methods = getTwoFaMethods();
+
+ /**
+ * Constructor method for the ConsoleAccountAuthController.
+ *
+ * @constructor
+ */
+ constructor() {
+ super(...arguments);
+ this.loadSystemTwoFaConfig.perform();
+ this.loadCompanyTwoFaSettings.perform();
+ }
+
+ /**
+ * Handles the event when two-factor authentication is toggled.
+ *
+ * @method onTwoFaToggled
+ * @param {boolean} enabled - Whether two-factor authentication is enabled or not.
+ */
+ @action onTwoFaToggled(enabled) {
+ this.twoFaSettings = {
+ ...this.twoFaSettings,
+ enabled,
+ };
+ }
+
+ /**
+ * Handles the event when a two-factor authentication method is selected.
+ *
+ * @method onTwoFaMethodSelected
+ * @param {string} method - The selected two-factor authentication method.
+ */
+ @action onTwoFaMethodSelected(method) {
+ this.twoFaSettings = {
+ ...this.twoFaSettings,
+ method,
+ };
+ }
+
+ @action enforceTwoFaForCompanyUsersAction() {
+ this.enforceTwoFaForCompanyUsers.perform(this.twoFaSettings);
+ }
+
+ /**
+ * Initiates the task to load user-specific two-factor authentication settings asynchronously.
+ *
+ * @method loadUserTwoFaSettings
+ */
+ @task *loadCompanyTwoFaSettings() {
+ const twoFaSettings = yield this.fetch.get('companies/two-fa');
+
+ if (twoFaSettings) {
+ this.twoFaSettings = twoFaSettings;
+ }
+ return twoFaSettings;
+ }
+
+ /**
+ * Initiates the task to load system-wide two-factor authentication configuration asynchronously.
+ *
+ * @method loadSystemTwoFaConfig
+ */
+ @task *loadSystemTwoFaConfig() {
+ const twoFaConfig = yield this.fetch.get('two-fa/config');
+
+ if (twoFaConfig) {
+ this.isSystemTwoFaEnabled = twoFaConfig.enabled;
+ this.twoFaConfig = twoFaConfig;
+ }
+ return twoFaConfig;
+ }
+
+ @task *enforceTwoFaForCompanyUsers(twoFaSettings = {}) {
+ yield this.fetch
+ .post('companies/enforce', { twoFaSettings })
+ .then(() => {
+ this.notifications.success('2FA Settings enforced for all users successfully.');
+ })
+ .catch((error) => {
+ this.notifications.serverError(error);
+ });
+ }
+}
diff --git a/console/app/router.js b/console/app/router.js
index 5b5de27d..ae840575 100644
--- a/console/app/router.js
+++ b/console/app/router.js
@@ -26,9 +26,11 @@ Router.map(function () {
this.route('notifications');
this.route('account', function () {
this.route('virtual', { path: '/:slug/:view' });
+ this.route('auth');
});
this.route('settings', function () {
this.route('virtual', { path: '/:slug/:view' });
+ this.route('auth');
});
this.route('virtual', { path: '/:slug/:view' });
this.route('admin', function () {
diff --git a/console/app/templates/console/account/auth.hbs b/console/app/templates/console/account/auth.hbs
index fb423552..63cc160b 100644
--- a/console/app/templates/console/account/auth.hbs
+++ b/console/app/templates/console/account/auth.hbs
@@ -5,38 +5,51 @@
<div class="container mx-auto h-screen" {{increase-height-by 500}}>
<div class="max-w-3xl my-10 mx-auto space-y-6">
<ContentPanel @title="Change Password" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
- {{#unless this.passwordsValidated}}
+ {{#if this.isPasswordValidated}}
<form id="validate-password-form" aria-label="validate-password" {{on "submit" this.validatePassword}}>
<legend class="mb-3">Validate Current Password</legend>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
<InputGroup @name="Password" @type="password" @value={{this.password}} />
<InputGroup @name="Confirm Password" @type="password" @value={{this.confirmPassword}} />
</div>
- <Button @type="primary" @buttonType="submit" @text="Continue" @icon="check" />
+ <Button @type="primary" @buttonType="submit" @text="Continue" @icon="check" {{on "click" this.validatePassword}} />
</form>
{{else}}
<form id="change-password-form" aria-label="change-password" {{on "submit" this.changeUserPassword}}>
<legend class="mb-3">Change Password</legend>
- <div class="grid grid-cols-1 gap-4">
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
<InputGroup @name="Enter new Password" @type="password" @value={{this.newPassword}} />
+ <InputGroup @name="Confirm Password" @type="password" @value={{this.newConfirmPassword}} />
</div>
- <Button @type="primary" @buttonType="submit" @text="Confirm & Change Password" @icon="save" />
+ <Button @type="primary" @buttonType="submit" @text="Confirm & Change Password" @icon="save" {{on "click" this.changeUserPassword}} />
</form>
- {{/unless}}
+ {{/if}}
</ContentPanel>
{{#if this.isSystemTwoFaEnabled}}
<ContentPanel @title="2FA Settings" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<div class="mb-3">
{{#if this.loadUserTwoFaSettings.isIdle}}
- <TwoFaSettings @twoFaMethods={{this.methods}} @twoFaSettings={{this.twoFaSettings}} @onTwoFaToggled={{this.onTwoFaToggled}} @onTwoFaMethodSelected={{this.onTwoFaMethodSelected}} />
+ <TwoFaSettings
+ @twoFaMethods={{this.methods}}
+ @twoFaSettings={{this.twoFaSettings}}
+ @onTwoFaToggled={{this.onTwoFaToggled}}
+ @onTwoFaMethodSelected={{this.onTwoFaMethodSelected}}
+ />
{{else}}
<div class="flex items-center justify-center p-4">
<Spinner @loadingMessage="Loading User 2FA Settings..." @wrapperClass="flex flex-row" @iconClass="mr-2" />
</div>
{{/if}}
</div>
- <Button @type="primary" @buttonType="submit" @text="Save 2FA Settings" @icon="save" @onClick={{this.saveTwoFactorAuthSettings}} @isLoading={{this.saveUserTwoFaSettings.isRunning}} />
+ <Button
+ @type="primary"
+ @buttonType="submit"
+ @text="Save 2FA Settings"
+ @icon="save"
+ @onClick={{this.saveTwoFactorAuthSettings}}
+ @isLoading={{this.saveUserTwoFaSettings.isRunning}}
+ />
</ContentPanel>
{{/if}}
</div>
diff --git a/console/app/templates/console/settings.hbs b/console/app/templates/console/settings.hbs
index 39e5f2ec..aba75156 100644
--- a/console/app/templates/console/settings.hbs
+++ b/console/app/templates/console/settings.hbs
@@ -2,17 +2,27 @@
<EmberWormhole @to="sidebar-menu-items">
<Layout::Sidebar::Panel @open={{true}} @title="Settings">
<Layout::Sidebar::Item @route="console.settings.index" @icon="cog">Organization</Layout::Sidebar::Item>
+ <Layout::Sidebar::Item @route="console.settings.auth" @icon="key">Auth</Layout::Sidebar::Item>
{{#each this.universe.settingsMenuItems as |menuItem|}}
- <Layout::Sidebar::Item @onClick={{fn this.universe.transitionMenuItem "console.settings.virtual" menuItem}} @item={{menuItem}} @icon={{menuItem.icon}}>{{menuItem.title}}</Layout::Sidebar::Item>
+ <Layout::Sidebar::Item
+ @onClick={{fn this.universe.transitionMenuItem "console.settings.virtual" menuItem}}
+ @item={{menuItem}}
+ @icon={{menuItem.icon}}
+ >{{menuItem.title}}</Layout::Sidebar::Item>
{{/each}}
</Layout::Sidebar::Panel>
{{#each this.universe.settingsMenuPanels as |menuPanel|}}
<Layout::Sidebar::Panel @open={{menuPanel.open}} @title={{menuPanel.title}}>
{{#each menuPanel.items as |menuItem|}}
- <Layout::Sidebar::Item @onClick={{fn this.universe.transitionMenuItem "console.settings.virtual" menuItem}} @item={{menuItem}} @icon={{menuItem.icon}}>{{menuItem.title}}</Layout::Sidebar::Item>
+ <Layout::Sidebar::Item
+ @onClick={{fn this.universe.transitionMenuItem "console.settings.virtual" menuItem}}
+ @item={{menuItem}}
+ @icon={{menuItem.icon}}
+ >{{menuItem.title}}</Layout::Sidebar::Item>
{{/each}}
</Layout::Sidebar::Panel>
{{/each}}
+
</EmberWormhole>
{{outlet}}
\ No newline at end of file
diff --git a/console/app/templates/console/settings/auth.hbs b/console/app/templates/console/settings/auth.hbs
index 3238cf1d..ef63e203 100644
--- a/console/app/templates/console/settings/auth.hbs
+++ b/console/app/templates/console/settings/auth.hbs
@@ -1,2 +1,34 @@
-{{page-title "Auth"}}
-{{outlet}}
\ No newline at end of file
+{{page-title "Organization Auth"}}
+<Layout::Section::Header @title="Organization Auth" />
+
+<Layout::Section::Body class="overflow-y-scroll h-full">
+ <div class="container mx-auto h-screen" {{increase-height-by 500}}>
+ <div class="max-w-3xl my-10 mx-auto space-y-6">
+
+ <ContentPanel @title="Enforce 2FA Settings For All Users" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
+ <div class="mb-3">
+ {{#if this.loadCompanyTwoFaSettings.isIdle}}
+ <TwoFaSettings
+ @twoFaMethods={{this.methods}}
+ @twoFaSettings={{this.twoFaSettings}}
+ @onTwoFaToggled={{this.onTwoFaToggled}}
+ @onTwoFaMethodSelected={{this.onTwoFaMethodSelected}}
+ />
+ {{else}}
+ <div class="flex items-center justify-center p-4">
+ <Spinner @loadingMessage="Loading User 2FA Settings..." @wrapperClass="flex flex-row" @iconClass="mr-2" />
+ </div>
+ {{/if}}
+ </div>
+ <Button
+ @type="primary"
+ @buttonType="submit"
+ @text="Save 2FA Settings"
+ @icon="save"
+ @onClick={{this.enforceTwoFaForCompanyUsersAction}}
+ @isLoading={{this.enforceTwoFaForCompanyUsersAction.isRunning}}
+ />
+ </ContentPanel>
+ </div>
+ </div>
+</Layout::Section::Body>
\ No newline at end of file