From c3210f044d790997845e4da47237c913bfba65ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 15 Sep 2021 11:45:48 +0200 Subject: [PATCH] MOBILE-3676 site: Check qrcode type from site config --- src/core/classes/site.ts | 10 ++++++++++ .../login/pages/credentials/credentials.ts | 2 +- .../features/login/pages/reconnect/reconnect.ts | 2 +- src/core/features/login/services/login-helper.ts | 15 +++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index c3593943a..5105c2b2e 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -41,6 +41,15 @@ import { CoreLogger } from '@singletons/logger'; import { Translate } from '@singletons'; import { CoreIonLoadingElement } from './ion-loading'; +/** + * QR Code type enumeration. + */ +export enum CoreSiteQRCodeType { + QR_CODE_DISABLED = 0, // QR code disabled value + QR_CODE_URL = 1, // QR code type URL value + QR_CODE_LOGIN = 2, // QR code type login value +} + /** * Class that represents a site (combination of site + user). * It will have all the site data and provide utility functions regarding a site. @@ -2122,6 +2131,7 @@ export type CoreSitePublicConfigResponse = { tool_mobile_androidappid?: string; // Android app's unique identifier. // eslint-disable-next-line @typescript-eslint/naming-convention tool_mobile_setuplink?: string; // App download page. + tool_mobile_qrcodetype?: CoreSiteQRCodeType; // eslint-disable-line @typescript-eslint/naming-convention warnings?: CoreWSExternalWarning[]; }; diff --git a/src/core/features/login/pages/credentials/credentials.ts b/src/core/features/login/pages/credentials/credentials.ts index c3189ef06..ad4e804ce 100644 --- a/src/core/features/login/pages/credentials/credentials.ts +++ b/src/core/features/login/pages/credentials/credentials.ts @@ -177,7 +177,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { this.siteName = CoreConstants.CONFIG.sitename ? CoreConstants.CONFIG.sitename : this.siteConfig.sitename; this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig); this.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps'); - this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(); + this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype); const disabledFeatures = CoreLoginHelper.getDisabledFeatures(this.siteConfig); this.identityProviders = CoreLoginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures); diff --git a/src/core/features/login/pages/reconnect/reconnect.ts b/src/core/features/login/pages/reconnect/reconnect.ts index bb5193d2a..b34720cdd 100644 --- a/src/core/features/login/pages/reconnect/reconnect.ts +++ b/src/core/features/login/pages/reconnect/reconnect.ts @@ -135,7 +135,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { } this.showScanQR = CoreLoginHelper.displayQRInSiteScreen() || - CoreLoginHelper.displayQRInCredentialsScreen(); + CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype); await CoreSites.checkApplication(this.siteConfig); diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index 75c316eb2..8f9780fc3 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -26,7 +26,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreUrlParams, CoreUrlUtils } from '@services/utils/url'; import { CoreUtils } from '@services/utils/utils'; import { CoreConstants } from '@/core/constants'; -import { CoreSite, CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/site'; +import { CoreSite, CoreSiteIdentityProvider, CoreSitePublicConfigResponse, CoreSiteQRCodeType } from '@classes/site'; import { CoreError } from '@classes/errors/error'; import { CoreWSError } from '@classes/errors/wserror'; import { makeSingleton, Translate } from '@singletons'; @@ -1237,15 +1237,22 @@ export class CoreLoginHelperProvider { /** * Check whether the QR reader should be displayed in credentials screen. * + * @param qrCodeType QR Code type from public config, assuming enabled if undefined. * @return Whether the QR reader should be displayed in credentials screen. */ - displayQRInCredentialsScreen(): boolean { + displayQRInCredentialsScreen(qrCodeType = CoreSiteQRCodeType.QR_CODE_LOGIN): boolean { if (!CoreUtils.canScanQR()) { return false; } - return (CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) || - (CoreConstants.CONFIG.displayqroncredentialscreen !== undefined && !!CoreConstants.CONFIG.displayqroncredentialscreen); + if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) || + (CoreConstants.CONFIG.displayqroncredentialscreen !== undefined && + !!CoreConstants.CONFIG.displayqroncredentialscreen)) { + + return qrCodeType == CoreSiteQRCodeType.QR_CODE_LOGIN; + } + + return false; } /**