From 8df8c242702070fa03c317f07d8e6c5e4a9f2ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 29 Jun 2020 16:14:13 +0200 Subject: [PATCH 1/2] MOBILE-3458 login: Show qr when configured --- src/config.json | 3 +- src/core/login/login.scss | 6 ++ .../login/pages/credentials/credentials.html | 10 ++++ .../login/pages/credentials/credentials.ts | 56 +++++++++++++++++++ src/core/login/pages/site/site.html | 21 ++++--- src/core/login/pages/site/site.scss | 6 -- src/core/login/pages/site/site.ts | 4 +- 7 files changed, 87 insertions(+), 19 deletions(-) diff --git a/src/config.json b/src/config.json index 7b6e032bd..0a6c014e4 100644 --- a/src/config.json +++ b/src/config.json @@ -81,6 +81,7 @@ "siteurl": "", "sitename": "", "multisitesdisplay": "", + "onlyallowlistedsites": false, "skipssoconfirmation": false, "forcedefaultlanguage": false, "privacypolicy": "https:\/\/moodle.net\/moodle-app-privacy\/", @@ -104,4 +105,4 @@ "mac": "id1255924440", "linux": "https:\/\/download.moodle.org\/desktop\/download.php?platform=linux&arch=64" } -} \ No newline at end of file +} diff --git a/src/core/login/login.scss b/src/core/login/login.scss index 5b5ba112a..8206b3750 100644 --- a/src/core/login/login.scss +++ b/src/core/login/login.scss @@ -105,4 +105,10 @@ ion-app.app-root page-core-login-site { background: transparent; } } + + .core-login-site-qrcode-separator { + text-align: center; + margin-top: 12px; + font-size: 1.2em; + } } diff --git a/src/core/login/pages/credentials/credentials.html b/src/core/login/pages/credentials/credentials.html index eb2eab7ed..749997711 100644 --- a/src/core/login/pages/credentials/credentials.html +++ b/src/core/login/pages/credentials/credentials.html @@ -34,6 +34,16 @@
+ + + + + diff --git a/src/core/login/pages/credentials/credentials.ts b/src/core/login/pages/credentials/credentials.ts index e614d1b8b..180aa315e 100644 --- a/src/core/login/pages/credentials/credentials.ts +++ b/src/core/login/pages/credentials/credentials.ts @@ -16,12 +16,14 @@ import { Component, ViewChild, ElementRef } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; +import { CoreUtils } from '@providers/utils/utils'; import { CoreEventsProvider } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreLoginHelperProvider } from '../../providers/helper'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { CoreConfigConstants } from '../../../../configconstants'; +import { CoreCustomURLSchemes } from '@providers/urlschemes'; /** * Page to enter the user credentials. @@ -47,6 +49,7 @@ export class CoreLoginCredentialsPage { isBrowserSSO = false; isFixedUrlSet = false; showForgottenPassword = true; + showScanQR: boolean; protected siteConfig; protected eventThrown = false; @@ -74,6 +77,17 @@ export class CoreLoginCredentialsPage { username: [navParams.get('username') || '', Validators.required], password: ['', Validators.required] }); + + const canScanQR = CoreUtils.instance.canScanQR(); + if (canScanQR) { + if (typeof CoreConfigConstants['displayqroncredentialscreen'] == 'undefined') { + this.showScanQR = this.loginHelper.isFixedUrlSet(); + } else { + this.showScanQR = !!CoreConfigConstants['displayqroncredentialscreen']; + } + } else { + this.showScanQR = false; + } } /** @@ -267,4 +281,46 @@ export class CoreLoginCredentialsPage { signup(): void { this.navCtrl.push('CoreLoginEmailSignupPage', { siteUrl: this.siteUrl }); } + + /** + * Show instructions and scan QR code. + */ + showInstructionsAndScanQR(): void { + // Show some instructions first. + this.domUtils.showAlertWithOptions({ + title: this.translate.instant('core.login.faqwhereisqrcode'), + message: this.translate.instant('core.login.faqwhereisqrcodeanswer', + {$image: CoreLoginHelperProvider.FAQ_QRCODE_IMAGE_HTML}), + buttons: [ + { + text: this.translate.instant('core.cancel'), + role: 'cancel' + }, + { + text: this.translate.instant('core.next'), + handler: (): void => { + this.scanQR(); + } + }, + ], + }); + } + + /** + * Scan a QR code and put its text in the URL input. + * + * @return Promise resolved when done. + */ + async scanQR(): Promise { + // Scan for a QR code. + const text = await CoreUtils.instance.scanQR(); + + if (text && CoreCustomURLSchemes.instance.isCustomURL(text)) { + try { + await CoreCustomURLSchemes.instance.handleCustomURL(text); + } catch (error) { + CoreCustomURLSchemes.instance.treatHandleCustomURLError(error); + } + } + } } diff --git a/src/core/login/pages/site/site.html b/src/core/login/pages/site/site.html index d5dc5c1d9..c466aa73a 100644 --- a/src/core/login/pages/site/site.html +++ b/src/core/login/pages/site/site.html @@ -56,17 +56,6 @@ {{site.name}} - - - - - - @@ -85,6 +74,16 @@ {{site.name}} + + + + +