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
updated login function within 2fa
TemuulenBM9a23c64dde7f
diff --git a/console/app/controllers/auth/login.js b/console/app/controllers/auth/login.jsindex 1f56ec10..d2b535c5 100644--- a/console/app/controllers/auth/login.js+++ b/console/app/controllers/auth/login.js@@ -11,7 +11,7 @@ export default class AuthLoginController extends Controller {* @var {Controller}*/@controller('auth.forgot-password') forgotPasswordController;-+/*** Inject the `notifications` service*@@ -89,6 +89,8 @@ export default class AuthLoginController extends Controller {*/@tracked failedAttempts = 0;+ @tracked token;+@action async login(event) {// firefox patchevent.preventDefault();@@ -98,12 +100,25 @@ export default class AuthLoginController extends Controller {this.set('isLoading', true);// set where to redirect on loginthis.setRedirect();++ // send request to check for 2fa+ try {+ let { twoFaSession, twoFaEnabled, isTwoFaValidated } = await this.session.checkForTwoFactor(identity);++ if (twoFaEnabled && !isTwoFaValidated) {+ return this.router.transitionTo('auth.two-fa', { token: twoFaSession });+ }+ } catch (error) {+ return this.notifications.serverError(error);+ }+try {await this.session.authenticate('authenticator:fleetbase', { identity, password }, rememberMe);} catch (error) {this.failedAttempts++;return this.failure(error);}+if (this.session.isAuthenticated) {this.success();}diff --git a/console/app/router.js b/console/app/router.jsindex 978ea0fa..562fb2cf 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');@@ -52,16 +53,16 @@ Router.map(function () {path: 'developers'});- this.mount('@fleetbase/iam-engine', {- as: 'iam',- path: 'iam'- });-this.mount('@fleetbase/fleetops-engine', {as: 'fleet-ops',path: 'fleet-ops'});+ this.mount('@fleetbase/iam-engine', {+ as: 'iam',+ path: 'iam'+ });+this.mount('@fleetbase/storefront-engine', {as: 'storefront',path: 'storefront'diff --git a/console/app/routes/auth/two-fa.js b/console/app/routes/auth/two-fa.jsindex 2cc70cc6..b73111d1 100644--- a/console/app/routes/auth/two-fa.js+++ b/console/app/routes/auth/two-fa.js@@ -3,20 +3,40 @@ import { inject as service } from '@ember/service';export default class AuthTwoFaRoute extends Route {@service fetch;+ @service notifications;+ @service session;queryParams = {token: {- refreshModel: false- }- }+ refreshModel: false,+ },+ };++ // beforeModel(transition) {+ // // validate 2fa session with server+ // const { token } = transition.params;++ // return this.fetch.post('two-fa/validate-session', { token }).catch((error) => {+ // this.notifications.serverError(error);+ // return this.redirect('auth.login');+ // });+ // }- beforeModel(transition) {- // validate 2fa session with server- const { token } = transition.params;+ async beforeModel(transition) {+ // Validate 2fa session with the server+ const { token } = transition.to.queryParams;- return this.fetch.post('two-fa/validate-session', { token }).catch((error) => {+ try {+ // Make a request to validate the 2FA session+ await this.fetch.post('two-fa/validate-session', { token });++ // If the session is valid, do nothing, and the transition will continue+ } catch (error) {+ // If the session is not valid, show an error notificationthis.notifications.serverError(error);- return this.redirect('auth.login');- });++ // Redirect to the login route+ this.transitionTo('auth.login');+ }}}