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
Tried to verify after verification code is sent
TemuulenBMc5ac6110006a
diff --git a/console/app/controllers/auth/two-fa.js b/console/app/controllers/auth/two-fa.jsindex 57951b03..f8935c6c 100644--- a/console/app/controllers/auth/two-fa.js+++ b/console/app/controllers/auth/two-fa.js@@ -68,14 +68,30 @@ export default class AuthTwoFaController extends Controller {@tracked clientToken;/**- * Tracked property representing the new client token from the validated 2fa session.+ * Tracked property representing the client token from the validated 2fa session.*- * @property {number} newClientSessionToken+ * @property {number} clientToken* @tracked* @default null*/@tracked newClientSessionToken;+ /**+ * Tracked property for storing the verification code.+ *+ * @property {string} verificationCode+ * @tracked+ */+ @tracked verificationCode = '';++ /**+ * Tracked property for storing the verification code.+ *+ * @property {string} verificationCode+ * @tracked+ */+ @tracked otpValue = '';+/*** Tracked property representing the date the 2fa session will expire* @property {Date|null} twoFactorSessionExpiresAfter@@ -98,7 +114,11 @@ export default class AuthTwoFaController extends Controller {** @property {Array} queryParams*/- queryParams = ['token', 'clientToken'];+ queryParams = ['token', 'clientToken', 'newClientSessionToken'];++ constructor() {+ super(...arguments);+ }/*** Action method for verifying the entered verification code.@@ -111,27 +131,22 @@ export default class AuthTwoFaController extends Controller {event.preventDefault();try {- const { token, verificationCode, clientToken, newClientSessionToken, identity } = this;-- console.log('Verification Code:', verificationCode);- console.log('Client Token:', clientToken);- console.log('New Client Session Token:', newClientSessionToken);-- const selectedClientToken = newClientSessionToken || clientToken;-- console.log('selectedClientToken:', selectedClientToken);+ const { token, verificationCode, clientToken, identity, newClientSessionToken } = this;- if (!selectedClientToken) {+ if (!clientToken && !newClientSessionToken) {this.notifications.error('Invalid session. Please try again.');return;}+ console.log("Verification Code to be verified:", verificationCode);+// Call the backend API to verify the entered verification codeconst { authToken } = await this.fetch.post('two-fa/verify-code', {token,verificationCode,- clientToken: selectedClientToken,+ clientToken,identity,+ newClientSessionToken,});// If verification is successful, transition to the desired route@@ -142,27 +157,45 @@ export default class AuthTwoFaController extends Controller {return this.router.transitionTo('console');});} catch (error) {- // Handle verification failure- this.notifications.error('Verification failed. Please try again.');+ if (error.message.includes('Verification code has expired')) {+ this.notifications.info('Verification code has expired. Please request a new one.');+ } else {+ this.notifications.error('Verification failed. Please try again.');+ }}}@action async resendCode() {try {- const { token, clientToken, identity } = this;+ const { identity, token, clientToken } = this;++ if (!clientToken) {+ this.notifications.error('Invalid session. Please try again.');+ return;+ }// Call the backend API to resend the verification code- const { newClientSessionToken } = await this.fetch.post('two-fa/resend-code', {- token,- clientToken,- identity,+ const response = await this.fetch.post('two-fa/resend-code', {+ token: this.token,+ identity: this.identity,+ clientToken: this.clientToken,});- this.newClientSessionToken = newClientSessionToken;+ // const { newClientSessionToken } = response;+ const { newClientSessionToken, generatedVerificationCode } = response;++ if (newClientSessionToken) {+ this.newClientSessionToken = newClientSessionToken;++ console.log("Generated Verification Code:", generatedVerificationCode);- this.notifications.success('Verification code resent successfully.');+ this.notifications.success('Verification code resent successfully.');+ } else {+ this.notifications.error('Failed to get a new client session token. Please try again.');+ }} catch (error) {- // Handle resend failure+ console.error('Error while resending verification code:', error);+ // Handle the error, e.g., show an error notificationthis.notifications.error('Failed to resend verification code. Please try again.');}}@@ -174,9 +207,9 @@ export default class AuthTwoFaController extends Controller {* @param {string} clientToken - Base64 encoded client token.* @returns {Date|null} - Date representing the expiration date, or null if invalid.*/- getExpirationDateFromClientToken(sessionToken) {+ getExpirationDateFromClientToken(clientToken) {const decoder = new TextDecoder();- const binString = atob(sessionToken);+ const binString = atob(clientToken);const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0));const decodedString = decoder.decode(bytes);@@ -203,7 +236,10 @@ export default class AuthTwoFaController extends Controller {const utcDate = new Date(utcDateTimeString);const clientTimezoneOffset = new Date().getTimezoneOffset();const clientDate = new Date(utcDate.getTime() - clientTimezoneOffset * 60 * 1000);-return clientDate;}++ @action handleOtpInput(otpValue) {+ this.verificationCode = otpValue;+ }}diff --git a/console/app/router.js b/console/app/router.jsindex 562fb2cf..5b5de27d 100644--- a/console/app/router.js+++ b/console/app/router.js@@ -53,16 +53,16 @@ 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'});+ this.mount('@fleetbase/fleetops-engine', {+ as: 'fleet-ops',+ path: 'fleet-ops'+ });+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 d2e19cf6..2581f9bf 100644--- a/console/app/routes/auth/two-fa.js+++ b/console/app/routes/auth/two-fa.js@@ -66,15 +66,16 @@ export default class AuthTwoFaRoute extends Route {return this.router.transitionTo('auth.login');}- const selectedClientToken = newClientSessionToken || clientToken;-return this.fetch- .post('two-fa/validate-session', { token, identity, clientToken: selectedClientToken })- .then(({ clientToken }) => {+ .post('two-fa/validate-session', { token, identity, clientToken, newClientSessionToken })+ .then(({ clientToken, newClientSessionToken }) => {+ const tokenToPersist = clientToken || newClientSessionToken;// clear session data after validated 2fa sessionthis.session.store.persist({identity,+ token: tokenToPersist,clientToken,+ newClientSessionToken,});}).catch((error) => {@@ -92,11 +93,11 @@ export default class AuthTwoFaRoute extends Route {setupController(controller) {super.setupController(...arguments);- this.session.store.restore().then(({ clientToken, newClientSessionToken, identity }) => {+ this.session.store.restore().then(({ clientToken, identity, newClientSessionToken }) => {controller.clientToken = clientToken;controller.newClientSessionToken = newClientSessionToken;controller.identity = identity;- controller.twoFactorSessionExpiresAfter = controller.getExpirationDateFromClientToken(clientToken || newClientSessionToken);+ controller.twoFactorSessionExpiresAfter = controller.getExpirationDateFromClientToken(clientToken);controller.countdownReady = true;});}diff --git a/console/app/templates/auth/two-fa.hbs b/console/app/templates/auth/two-fa.hbsindex afe3e0a1..3894dc80 100644--- a/console/app/templates/auth/two-fa.hbs+++ b/console/app/templates/auth/two-fa.hbs@@ -1,50 +1,36 @@-<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 class="mb-8 text-center">+ <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-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 {{this.selectedMethod}}</strong><br />+ We've sent you a verification code. Enter the code below to complete the login process.+ </p>+</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 {{this.selectedMethod}}</strong><br />- We've sent you a verification code. Enter the code below to complete the login process.- </p>+<form class="mt-8" {{on "submit" this.verifyCode}}>+ <div class="flex items-center justify-between mt-6">+ <OtpInput @onInput={{this.handleOtpInput}}/></div>++ {{#if this.countdownReady}}+ <Countdown @expiry={{this.twoFactorSessionExpiresAfter}} />+ {{/if}}- <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>- {{#if this.countdownReady}}- <Countdown @expiry={{this.twoFactorSessionExpiresAfter}} />- {{/if}}- <div class="text-right">- <a href="#" class="text-sm text-blue-500 hover:underline" {{on "click" this.resendCode}}>- Resend Code- </a>- </div>+ <div class="mt-6">+ <Button @buttonType="submit" @type="primary" @text="Verify Code" @icon="check-circle" @wrapperClass="btn-block" @isLoading={{this.isLoading}} />+ </div>- <div class="flex flex-row space-x-2">- <Button @icon="check-circle" @type="primary" @buttonType="submit" @text="Verify Code" @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 file+ <div class="text-center">+ <a href="#" class="text-sm text-blue-500 hover:underline inline-block" {{on "click" this.resendCode}}>+ Resend Code+ </a>+ </div>+</form>\ No newline at end of file