From ff00454e33fc3ad532091ba7c86afb8248135a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 25 Aug 2023 15:03:53 +0200 Subject: [PATCH 01/11] MOBILE-4201 login: Move oauth and scanQR to login methods component --- .../login-methods/login-methods.html | 28 ++++++- .../components/login-methods/login-methods.ts | 74 +++++++++++++++++-- .../login/pages/credentials/credentials.html | 21 +----- .../login/pages/credentials/credentials.ts | 33 +-------- .../login/pages/reconnect/reconnect.html | 32 +------- .../login/pages/reconnect/reconnect.ts | 53 ++----------- .../features/login/services/login-helper.ts | 1 + 7 files changed, 106 insertions(+), 136 deletions(-) diff --git a/src/core/features/login/components/login-methods/login-methods.html b/src/core/features/login/components/login-methods/login-methods.html index 1e6323288..3ce4e3fa9 100644 --- a/src/core/features/login/components/login-methods/login-methods.html +++ b/src/core/features/login/components/login-methods/login-methods.html @@ -1,7 +1,33 @@ - + + + + + + + + + diff --git a/src/core/features/login/components/login-methods/login-methods.ts b/src/core/features/login/components/login-methods/login-methods.ts index b0c78e299..606e2ee13 100644 --- a/src/core/features/login/components/login-methods/login-methods.ts +++ b/src/core/features/login/components/login-methods/login-methods.ts @@ -12,9 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; +import { CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/site'; import { CoreLoginHelper, CoreLoginMethod } from '@features/login/services/login-helper'; +import { CoreRedirectPayload } from '@services/navigator'; import { CoreSites } from '@services/sites'; +import { CoreDomUtils } from '@services/utils/dom'; @Component({ selector: 'core-login-methods', @@ -23,18 +26,75 @@ import { CoreSites } from '@services/sites'; }) export class CoreLoginMethodsComponent implements OnInit { - loginMethods?: CoreLoginMethod[]; + @Input() reconnect = false; + @Input() siteUrl = ''; + @Input() siteConfig?: CoreSitePublicConfigResponse; + @Input() redirectData?: CoreRedirectPayload; + + showScanQR = false; + loginMethods: CoreLoginMethod[] = []; + identityProviders: CoreSiteIdentityProvider[] = []; /** * @inheritdoc */ async ngOnInit(): Promise { - this.loginMethods = await CoreLoginHelper.getLoginMethods(); - const currentSite = CoreSites.getCurrentSite(); - const defaultMethod = await CoreLoginHelper.getDefaultLoginMethod(); + if (this.reconnect) { + this.loginMethods = await CoreLoginHelper.getLoginMethods(); - if (currentSite?.isLoggedOut() && defaultMethod) { - await defaultMethod.action(); + const currentSite = CoreSites.getCurrentSite(); + const defaultMethod = await CoreLoginHelper.getDefaultLoginMethod(); + if (currentSite?.isLoggedOut() && defaultMethod) { + await defaultMethod.action(); + } + } + + if (this.siteConfig) { + const disabledFeatures = CoreLoginHelper.getDisabledFeatures(this.siteConfig); + + this.identityProviders = CoreLoginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures); + + if (this.reconnect) { + this.showScanQR = CoreLoginHelper.displayQRInSiteScreen(); + } + + // If still false or credentials screen. + if (!this.reconnect || !this.showScanQR) { + this.showScanQR = await CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype); + } + } + } + + /** + * Show instructions and scan QR code. + * + * @returns Promise resolved when done. + */ + async showInstructionsAndScanQR(): Promise { + try { + await CoreLoginHelper.showScanQRInstructions(); + + await CoreLoginHelper.scanQR(); + } catch { + // Ignore errors. + } + } + + /** + * An OAuth button was clicked. + * + * @param provider The provider that was clicked. + */ + oauthClicked(provider: CoreSiteIdentityProvider): void { + const result = CoreLoginHelper.openBrowserForOAuthLogin( + this.siteUrl, + provider, + this.siteConfig?.launchurl, + this.redirectData, + ); + + if (!result) { + CoreDomUtils.showErrorModal('Invalid data.'); } } diff --git a/src/core/features/login/pages/credentials/credentials.html b/src/core/features/login/pages/credentials/credentials.html index ca5b410eb..eecf03a27 100644 --- a/src/core/features/login/pages/credentials/credentials.html +++ b/src/core/features/login/pages/credentials/credentials.html @@ -59,14 +59,6 @@ - - - - - @@ -75,18 +67,7 @@ {{ 'core.login.forgotten' | translate }} - +