Merge pull request #2948 from crazyserver/MOBILE-3676

Mobile 3676
main
Dani Palou 2021-09-15 15:56:46 +02:00 committed by GitHub
commit fc4cd623cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 60 deletions

View File

@ -41,6 +41,15 @@ import { CoreLogger } from '@singletons/logger';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreIonLoadingElement } from './ion-loading'; 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). * Class that represents a site (combination of site + user).
* It will have all the site data and provide utility functions regarding a site. * 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. tool_mobile_androidappid?: string; // Android app's unique identifier.
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
tool_mobile_setuplink?: string; // App download page. tool_mobile_setuplink?: string; // App download page.
tool_mobile_qrcodetype?: CoreSiteQRCodeType; // eslint-disable-line @typescript-eslint/naming-convention
warnings?: CoreWSExternalWarning[]; warnings?: CoreWSExternalWarning[];
}; };

View File

@ -68,32 +68,32 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
/** /**
* Initialize the component. * Initialize the component.
*/ */
ngOnInit(): void { async ngOnInit(): Promise<void> {
const siteUrl = CoreNavigator.getRouteParam<string>('siteUrl'); try {
if (!siteUrl) { this.siteUrl = CoreNavigator.getRequiredRouteParam<string>('siteUrl');
CoreDomUtils.showErrorModal('Site URL not supplied.');
CoreNavigator.back();
return; this.siteName = CoreNavigator.getRouteParam('siteName');
this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && CoreNavigator.getRouteParam('logoUrl') || undefined;
this.siteConfig = CoreNavigator.getRouteParam('siteConfig');
this.urlToOpen = CoreNavigator.getRouteParam('urlToOpen');
} catch (error) {
CoreDomUtils.showErrorModal(error);
return CoreNavigator.back();
} }
this.siteUrl = siteUrl;
this.siteName = CoreNavigator.getRouteParam('siteName');
this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && CoreNavigator.getRouteParam('logoUrl') || undefined;
this.siteConfig = CoreNavigator.getRouteParam('siteConfig');
this.urlToOpen = CoreNavigator.getRouteParam('urlToOpen');
this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen();
this.credForm = this.fb.group({ this.credForm = this.fb.group({
username: [CoreNavigator.getRouteParam<string>('username') || '', Validators.required], username: [CoreNavigator.getRouteParam<string>('username') || '', Validators.required],
password: ['', Validators.required], password: ['', Validators.required],
}); });
this.treatSiteConfig(); if (this.siteConfig) {
this.treatSiteConfig();
}
this.isFixedUrlSet = CoreLoginHelper.isFixedUrlSet(); this.isFixedUrlSet = CoreLoginHelper.isFixedUrlSet();
if (this.isFixedUrlSet) { if (this.isFixedUrlSet || !this.siteConfig) {
// Fixed URL, we need to check if it uses browser SSO login. // Fixed URL or not siteConfig retrieved from params, we need to check if it uses browser SSO login.
this.checkSite(this.siteUrl); this.checkSite(this.siteUrl);
} else { } else {
this.siteChecked = true; this.siteChecked = true;
@ -177,6 +177,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
this.siteName = CoreConstants.CONFIG.sitename ? CoreConstants.CONFIG.sitename : this.siteConfig.sitename; this.siteName = CoreConstants.CONFIG.sitename ? CoreConstants.CONFIG.sitename : this.siteConfig.sitename;
this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig); this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig);
this.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps'); this.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps');
this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype);
const disabledFeatures = CoreLoginHelper.getDisabledFeatures(this.siteConfig); const disabledFeatures = CoreLoginHelper.getDisabledFeatures(this.siteConfig);
this.identityProviders = CoreLoginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures); this.identityProviders = CoreLoginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures);

View File

@ -20,7 +20,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreLoginHelper } from '@features/login/services/login-helper';
import { CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/site'; import { CoreSite, CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/site';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator';
@ -64,7 +64,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
) { ) {
const currentSite = CoreSites.getCurrentSite(); const currentSite = CoreSites.getCurrentSite();
this.isLoggedOut = !!currentSite?.isLoggedOut(); this.isLoggedOut = !currentSite || currentSite.isLoggedOut();
this.credForm = fb.group({ this.credForm = fb.group({
password: ['', Validators.required], password: ['', Validators.required],
}); });
@ -74,17 +74,12 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
* Initialize the component. * Initialize the component.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
const siteId = CoreNavigator.getRouteParam<string>('siteId');
if (!siteId) {
return this.cancel();
}
this.siteId = siteId;
this.page = CoreNavigator.getRouteParam('pageName');
this.pageOptions = CoreNavigator.getRouteParam('pageOptions');
this.showScanQR = CoreLoginHelper.displayQRInSiteScreen() || CoreLoginHelper.displayQRInCredentialsScreen();
try { try {
this.siteId = CoreNavigator.getRequiredRouteParam<string>('siteId');
this.page = CoreNavigator.getRouteParam('pageName');
this.pageOptions = CoreNavigator.getRouteParam('pageOptions');
const site = await CoreSites.getSite(this.siteId); const site = await CoreSites.getSite(this.siteId);
if (!site.infos) { if (!site.infos) {
@ -103,26 +98,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
// Show logo instead of avatar if it's a fixed site. // Show logo instead of avatar if it's a fixed site.
this.showSiteAvatar = !!this.userAvatar && !CoreLoginHelper.getFixedSites(); this.showSiteAvatar = !!this.userAvatar && !CoreLoginHelper.getFixedSites();
const config = await CoreUtils.ignoreErrors(site.getPublicConfig()); this.checkSiteConfig(site);
if (!config) {
return;
}
this.siteConfig = config;
await CoreSites.checkApplication(config);
// Check logoURL if user avatar is not set.
if (this.userAvatar.startsWith(this.siteUrl + '/theme/image.php')) {
this.showSiteAvatar = false;
}
this.logoUrl = CoreLoginHelper.getLogoUrl(config);
this.getDataFromConfig(this.siteConfig);
} catch (error) { } catch (error) {
// Just leave the view. CoreDomUtils.showErrorModal(error);
this.cancel();
return this.cancel();
} }
} }
@ -136,19 +116,34 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
/** /**
* Get some data (like identity providers) from the site config. * Get some data (like identity providers) from the site config.
*
* @param config Config to use.
*/ */
protected getDataFromConfig(config: CoreSitePublicConfigResponse): void { protected async checkSiteConfig(site: CoreSite): Promise<void> {
const disabledFeatures = CoreLoginHelper.getDisabledFeatures(config); this.siteConfig = await CoreUtils.ignoreErrors(site.getPublicConfig());
this.identityProviders = CoreLoginHelper.getValidIdentityProviders(config, disabledFeatures); if (!this.siteConfig) {
this.showForgottenPassword = !CoreLoginHelper.isForgottenPasswordDisabled(config); return;
}
const disabledFeatures = CoreLoginHelper.getDisabledFeatures(this.siteConfig);
this.identityProviders = CoreLoginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures);
this.showForgottenPassword = !CoreLoginHelper.isForgottenPasswordDisabled(this.siteConfig);
if (!this.eventThrown && !this.viewLeft) { if (!this.eventThrown && !this.viewLeft) {
this.eventThrown = true; this.eventThrown = true;
CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: config }); CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: this.siteConfig });
} }
this.showScanQR = CoreLoginHelper.displayQRInSiteScreen() ||
CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype);
await CoreSites.checkApplication(this.siteConfig);
// Check logoURL if user avatar is not set.
if (this.userAvatar?.startsWith(this.siteUrl + '/theme/image.php')) {
this.showSiteAvatar = false;
}
this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig);
} }
/** /**
@ -162,6 +157,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
e.stopPropagation(); e.stopPropagation();
} }
if (this.isLoggedOut) {
// Go to sites page when user is logged out.
CoreNavigator.navigate('/login/sites', { reset: true });
}
CoreSites.logout(); CoreSites.logout();
} }

View File

@ -26,7 +26,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreUrlParams, CoreUrlUtils } from '@services/utils/url'; import { CoreUrlParams, CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreConstants } from '@/core/constants'; 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 { CoreError } from '@classes/errors/error';
import { CoreWSError } from '@classes/errors/wserror'; import { CoreWSError } from '@classes/errors/wserror';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
@ -1237,15 +1237,22 @@ export class CoreLoginHelperProvider {
/** /**
* Check whether the QR reader should be displayed in credentials screen. * 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. * @return Whether the QR reader should be displayed in credentials screen.
*/ */
displayQRInCredentialsScreen(): boolean { displayQRInCredentialsScreen(qrCodeType = CoreSiteQRCodeType.QR_CODE_LOGIN): boolean {
if (!CoreUtils.canScanQR()) { if (!CoreUtils.canScanQR()) {
return false; return false;
} }
return (CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) || if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) ||
(CoreConstants.CONFIG.displayqroncredentialscreen !== undefined && !!CoreConstants.CONFIG.displayqroncredentialscreen); (CoreConstants.CONFIG.displayqroncredentialscreen !== undefined &&
!!CoreConstants.CONFIG.displayqroncredentialscreen)) {
return qrCodeType == CoreSiteQRCodeType.QR_CODE_LOGIN;
}
return false;
} }
/** /**

View File

@ -948,9 +948,13 @@ export class CoreSitesProvider {
} else { } else {
// Retrieve and create the site. // Retrieve and create the site.
const db = await this.appDB; const db = await this.appDB;
const data = await db.getRecord<SiteDBEntry>(SITES_TABLE_NAME, { id: siteId }); try {
const data = await db.getRecord<SiteDBEntry>(SITES_TABLE_NAME, { id: siteId });
return this.makeSiteFromSiteListEntry(data); return this.makeSiteFromSiteListEntry(data);
} catch {
throw new CoreError('SiteId not found');
}
} }
} }