Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
Created 2FA page
TemuulenBM16e59f34651f
diff --git a/console/app/components/two-fa-settings.hbs b/console/app/components/two-fa-settings.hbsindex 8492ebf4..ca7bcbfb 100644--- a/console/app/components/two-fa-settings.hbs+++ b/console/app/components/two-fa-settings.hbs@@ -6,18 +6,9 @@{{#if this.is2FAEnabled}}<div class="mt-6"><label class="text-lg font-medium">Choose an authentication method</label>- <p class="text-sm text-gray-600 mt-1">In addition to your username and password, you'll have to enter a code(delivered via app or SMS) to sign in to your account</p>- {{#if this.selected2FAMethod}}- <p class="text-sm text-gray-600 mt-1">- {{#each this.TwoFaMethods as |method|}}- {{#if (eq this.selected2FAMethod method)}}- {{method.description}}- {{/if}}- {{/each}}- </p>- {{/if}}+ <p class="text-sm text-gray-600 mt-1">In addition to your username and password, you'll have to enter a code (delivered via app or SMS) to sign in to your account</p>{{#each this.TwoFaMethods as |method|}}- <div class="border p-4 mt-2 transition duration-300 {{eq this.selected2FAMethod method 'border-blue-500' 'border-gray-200'}}">+ <div class="border p-4 mt-2 transition duration-300 {{if (eq this.selected2FAMethod method) 'border-blue-500' 'border-gray-200'}}"><input type="radio" name="2fa-method" id="{{method.name}}" checked={{eq this.selected2FAMethod method}} {{on "change" (fn this.select2FAMethod method)}} /><label for="{{method.name}}">{{method.name}}diff --git a/console/app/components/two-fa-settings.js b/console/app/components/two-fa-settings.jsindex 910775e0..2a9f7bde 100644--- a/console/app/components/two-fa-settings.js+++ b/console/app/components/two-fa-settings.js@@ -1,21 +1,35 @@import Component from '@glimmer/component';import { tracked } from '@glimmer/tracking';import { action } from '@ember/object';+import { inject as service } from '@ember/service';export default class TwoFaSettingsComponent extends Component {+ @service fetch;+ @service notifications;+@tracked is2FAEnabled = false;@tracked selected2FAMethod;+TwoFaMethods = [{ name: 'Authenticator App', description: 'Get codes from an app like Authy, 1Password, Microsoft Authenticator, or Google Authenticator', recommended: true },{ name: 'SMS', description: 'Receive a unique code via SMS' },{ name: 'Email', description: 'Receive a unique code via Email' },];- @action toggle2FA() {+ constructor() {+ super(...arguments);+ if (this.is2FAEnabled) {+ this.selected2FAMethod = this.TwoFaMethods.find((method) => method.recommended);+ }+ }++ @action async toggle2FA() {this.is2FAEnabled = !this.is2FAEnabled;if (!this.is2FAEnabled) {this.selected2FAMethod = null;+ } else {+ this.selected2FAMethod = this.TwoFaMethods.find((method) => method.recommended);}}diff --git a/console/app/controllers/auth/login.js b/console/app/controllers/auth/login.jsindex cc43fd58..78e65798 100644--- a/console/app/controllers/auth/login.js+++ b/console/app/controllers/auth/login.js@@ -109,9 +109,18 @@ export default class AuthLoginController extends Controller {try {await this.session.authenticate('authenticator:fleetbase', { email, password }, rememberMe);++ const isTwoFactorEnabled = this.session.user ? this.session.user.isTwoFactorEnabled : false;++ if (isTwoFactorEnabled) {+ // Redirect to the 2FA page if 2FA is enabled+ this.transitionToRoute('auth.two-fa');+ } else {+ // Continue with the default behavior (e.g., redirect to another route)+ this.success();+ }} catch (error) {this.failedAttempts++;-return this.failure(error);}diff --git a/console/app/controllers/auth/two-fa.js b/console/app/controllers/auth/two-fa.jsnew file mode 100644index 00000000..f60aada8--- /dev/null+++ b/console/app/controllers/auth/two-fa.js@@ -0,0 +1,3 @@+import Controller from '@ember/controller';++export default class AuthTwoFaController extends Controller {}diff --git a/console/app/controllers/console/admin/two-fa-settings.js b/console/app/controllers/console/admin/two-fa-settings.jsindex cb8fa7a9..a3d1bdb6 100644--- a/console/app/controllers/console/admin/two-fa-settings.js+++ b/console/app/controllers/console/admin/two-fa-settings.js@@ -1,3 +1,59 @@import Controller from '@ember/controller';+import { inject as service } from '@ember/service';+import { action } from '@ember/object';+import { tracked } from '@glimmer/tracking';-export default class ConsoleAdminTwoFaSettingsController extends Controller {}+export default class ConsoleAdminTwoFaSettingsController extends Controller {+ @service notifications;+ @service currentUser;++ @tracked selected2FAMethod;+ @tracked is2FAEnabled = false;++ // @action+ // async saveSettings() {+ // const currentUser = this.currentUser.user;+ // if (currentUser) {+ // console.log('Before setting meta:', currentUser.meta);+ // currentUser.meta = {+ // two_factor_method: this.selected2FAMethod,+ // };+ // console.log('After setting meta:', currentUser.meta);+ // try {+ // await currentUser.save();+ // this.notifications.success('Settings saved successfully.');+ // } catch (error) {+ // console.error('Error saving settings:', error);+ // this.notifications.error('Failed to save settings.');+ // }+ // } else {+ // console.error('Current user not found.');+ // this.notifications.error('User not found.');+ // }+ // }++ @action+ async saveSettings() {+ const currentUser = this.currentUser.user;+ if (currentUser) {+ if (this.selected2FAMethod) {+ currentUser.meta = {+ two_factor_method: this.selected2FAMethod,+ };+ try {+ await currentUser.save();+ this.notifications.success('Settings saved successfully.');+ } catch (error) {+ console.error('Error saving settings:', error);+ this.notifications.error('Failed to save settings.');+ }+ } else {+ console.error('No selected 2FA method.');+ this.notifications.warning('Please select a 2FA method before saving.');+ }+ } else {+ console.error('Current user not found.');+ this.notifications.error('User not found.');+ }+ }+}diff --git a/console/app/models/user.js b/console/app/models/user.jsindex 595e759c..2c687d1c 100644--- a/console/app/models/user.js+++ b/console/app/models/user.js@@ -79,6 +79,11 @@ export default class UserModel extends Model {@not('isEmailVerified') emailIsNotVerified;@not('isPhoneVerified') phoneIsNotVerified;+ /** @computed */+ @computed('meta') get isTwoFactorEnabled() {+ return this.meta && this.meta.two_factor_enabled;+ }+@computed('types') get typesList() {const types = Array.from(this.types);return types.join(', ');diff --git a/console/app/router.js b/console/app/router.jsindex 6e47e40b..83018ed9 100644--- a/console/app/router.js+++ b/console/app/router.js@@ -11,6 +11,7 @@ Router.map(function () {this.route('login', { path: '/' });this.route('forgot-password');this.route('reset-password');+ this.route('two-fa');});this.route('onboard', function () {this.route('verify-email');@@ -43,8 +44,8 @@ Router.map(function () {});this.route('branding');this.route('notifications');- this.route('virtual', { path: '/:slug/:view' });this.route('two-fa-settings');+ this.route('virtual', { path: '/:slug/:view' });});this.mount('@fleetbase/dev-engine', {@@ -52,11 +53,6 @@ Router.map(function () {path: 'developers',});- this.mount('@fleetbase/fleetops-engine', {- as: 'fleet-ops',- path: 'fleet-ops',- });-this.mount('@fleetbase/iam-engine', {as: 'iam',path: 'iam',@@ -66,6 +62,11 @@ Router.map(function () {as: 'storefront',path: 'storefront',});++ this.mount('@fleetbase/fleetops-engine', {+ as: 'fleet-ops',+ path: 'fleet-ops',+ });});this.route('install');});diff --git a/console/app/routes/auth/two-fa.js b/console/app/routes/auth/two-fa.jsnew file mode 100644index 00000000..6ac23eb2--- /dev/null+++ b/console/app/routes/auth/two-fa.js@@ -0,0 +1,3 @@+import Route from '@ember/routing/route';++export default class AuthTwoFaRoute extends Route {}diff --git a/console/app/routes/console/admin/two-fa-settings.js b/console/app/routes/console/admin/two-fa-settings.jsindex 0165a869..cd82a0a2 100644--- a/console/app/routes/console/admin/two-fa-settings.js+++ b/console/app/routes/console/admin/two-fa-settings.js@@ -1,7 +1,10 @@import Route from '@ember/routing/route';+import { inject as service } from '@ember/service';export default class ConsoleAdminTwoFaSettingsRoute extends Route {- model() {- return {};+ @service store;++ model(params) {+ return this.store.query('user', params);}}diff --git a/console/app/templates/auth/two-fa.hbs b/console/app/templates/auth/two-fa.hbsnew file mode 100644index 00000000..b3d5178c--- /dev/null+++ b/console/app/templates/auth/two-fa.hbs@@ -0,0 +1,41 @@+<div class="bg-white dark:bg-gray-800 py-8 px-4 shadow rounded-lg">+ <div class="mb-4">+ <Image src={{@model.logo_url}} @fallbackSrc="/images/fleetbase-logo-svg.svg" alt={{t "app.name"}} width="160" height="56" class="w-40 h-14 mx-auto" />+ <h2 class="text-center text-lg font-extrabold text-gray-900 dark:text-white truncate">+ {{if this.isSent "Verification Code"}}+ </h2>+ </div>++ <div class="flex px-3 py-2 mb-4 rounded-md shadow-sm bg-green-200">+ <div>+ <FaIcon @icon="check-circle" @size="lg" class="text-green-900 mr-4" />+ </div>+ <p class="flex-1 text-sm text-green-900 dark:text-green-900">+ <strong>Check your SMS!</strong><br />+ We've sent you a verification code via SMS. Enter the code below to complete the login process.+ </p>+ </div>+ <form class="space-y-6" {{on "submit" this.verifyCode}}>+ <div>+ <label for="verificationCode" class="block text-sm font-medium text-gray-700 dark:text-gray-50">+ Verification Code+ </label>+ <div class="mt-2">+ <Input+ @value={{this.verificationCode}}+ @type="text"+ id="verificationCode"+ name="verificationCode"+ required+ class="form-input form-input-lg w-full"+ placeholder="Enter your verification code"+ />+ </div>+ </div>++ <div class="flex flex-row space-x-2">+ <Button @icon="check-circle" @type="primary" @buttonType="submit" @text="Verify Code" @onClick={{this.verifyCode}} @isLoading={{this.isLoading}} />+ <Button @buttonType="button" @text="Cancel" @onClick={{fn (transition-to "auth.login")}} @disabled={{this.isLoading}} />+ </div>+ </form>+</div>\ No newline at end of filediff --git a/console/tests/unit/controllers/auth/two-fa-test.js b/console/tests/unit/controllers/auth/two-fa-test.jsnew file mode 100644index 00000000..0bd93ec3--- /dev/null+++ b/console/tests/unit/controllers/auth/two-fa-test.js@@ -0,0 +1,12 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Controller | auth/two-fa', function (hooks) {+ setupTest(hooks);++ // TODO: Replace this with your real tests.+ test('it exists', function (assert) {+ let controller = this.owner.lookup('controller:auth/two-fa');+ assert.ok(controller);+ });+});diff --git a/console/tests/unit/routes/auth/two-fa-test.js b/console/tests/unit/routes/auth/two-fa-test.jsnew file mode 100644index 00000000..0ca52af6--- /dev/null+++ b/console/tests/unit/routes/auth/two-fa-test.js@@ -0,0 +1,11 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Route | auth/two-fa', function (hooks) {+ setupTest(hooks);++ test('it exists', function (assert) {+ let route = this.owner.lookup('route:auth/two-fa');+ assert.ok(route);+ });+});