MOBILE-4469 core: Create new CoreUnauthenticatedSite class
parent
988ddb4b94
commit
954ce48d7b
|
@ -86,7 +86,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit {
|
|||
*/
|
||||
protected setOpenInBrowserUrl(): void {
|
||||
const site = CoreSites.getRequiredCurrentSite();
|
||||
if (!CoreSites.shouldDisplayInformativeLinks(site)) {
|
||||
if (!site.shouldDisplayInformativeLinks()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
|||
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
this.isOnline = CoreNetwork.isOnline();
|
||||
this.externalUrl = currentSite && CoreSites.shouldDisplayInformativeLinks(currentSite) ?
|
||||
this.externalUrl = currentSite && currentSite.shouldDisplayInformativeLinks() ?
|
||||
currentSite.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() }) :
|
||||
undefined;
|
||||
this.onlineObserver = CoreNetwork.onChange().subscribe(() => {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreFile } from '@services/file';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
|
|
@ -24,7 +24,6 @@ import {
|
|||
CoreWS,
|
||||
CoreWSPreSets,
|
||||
CoreWSFileUploadOptions,
|
||||
CoreWSAjaxPreSets,
|
||||
CoreWSExternalWarning,
|
||||
CoreWSUploadFileResult,
|
||||
CoreWSPreSetsSplitRequest,
|
||||
|
@ -62,19 +61,9 @@ import { finalize, map, mergeMap } from 'rxjs/operators';
|
|||
import { firstValueFrom } from '../../utils/rxjs';
|
||||
import { CoreSiteError } from '@classes/errors/siteerror';
|
||||
import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CorePath } from '@singletons/path';
|
||||
import { CoreErrorLogs } from '@singletons/error-logs';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
import { CoreSiteInfo, CoreSiteInfoResponse, CoreSitePublicConfigResponse, CoreUnauthenticatedSite } from './unauthenticated-site';
|
||||
|
||||
// WS that we allow to call even if the site is logged out.
|
||||
const ALLOWED_LOGGEDOUT_WS = [
|
||||
|
@ -89,7 +78,7 @@ const ALLOWED_LOGGEDOUT_WS = [
|
|||
*
|
||||
* @todo Refactor this class to improve "temporary" sites support (not fully authenticated).
|
||||
*/
|
||||
export class CoreSite {
|
||||
export class CoreSite extends CoreUnauthenticatedSite {
|
||||
|
||||
static readonly REQUEST_QUEUE_FORCE_WS = false; // Use "tool_mobile_call_external_functions" even for calling a single function.
|
||||
|
||||
|
@ -161,8 +150,9 @@ export class CoreSite {
|
|||
public config?: CoreSiteConfig,
|
||||
public loggedOut?: boolean,
|
||||
) {
|
||||
super(siteUrl);
|
||||
|
||||
this.logger = CoreLogger.getInstance('CoreSite');
|
||||
this.siteUrl = CoreUrlUtils.removeUrlParams(this.siteUrl); // Make sure the URL doesn't have params.
|
||||
|
||||
this.cacheTable = asyncInstance(() => CoreSites.getSiteTable(WS_CACHE_TABLE, {
|
||||
siteId: this.getId(),
|
||||
|
@ -212,15 +202,6 @@ export class CoreSite {
|
|||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site URL.
|
||||
*
|
||||
* @returns Site URL.
|
||||
*/
|
||||
getURL(): string {
|
||||
return this.siteUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site token.
|
||||
*
|
||||
|
@ -236,9 +217,7 @@ export class CoreSite {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get site info.
|
||||
*
|
||||
* @returns Site info.
|
||||
* @inheritdoc
|
||||
*/
|
||||
getInfo(): CoreSiteInfo | undefined {
|
||||
return this.infos;
|
||||
|
@ -290,32 +269,6 @@ export class CoreSite {
|
|||
return this.infos?.siteid || 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site name.
|
||||
*
|
||||
* @returns Site name.
|
||||
*/
|
||||
async getSiteName(): Promise<string> {
|
||||
if (this.isDemoModeSite()) {
|
||||
return CoreConstants.CONFIG.appname;
|
||||
}
|
||||
|
||||
if (this.infos?.sitename) {
|
||||
return this.infos?.sitename;
|
||||
}
|
||||
|
||||
// Fallback.
|
||||
const isSingleFixedSite = await CoreLoginHelper.isSingleFixedSite();
|
||||
|
||||
if (isSingleFixedSite) {
|
||||
const sites = await CoreLoginHelper.getAvailableSites();
|
||||
|
||||
return sites[0].name;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set site ID.
|
||||
*
|
||||
|
@ -1623,47 +1576,11 @@ export class CoreSite {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a url to link an specific page on the site.
|
||||
*
|
||||
* @param path Path of the url to go to.
|
||||
* @param params Object with the params to add.
|
||||
* @param anchor Anchor text if needed.
|
||||
* @returns URL with params.
|
||||
*/
|
||||
createSiteUrl(path: string, params?: Record<string, unknown>, anchor?: string): string {
|
||||
return CoreUrlUtils.addParamsToUrl(CorePath.concatenatePaths(this.siteUrl, path), params, anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL belongs to this site.
|
||||
*
|
||||
* @param url URL to check.
|
||||
* @returns Whether the URL belongs to this site.
|
||||
*/
|
||||
containsUrl(url?: string): boolean {
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const siteUrl = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(this.siteUrl));
|
||||
url = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(url));
|
||||
|
||||
return url.indexOf(siteUrl) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public config of this site.
|
||||
*
|
||||
* @param options Options.
|
||||
* @returns Promise resolved with public config. Rejected with an object if error, see CoreWSProvider.callAjax.
|
||||
* @inheritdoc
|
||||
*/
|
||||
async getPublicConfig(options: { readingStrategy?: CoreSitesReadingStrategy } = {}): Promise<CoreSitePublicConfigResponse> {
|
||||
if (!this.db) {
|
||||
if (options.readingStrategy === CoreSitesReadingStrategy.ONLY_CACHE) {
|
||||
throw new CoreError('Cache not available to read public config');
|
||||
}
|
||||
|
||||
return this.requestPublicConfig();
|
||||
return super.getPublicConfig(options);
|
||||
}
|
||||
|
||||
const method = 'tool_mobile_get_public_config';
|
||||
|
@ -1754,47 +1671,12 @@ export class CoreSite {
|
|||
}
|
||||
|
||||
/**
|
||||
* Perform a request to the server to get the public config of this site.
|
||||
* Check if GET method is supported for AJAX calls.
|
||||
*
|
||||
* @returns Promise resolved with public config.
|
||||
* @returns Whether it's supported.
|
||||
*/
|
||||
protected async requestPublicConfig(): Promise<CoreSitePublicConfigResponse> {
|
||||
const preSets: CoreWSAjaxPreSets = {
|
||||
siteUrl: this.siteUrl,
|
||||
};
|
||||
|
||||
let config: CoreSitePublicConfigResponse;
|
||||
|
||||
try {
|
||||
config = await CoreWS.callAjax<CoreSitePublicConfigResponse>('tool_mobile_get_public_config', {}, preSets);
|
||||
} catch (error) {
|
||||
if (!error || error.errorcode !== 'codingerror' || (this.getInfo() && !this.isVersionGreaterEqualThan('3.8'))) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// This error probably means that there is a redirect in the site. Try to use a GET request.
|
||||
preSets.noLogin = true;
|
||||
preSets.useGet = true;
|
||||
|
||||
try {
|
||||
config = await CoreWS.callAjax<CoreSitePublicConfigResponse>('tool_mobile_get_public_config', {}, preSets);
|
||||
} catch (error2) {
|
||||
if (this.getInfo() && this.isVersionGreaterEqualThan('3.8')) {
|
||||
// GET is supported, return the second error.
|
||||
throw error2;
|
||||
} else {
|
||||
// GET not supported or we don't know if it's supported. Return first error.
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use the wwwroot returned by the server.
|
||||
if (config.httpswwwroot) {
|
||||
this.siteUrl = CoreUrlUtils.removeUrlParams(config.httpswwwroot); // Make sure the URL doesn't have params.
|
||||
}
|
||||
|
||||
return config;
|
||||
protected isAjaxGetSupported(): boolean {
|
||||
return !!this.getInfo() && this.isVersionGreaterEqualThan('3.8');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2325,35 +2207,6 @@ export class CoreSite {
|
|||
return this.tokenPluginFileWorksPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL to a file belongs to the site and uses the pluginfileurl or tokenpluginfileurl endpoints.
|
||||
*
|
||||
* @param url File URL to check.
|
||||
* @returns Whether it's a site file URL.
|
||||
*/
|
||||
isSitePluginFileUrl(url: string): boolean {
|
||||
const isPluginFileUrl = CoreUrlUtils.isPluginFileUrl(url) || CoreUrlUtils.isTokenPluginFileUrl(url);
|
||||
if (!isPluginFileUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.containsUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL to a file belongs to the site and is a theme image file.
|
||||
*
|
||||
* @param url File URL to check.
|
||||
* @returns Whether it's a site theme image URL.
|
||||
*/
|
||||
isSiteThemeImageUrl(url: string): boolean {
|
||||
if (!CoreUrlUtils.isThemeImageUrl(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.containsUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes last viewed records based on some conditions.
|
||||
*
|
||||
|
@ -2431,17 +2284,6 @@ export class CoreSite {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the site is a demo mode site.
|
||||
*
|
||||
* @returns Whether the site is a demo mode site.
|
||||
*/
|
||||
isDemoModeSite(): boolean {
|
||||
const demoSiteData = CoreLoginHelper.getDemoModeSiteInfo();
|
||||
|
||||
return this.containsUrl(demoSiteData?.url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2647,65 +2489,6 @@ type RequestQueueItem<T = any> = {
|
|||
deferred: CorePromisedValue<T>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS core_webservice_get_site_info.
|
||||
*/
|
||||
export type CoreSiteInfoResponse = {
|
||||
sitename: string; // Site name.
|
||||
username: string; // Username.
|
||||
firstname: string; // First name.
|
||||
lastname: string; // Last name.
|
||||
fullname: string; // User full name.
|
||||
lang: string; // Current language.
|
||||
userid: number; // User id.
|
||||
siteurl: string; // Site url.
|
||||
userpictureurl: string; // The user profile picture.
|
||||
functions: {
|
||||
name: string; // Function name.
|
||||
version: string; // The version number of the component to which the function belongs.
|
||||
}[];
|
||||
downloadfiles?: number; // 1 if users are allowed to download files, 0 if not.
|
||||
uploadfiles?: number; // 1 if users are allowed to upload files, 0 if not.
|
||||
release?: string; // Moodle release number.
|
||||
version?: string; // Moodle version number.
|
||||
mobilecssurl?: string; // Mobile custom CSS theme.
|
||||
advancedfeatures?: { // Advanced features availability.
|
||||
name: string; // Feature name.
|
||||
value: number; // Feature value. Usually 1 means enabled.
|
||||
}[];
|
||||
usercanmanageownfiles?: boolean; // True if the user can manage his own files.
|
||||
userquota?: number; // User quota (bytes). 0 means user can ignore the quota.
|
||||
usermaxuploadfilesize?: number; // User max upload file size (bytes). -1 means the user can ignore the upload file size.
|
||||
userhomepage?: CoreSiteInfoUserHomepage; // The default home page for the user.
|
||||
userprivateaccesskey?: string; // Private user access key for fetching files.
|
||||
siteid?: number; // Site course ID.
|
||||
sitecalendartype?: string; // Calendar type set in the site.
|
||||
usercalendartype?: string; // Calendar typed used by the user.
|
||||
userissiteadmin?: boolean; // Whether the user is a site admin or not.
|
||||
theme?: string; // Current theme for the user.
|
||||
};
|
||||
|
||||
/**
|
||||
* Site info, including some calculated data.
|
||||
*/
|
||||
export type CoreSiteInfo = CoreSiteInfoResponse & {
|
||||
functionsByName?: {
|
||||
[name: string]: {
|
||||
name: string; // Function name.
|
||||
version: string; // The version number of the component to which the function belongs.
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum constants that define default user home page.
|
||||
*/
|
||||
export enum CoreSiteInfoUserHomepage {
|
||||
HOMEPAGE_SITE = 0, // Site home.
|
||||
HOMEPAGE_MY = 1, // Dashboard.
|
||||
HOMEPAGE_MYCOURSES = 3, // My courses.
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of WS tool_mobile_get_config.
|
||||
*/
|
||||
|
@ -2717,15 +2500,6 @@ export type CoreSiteConfigResponse = {
|
|||
warnings?: CoreWSExternalWarning[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Possible values for 'supportavailability' config.
|
||||
*/
|
||||
export const enum CoreSiteConfigSupportAvailability {
|
||||
Disabled = 0,
|
||||
Authenticated = 1,
|
||||
Anyone = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* Site config indexed by name.
|
||||
*/
|
||||
|
@ -2735,64 +2509,6 @@ export type CoreSiteConfig = Record<string, string> & {
|
|||
searchbannerenable?: string; // Whether search banner is enabled.
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS tool_mobile_get_public_config.
|
||||
*/
|
||||
export type CoreSitePublicConfigResponse = {
|
||||
wwwroot: string; // Site URL.
|
||||
httpswwwroot: string; // Site https URL (if httpslogin is enabled).
|
||||
sitename: string; // Site name.
|
||||
guestlogin: number; // Whether guest login is enabled.
|
||||
rememberusername: number; // Values: 0 for No, 1 for Yes, 2 for optional.
|
||||
authloginviaemail: number; // Whether log in via email is enabled.
|
||||
registerauth: string; // Authentication method for user registration.
|
||||
forgottenpasswordurl: string; // Forgotten password URL.
|
||||
authinstructions: string; // Authentication instructions.
|
||||
authnoneenabled: number; // Whether auth none is enabled.
|
||||
enablewebservices: number; // Whether Web Services are enabled.
|
||||
enablemobilewebservice: number; // Whether the Mobile service is enabled.
|
||||
maintenanceenabled: number; // Whether site maintenance is enabled.
|
||||
maintenancemessage: string; // Maintenance message.
|
||||
logourl?: string; // The site logo URL.
|
||||
compactlogourl?: string; // The site compact logo URL.
|
||||
typeoflogin: TypeOfLogin; // The type of login. 1 for app, 2 for browser, 3 for embedded.
|
||||
launchurl?: string; // SSO login launch URL.
|
||||
mobilecssurl?: string; // Mobile custom CSS theme.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_disabledfeatures?: string; // Disabled features in the app.
|
||||
identityproviders?: CoreSiteIdentityProvider[]; // Identity providers.
|
||||
country?: string; // Default site country.
|
||||
agedigitalconsentverification?: boolean; // Whether age digital consent verification is enabled.
|
||||
supportname?: string; // Site support contact name (only if age verification is enabled).
|
||||
supportemail?: string; // Site support contact email (only if age verification is enabled).
|
||||
supportavailability?: CoreSiteConfigSupportAvailability;
|
||||
supportpage?: string; // Site support contact url.
|
||||
autolang?: number; // Whether to detect default language from browser setting.
|
||||
lang?: string; // Default language for the site.
|
||||
langmenu?: number; // Whether the language menu should be displayed.
|
||||
langlist?: string; // Languages on language menu.
|
||||
locale?: string; // Sitewide locale.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_minimumversion?: string; // Minimum required version to access.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_iosappid?: string; // IOS app's unique identifier.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
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[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Identity provider.
|
||||
*/
|
||||
export type CoreSiteIdentityProvider = {
|
||||
name: string; // The identity provider name.
|
||||
iconurl: string; // The icon URL for the provider.
|
||||
url: string; // The URL of the provider.
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS tool_mobile_get_autologin_key.
|
||||
*/
|
||||
|
@ -2853,12 +2569,3 @@ enum OngoingRequestType {
|
|||
STANDARD = 0,
|
||||
UPDATE_IN_BACKGROUND = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of login. 1 for app, 2 for browser, 3 for embedded.
|
||||
*/
|
||||
export enum TypeOfLogin {
|
||||
APP = 1,
|
||||
BROWSER = 2, // SSO in browser window is required.
|
||||
EMBEDDED = 3, // SSO in embedded browser is required.
|
||||
}
|
||||
|
|
|
@ -0,0 +1,409 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreTextUtils } from '@services/utils/text';
|
||||
import { CoreUrlUtils } from '@services/utils/url';
|
||||
import { CoreWS, CoreWSAjaxPreSets, CoreWSExternalWarning } from '@services/ws';
|
||||
import { CorePath } from '@singletons/path';
|
||||
|
||||
/**
|
||||
* Class that represents a Moodle site where the user still hasn't authenticated.
|
||||
*/
|
||||
export class CoreUnauthenticatedSite {
|
||||
|
||||
siteUrl: string;
|
||||
|
||||
/**
|
||||
* Create a site.
|
||||
*
|
||||
* @param siteUrl Site URL.
|
||||
*/
|
||||
constructor(siteUrl: string) {
|
||||
this.siteUrl = CoreUrlUtils.removeUrlParams(siteUrl); // Make sure the URL doesn't have params.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site URL.
|
||||
*
|
||||
* @returns Site URL.
|
||||
*/
|
||||
getURL(): string {
|
||||
return this.siteUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set site URL.
|
||||
*
|
||||
* @param url Site URL.
|
||||
*/
|
||||
setURL(url: string): void {
|
||||
this.siteUrl = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site info.
|
||||
*
|
||||
* @returns Site info.
|
||||
*/
|
||||
getInfo(): CoreSiteInfo | undefined {
|
||||
// Cannot retrieve info for unauthenticated sites.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site name.
|
||||
*
|
||||
* @returns Site name.
|
||||
*/
|
||||
async getSiteName(): Promise<string> {
|
||||
if (this.isDemoModeSite()) {
|
||||
return CoreConstants.CONFIG.appname;
|
||||
}
|
||||
|
||||
const siteName = this.getInfo()?.sitename;
|
||||
if (siteName) {
|
||||
return siteName;
|
||||
}
|
||||
|
||||
// Fallback.
|
||||
const isSingleFixedSite = await CoreLoginHelper.isSingleFixedSite();
|
||||
|
||||
if (isSingleFixedSite) {
|
||||
const sites = await CoreLoginHelper.getAvailableSites();
|
||||
|
||||
return sites[0].name;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the app should use the local logo instead of the remote one.
|
||||
*
|
||||
* @returns Whether local logo is forced.
|
||||
*/
|
||||
forcesLocalLogo(): boolean {
|
||||
return CoreConstants.CONFIG.forceLoginLogo || this.isDemoModeSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo URL from a site public config.
|
||||
*
|
||||
* @param config Site public config.
|
||||
* @returns Logo URL.
|
||||
*/
|
||||
getLogoUrl(config?: CoreSitePublicConfigResponse): string | undefined {
|
||||
if (!config || this.forcesLocalLogo()) {
|
||||
return 'assets/img/login_logo.png';
|
||||
}
|
||||
|
||||
return config.logourl || config.compactlogourl || 'assets/img/login_logo.png';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a url to link an specific page on the site.
|
||||
*
|
||||
* @param path Path of the url to go to.
|
||||
* @param params Object with the params to add.
|
||||
* @param anchor Anchor text if needed.
|
||||
* @returns URL with params.
|
||||
*/
|
||||
createSiteUrl(path: string, params?: Record<string, unknown>, anchor?: string): string {
|
||||
return CoreUrlUtils.addParamsToUrl(CorePath.concatenatePaths(this.siteUrl, path), params, anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL belongs to this site.
|
||||
*
|
||||
* @param url URL to check.
|
||||
* @returns Whether the URL belongs to this site.
|
||||
*/
|
||||
containsUrl(url?: string): boolean {
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const siteUrl = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(this.siteUrl));
|
||||
url = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(url));
|
||||
|
||||
return url.indexOf(siteUrl) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public config of this site.
|
||||
*
|
||||
* @param options Options.
|
||||
* @returns Promise resolved with public config. Rejected with an object if error, see CoreWSProvider.callAjax.
|
||||
*/
|
||||
async getPublicConfig(options: { readingStrategy?: CoreSitesReadingStrategy } = {}): Promise<CoreSitePublicConfigResponse> {
|
||||
if (options.readingStrategy === CoreSitesReadingStrategy.ONLY_CACHE) {
|
||||
throw new CoreError('Cache not available to read public config');
|
||||
}
|
||||
|
||||
return this.requestPublicConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a request to the server to get the public config of this site.
|
||||
*
|
||||
* @returns Promise resolved with public config.
|
||||
*/
|
||||
protected async requestPublicConfig(): Promise<CoreSitePublicConfigResponse> {
|
||||
const preSets: CoreWSAjaxPreSets = {
|
||||
siteUrl: this.siteUrl,
|
||||
};
|
||||
|
||||
let config: CoreSitePublicConfigResponse;
|
||||
|
||||
try {
|
||||
config = await CoreWS.callAjax<CoreSitePublicConfigResponse>('tool_mobile_get_public_config', {}, preSets);
|
||||
} catch (error) {
|
||||
if (!error || error.errorcode !== 'codingerror' || (this.getInfo() && !this.isAjaxGetSupported())) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// This error probably means that there is a redirect in the site. Try to use a GET request.
|
||||
preSets.noLogin = true;
|
||||
preSets.useGet = true;
|
||||
|
||||
try {
|
||||
config = await CoreWS.callAjax<CoreSitePublicConfigResponse>('tool_mobile_get_public_config', {}, preSets);
|
||||
} catch (error2) {
|
||||
if (this.isAjaxGetSupported()) {
|
||||
// GET is supported, return the second error.
|
||||
throw error2;
|
||||
} else {
|
||||
// GET not supported or we don't know if it's supported. Return first error.
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use the wwwroot returned by the server.
|
||||
if (config.httpswwwroot) {
|
||||
this.siteUrl = CoreUrlUtils.removeUrlParams(config.httpswwwroot); // Make sure the URL doesn't have params.
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if GET method is supported for AJAX calls.
|
||||
*
|
||||
* @returns Whether it's supported.
|
||||
* @since Moodle 3.8
|
||||
*/
|
||||
protected isAjaxGetSupported(): boolean {
|
||||
// We don't know if it's supported, assume it's not.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL to a file belongs to the site and uses the pluginfileurl or tokenpluginfileurl endpoints.
|
||||
*
|
||||
* @param url File URL to check.
|
||||
* @returns Whether it's a site file URL.
|
||||
*/
|
||||
isSitePluginFileUrl(url: string): boolean {
|
||||
const isPluginFileUrl = CoreUrlUtils.isPluginFileUrl(url) || CoreUrlUtils.isTokenPluginFileUrl(url);
|
||||
if (!isPluginFileUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.containsUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL to a file belongs to the site and is a theme image file.
|
||||
*
|
||||
* @param url File URL to check.
|
||||
* @returns Whether it's a site theme image URL.
|
||||
*/
|
||||
isSiteThemeImageUrl(url: string): boolean {
|
||||
if (!CoreUrlUtils.isThemeImageUrl(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.containsUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the site is a demo mode site.
|
||||
*
|
||||
* @returns Whether the site is a demo mode site.
|
||||
*/
|
||||
isDemoModeSite(): boolean {
|
||||
const demoSiteData = CoreLoginHelper.getDemoModeSiteInfo();
|
||||
|
||||
return this.containsUrl(demoSiteData?.url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether informative links should be displayed for this site.
|
||||
*
|
||||
* @returns Whether informative links should be displayed.
|
||||
*/
|
||||
shouldDisplayInformativeLinks(): boolean {
|
||||
return !CoreConstants.CONFIG.hideInformativeLinks && !this.isDemoModeSite();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of WS core_webservice_get_site_info.
|
||||
*/
|
||||
export type CoreSiteInfoResponse = {
|
||||
sitename: string; // Site name.
|
||||
username: string; // Username.
|
||||
firstname: string; // First name.
|
||||
lastname: string; // Last name.
|
||||
fullname: string; // User full name.
|
||||
lang: string; // Current language.
|
||||
userid: number; // User id.
|
||||
siteurl: string; // Site url.
|
||||
userpictureurl: string; // The user profile picture.
|
||||
functions: {
|
||||
name: string; // Function name.
|
||||
version: string; // The version number of the component to which the function belongs.
|
||||
}[];
|
||||
downloadfiles?: number; // 1 if users are allowed to download files, 0 if not.
|
||||
uploadfiles?: number; // 1 if users are allowed to upload files, 0 if not.
|
||||
release?: string; // Moodle release number.
|
||||
version?: string; // Moodle version number.
|
||||
mobilecssurl?: string; // Mobile custom CSS theme.
|
||||
advancedfeatures?: { // Advanced features availability.
|
||||
name: string; // Feature name.
|
||||
value: number; // Feature value. Usually 1 means enabled.
|
||||
}[];
|
||||
usercanmanageownfiles?: boolean; // True if the user can manage his own files.
|
||||
userquota?: number; // User quota (bytes). 0 means user can ignore the quota.
|
||||
usermaxuploadfilesize?: number; // User max upload file size (bytes). -1 means the user can ignore the upload file size.
|
||||
userhomepage?: CoreSiteInfoUserHomepage; // The default home page for the user.
|
||||
userprivateaccesskey?: string; // Private user access key for fetching files.
|
||||
siteid?: number; // Site course ID.
|
||||
sitecalendartype?: string; // Calendar type set in the site.
|
||||
usercalendartype?: string; // Calendar typed used by the user.
|
||||
userissiteadmin?: boolean; // Whether the user is a site admin or not.
|
||||
theme?: string; // Current theme for the user.
|
||||
};
|
||||
|
||||
/**
|
||||
* Site info, including some calculated data.
|
||||
*/
|
||||
export type CoreSiteInfo = CoreSiteInfoResponse & {
|
||||
functionsByName?: {
|
||||
[name: string]: {
|
||||
name: string; // Function name.
|
||||
version: string; // The version number of the component to which the function belongs.
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum constants that define default user home page.
|
||||
*/
|
||||
export enum CoreSiteInfoUserHomepage {
|
||||
HOMEPAGE_SITE = 0, // Site home.
|
||||
HOMEPAGE_MY = 1, // Dashboard.
|
||||
HOMEPAGE_MYCOURSES = 3, // My courses.
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible values for 'supportavailability' config.
|
||||
*/
|
||||
export const enum CoreSiteConfigSupportAvailability {
|
||||
Disabled = 0,
|
||||
Authenticated = 1,
|
||||
Anyone = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of WS tool_mobile_get_public_config.
|
||||
*/
|
||||
export type CoreSitePublicConfigResponse = {
|
||||
wwwroot: string; // Site URL.
|
||||
httpswwwroot: string; // Site https URL (if httpslogin is enabled).
|
||||
sitename: string; // Site name.
|
||||
guestlogin: number; // Whether guest login is enabled.
|
||||
rememberusername: number; // Values: 0 for No, 1 for Yes, 2 for optional.
|
||||
authloginviaemail: number; // Whether log in via email is enabled.
|
||||
registerauth: string; // Authentication method for user registration.
|
||||
forgottenpasswordurl: string; // Forgotten password URL.
|
||||
authinstructions: string; // Authentication instructions.
|
||||
authnoneenabled: number; // Whether auth none is enabled.
|
||||
enablewebservices: number; // Whether Web Services are enabled.
|
||||
enablemobilewebservice: number; // Whether the Mobile service is enabled.
|
||||
maintenanceenabled: number; // Whether site maintenance is enabled.
|
||||
maintenancemessage: string; // Maintenance message.
|
||||
logourl?: string; // The site logo URL.
|
||||
compactlogourl?: string; // The site compact logo URL.
|
||||
typeoflogin: TypeOfLogin; // The type of login. 1 for app, 2 for browser, 3 for embedded.
|
||||
launchurl?: string; // SSO login launch URL.
|
||||
mobilecssurl?: string; // Mobile custom CSS theme.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_disabledfeatures?: string; // Disabled features in the app.
|
||||
identityproviders?: CoreSiteIdentityProvider[]; // Identity providers.
|
||||
country?: string; // Default site country.
|
||||
agedigitalconsentverification?: boolean; // Whether age digital consent verification is enabled.
|
||||
supportname?: string; // Site support contact name (only if age verification is enabled).
|
||||
supportemail?: string; // Site support contact email (only if age verification is enabled).
|
||||
supportavailability?: CoreSiteConfigSupportAvailability;
|
||||
supportpage?: string; // Site support contact url.
|
||||
autolang?: number; // Whether to detect default language from browser setting.
|
||||
lang?: string; // Default language for the site.
|
||||
langmenu?: number; // Whether the language menu should be displayed.
|
||||
langlist?: string; // Languages on language menu.
|
||||
locale?: string; // Sitewide locale.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_minimumversion?: string; // Minimum required version to access.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
tool_mobile_iosappid?: string; // IOS app's unique identifier.
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
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[];
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
|
||||
/**
|
||||
* Identity provider.
|
||||
*/
|
||||
export type CoreSiteIdentityProvider = {
|
||||
name: string; // The identity provider name.
|
||||
iconurl: string; // The icon URL for the provider.
|
||||
url: string; // The URL of the provider.
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of login. 1 for app, 2 for browser, 3 for embedded.
|
||||
*/
|
||||
export enum TypeOfLogin {
|
||||
APP = 1,
|
||||
BROWSER = 2, // SSO in browser window is required.
|
||||
EMBEDDED = 3, // SSO in embedded browser is required.
|
||||
}
|
|
@ -14,8 +14,9 @@
|
|||
|
||||
import { Component, ContentChild, Input, Output, TemplateRef, EventEmitter } from '@angular/core';
|
||||
|
||||
import { CoreSiteBasicInfo, CoreSites } from '@services/sites';
|
||||
import { CoreSiteBasicInfo } from '@services/sites';
|
||||
import { CoreAccountsList } from '@features/login/services/login-helper';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Component to display a list of sites (accounts).
|
||||
|
@ -84,7 +85,7 @@ export class CoreSitesListComponent<T extends CoreSiteBasicInfo> {
|
|||
* @returns Whether to display URL.
|
||||
*/
|
||||
displaySiteUrl(site: CoreSiteBasicInfo): boolean {
|
||||
return CoreSites.shouldDisplayInformativeLinks(site.siteUrl);
|
||||
return CoreSitesFactory.makeSite(site.id, site.siteUrl, '', { info: site.info }).shouldDisplayInformativeLinks();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import { CoreNavigator } from '@services/navigator';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreUserHelper } from '@features/user/services/user-helper';
|
||||
import { CoreUrlUtils } from '@services/utils/url';
|
||||
import { CoreSiteInfo } from '@classes/site';
|
||||
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Component to display a "user avatar".
|
||||
|
|
|
@ -20,6 +20,7 @@ import { CoreContentLinksAction } from '../../services/contentlinks-delegate';
|
|||
import { CoreContentLinksHelper } from '../../services/contentlinks-helper';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Page to display the list of sites to choose one to perform a content link action.
|
||||
|
@ -73,7 +74,7 @@ export class CoreContentLinksChooseSiteModalComponent implements OnInit {
|
|||
this.sites = await CoreSites.getSites(siteIds);
|
||||
|
||||
// All sites have the same URL, use the first one.
|
||||
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.sites[0].siteUrl);
|
||||
this.displaySiteUrl = CoreSitesFactory.makeUnauthenticatedSite(this.sites[0].siteUrl).shouldDisplayInformativeLinks();
|
||||
} catch (error) {
|
||||
CoreDomUtils.showErrorModalDefault(error, 'core.contentlinks.errornosites', true);
|
||||
this.closeModal();
|
||||
|
|
|
@ -101,7 +101,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
this.displayOptions = Object.assign({
|
||||
displayOpenInBrowser: CoreSites.shouldDisplayInformativeLinks(),
|
||||
displayOpenInBrowser: !!CoreSites.getCurrentSite()?.shouldDisplayInformativeLinks(),
|
||||
displayDescription: true,
|
||||
displayRefresh: true,
|
||||
displayPrefetch: true,
|
||||
|
|
|
@ -138,7 +138,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
|||
const currentSiteUrl = CoreSites.getRequiredCurrentSite().getURL();
|
||||
this.enrolUrl = CorePath.concatenatePaths(currentSiteUrl, 'enrol/index.php?id=' + this.courseId);
|
||||
this.courseUrl = CorePath.concatenatePaths(currentSiteUrl, 'course/view.php?id=' + this.courseId);
|
||||
this.displayOpenInBrowser = CoreSites.shouldDisplayInformativeLinks();
|
||||
this.displayOpenInBrowser = CoreSites.getRequiredCurrentSite().shouldDisplayInformativeLinks();
|
||||
|
||||
await this.getCourse();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ export class CoreCourseModulePreviewPage implements OnInit {
|
|||
return;
|
||||
}
|
||||
|
||||
this.displayOpenInBrowser = CoreSites.shouldDisplayInformativeLinks();
|
||||
this.displayOpenInBrowser = !!CoreSites.getCurrentSite()?.shouldDisplayInformativeLinks();
|
||||
this.debouncedUpdateModule = CoreUtils.debounce(() => {
|
||||
this.doRefresh();
|
||||
}, 10000);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/sites/site';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
||||
import { CoreSiteHomeHomeHandler } from '@features/sitehome/services/handlers/sitehome-home';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSiteIdentityProvider, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreLoginHelper, CoreLoginMethod } from '@features/login/services/login-helper';
|
||||
import { CoreRedirectPayload } from '@services/navigator';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
|
|
@ -20,19 +20,17 @@
|
|||
</ion-header>
|
||||
<ion-content class="ion-padding limited-width">
|
||||
<core-loading [hideUntil]="pageLoaded">
|
||||
<ng-container *ngIf="!siteCheckError">
|
||||
<ng-container *ngIf="!siteCheckError && site">
|
||||
<div class="ion-text-wrap ion-text-center core-login-info-box">
|
||||
<div class="core-login-site">
|
||||
<div class="core-login-site-logo">
|
||||
<!-- Show site logo or a default image. -->
|
||||
<img *ngIf="logoUrl" [src]="logoUrl" role="presentation" alt="" onError="this.src='assets/img/login_logo.png'">
|
||||
<img *ngIf="!logoUrl" src="assets/img/login_logo.png" role="presentation" alt="">
|
||||
<div class="core-login-site-logo" *ngIf="logoUrl">
|
||||
<img [src]="logoUrl" role="presentation" alt="" onError="this.src='assets/img/login_logo.png'">
|
||||
</div>
|
||||
|
||||
<h2 *ngIf="siteName" class="ion-margin-top ion-no-padding core-sitename">
|
||||
<core-format-text [text]="siteName" [filter]="false"></core-format-text>
|
||||
</h2>
|
||||
<p class="core-siteurl" *ngIf="displaySiteUrl">{{siteUrl}}</p>
|
||||
<p class="core-siteurl" *ngIf="displaySiteUrl">{{site.siteUrl}}</p>
|
||||
</div>
|
||||
|
||||
<core-login-exceeded-attempts *ngIf="exceededAttemptsHTML && supportConfig && loginAttempts >= 3"
|
||||
|
@ -83,7 +81,7 @@
|
|||
</ng-container>
|
||||
|
||||
|
||||
<core-login-methods *ngIf="siteConfig" [siteConfig]="siteConfig" [siteUrl]="siteUrl"></core-login-methods>
|
||||
<core-login-methods *ngIf="siteConfig" [siteConfig]="siteConfig" [siteUrl]="site.siteUrl"></core-login-methods>
|
||||
</div>
|
||||
|
||||
<div class="core-login-sign-up" *ngIf="!isBrowserSSO && (canSignup || authInstructions)">
|
||||
|
|
|
@ -22,9 +22,8 @@ import { CoreNetwork } from '@services/network';
|
|||
import { CoreSiteCheckResponse, CoreSites } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSitePublicConfigResponse, CoreUnauthenticatedSite } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreForms } from '@singletons/form';
|
||||
|
@ -33,6 +32,7 @@ import { CoreUserSupportConfig } from '@features/user/classes/support/support-co
|
|||
import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config';
|
||||
import { SafeHtml } from '@angular/platform-browser';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Page to enter the user credentials.
|
||||
|
@ -47,7 +47,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
@ViewChild('credentialsForm') formElement?: ElementRef<HTMLFormElement>;
|
||||
|
||||
credForm!: FormGroup;
|
||||
siteUrl!: string;
|
||||
site!: CoreUnauthenticatedSite;
|
||||
siteName?: string;
|
||||
logoUrl?: string;
|
||||
authInstructions?: string;
|
||||
|
@ -61,7 +61,6 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
exceededAttemptsHTML?: SafeHtml | string | null;
|
||||
siteConfig?: CoreSitePublicConfigResponse;
|
||||
siteCheckError = '';
|
||||
isDemoModeSite = false;
|
||||
displaySiteUrl = false;
|
||||
|
||||
protected siteCheck?: CoreSiteCheckResponse;
|
||||
|
@ -81,24 +80,18 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
async ngOnInit(): Promise<void> {
|
||||
try {
|
||||
this.siteCheck = CoreNavigator.getRouteParam<CoreSiteCheckResponse>('siteCheck');
|
||||
if (this.siteCheck?.siteUrl) {
|
||||
this.siteUrl = this.siteCheck.siteUrl;
|
||||
} else {
|
||||
this.siteUrl = CoreNavigator.getRequiredRouteParam<string>('siteUrl');
|
||||
}
|
||||
|
||||
const siteUrl = this.siteCheck?.siteUrl || CoreNavigator.getRequiredRouteParam<string>('siteUrl');
|
||||
if (this.siteCheck?.config) {
|
||||
this.siteConfig = this.siteCheck.config;
|
||||
}
|
||||
|
||||
this.isDemoModeSite = CoreLoginHelper.isDemoModeSite(this.siteUrl);
|
||||
this.siteName = this.isDemoModeSite ? CoreConstants.CONFIG.appname : CoreNavigator.getRouteParam('siteName');
|
||||
this.logoUrl = !CoreConstants.CONFIG.forceLoginLogo && !this.isDemoModeSite ?
|
||||
CoreNavigator.getRouteParam('logoUrl') :
|
||||
undefined;
|
||||
this.site = CoreSitesFactory.makeUnauthenticatedSite(siteUrl);
|
||||
this.logoUrl = this.site.getLogoUrl(this.siteConfig);
|
||||
this.urlToOpen = CoreNavigator.getRouteParam('urlToOpen');
|
||||
this.supportConfig = this.siteConfig && new CoreUserGuestSupportConfig(this.siteConfig);
|
||||
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.siteUrl);
|
||||
this.displaySiteUrl = this.site.shouldDisplayInformativeLinks();
|
||||
this.siteName = (await this.site.getSiteName()) || CoreNavigator.getRouteParam('siteName');
|
||||
} catch (error) {
|
||||
CoreDomUtils.showErrorModal(error);
|
||||
|
||||
|
@ -160,14 +153,14 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
this.pageLoaded = false;
|
||||
|
||||
// If the site is configured with http:// protocol we force that one, otherwise we use default mode.
|
||||
const protocol = this.siteUrl.indexOf('http://') === 0 ? 'http://' : undefined;
|
||||
const protocol = this.site.siteUrl.indexOf('http://') === 0 ? 'http://' : undefined;
|
||||
|
||||
try {
|
||||
if (!this.siteCheck) {
|
||||
this.siteCheck = await CoreSites.checkSite(this.siteUrl, protocol);
|
||||
this.siteCheck = await CoreSites.checkSite(this.site.siteUrl, protocol);
|
||||
}
|
||||
|
||||
this.siteUrl = this.siteCheck.siteUrl;
|
||||
this.site.setURL(this.siteCheck.siteUrl);
|
||||
this.siteConfig = this.siteCheck.config;
|
||||
this.supportConfig = this.siteConfig && new CoreUserGuestSupportConfig(this.siteConfig);
|
||||
|
||||
|
@ -197,11 +190,11 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.isDemoModeSite) {
|
||||
if (this.site.isDemoModeSite()) {
|
||||
this.showScanQR = false;
|
||||
} else {
|
||||
this.siteName = this.siteConfig.sitename;
|
||||
this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig);
|
||||
this.logoUrl = this.site.getLogoUrl(this.siteConfig);
|
||||
this.showScanQR = await CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype);
|
||||
}
|
||||
|
||||
|
@ -258,7 +251,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
CoreApp.closeKeyboard();
|
||||
|
||||
// Get input data.
|
||||
const siteUrl = this.siteUrl;
|
||||
const siteUrl = this.site.getURL();
|
||||
const username = this.credForm.value.username;
|
||||
const password = this.credForm.value.password;
|
||||
|
||||
|
@ -331,14 +324,14 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
* Forgotten password button clicked.
|
||||
*/
|
||||
forgottenPassword(): void {
|
||||
CoreLoginHelper.forgottenPasswordClicked(this.siteUrl, this.credForm.value.username, this.siteConfig);
|
||||
CoreLoginHelper.forgottenPasswordClicked(this.site.getURL(), this.credForm.value.username, this.siteConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open email signup page.
|
||||
*/
|
||||
openEmailSignup(): void {
|
||||
CoreNavigator.navigate('/login/emailsignup', { params: { siteUrl: this.siteUrl } });
|
||||
CoreNavigator.navigate('/login/emailsignup', { params: { siteUrl: this.site.getURL() } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,12 +82,12 @@
|
|||
<ion-item class="ion-text-wrap ion-text-center">
|
||||
<ion-label>
|
||||
<!-- If no sitename show big siteurl. -->
|
||||
<p *ngIf="!siteName && displaySiteUrl" class="ion-padding item-heading">{{siteUrl}}</p>
|
||||
<p *ngIf="!siteName && displaySiteUrl" class="ion-padding item-heading">{{site.siteUrl}}</p>
|
||||
<!-- If sitename, show big sitename and small siteurl. -->
|
||||
<p *ngIf="siteName" class="ion-padding item-heading">
|
||||
<core-format-text [text]="siteName" [filter]="false"></core-format-text>
|
||||
</p>
|
||||
<p *ngIf="siteName && displaySiteUrl">{{siteUrl}}</p>
|
||||
<p *ngIf="siteName && displaySiteUrl">{{site.siteUrl}}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
|
@ -188,7 +188,7 @@
|
|||
<h2><span [core-mark-required]="true">{{ 'core.login.security_question' | translate }}</span></h2>
|
||||
</ion-label>
|
||||
</ion-item-divider>
|
||||
<core-recaptcha [publicKey]="settings.recaptchapublickey" [model]="captcha" [siteUrl]="siteUrl"
|
||||
<core-recaptcha [publicKey]="settings.recaptchapublickey" [model]="captcha" [siteUrl]="site.siteUrl"
|
||||
[showRequiredError]="formSubmitClicked"></core-recaptcha>
|
||||
</ng-container>
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import { CoreTextUtils } from '@services/utils/text';
|
|||
import { CoreCountry, CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWS, CoreWSExternalWarning } from '@services/ws';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSitePublicConfigResponse, CoreUnauthenticatedSite } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreUserProfileFieldDelegate } from '@features/user/services/user-profile-field-delegate';
|
||||
|
||||
import {
|
||||
|
@ -34,7 +34,7 @@ import { CoreForms } from '@singletons/form';
|
|||
import { CoreRecaptchaComponent } from '@components/recaptcha/recaptcha';
|
||||
import { CorePath } from '@singletons/path';
|
||||
import { CoreDom } from '@singletons/dom';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Page to signup using email.
|
||||
|
@ -51,8 +51,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
@ViewChild('signupFormEl') signupFormElement?: ElementRef;
|
||||
|
||||
signupForm: FormGroup;
|
||||
siteUrl!: string;
|
||||
isDemoModeSite = false;
|
||||
site!: CoreUnauthenticatedSite;
|
||||
displaySiteUrl = false;
|
||||
siteConfig?: CoreSitePublicConfigResponse;
|
||||
siteName?: string;
|
||||
|
@ -129,9 +128,8 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
return;
|
||||
}
|
||||
|
||||
this.siteUrl = siteUrl;
|
||||
this.isDemoModeSite = CoreLoginHelper.isDemoModeSite(this.siteUrl);
|
||||
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(this.siteUrl);
|
||||
this.site = CoreSitesFactory.makeUnauthenticatedSite(siteUrl);
|
||||
this.displaySiteUrl = this.site.shouldDisplayInformativeLinks();
|
||||
|
||||
// Fetch the data.
|
||||
this.fetchData().finally(() => {
|
||||
|
@ -165,10 +163,11 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
protected async fetchData(): Promise<void> {
|
||||
try {
|
||||
// Get site config.
|
||||
this.siteConfig = await CoreSites.getSitePublicConfig(this.siteUrl);
|
||||
this.siteConfig = await CoreSites.getSitePublicConfig(this.site.getURL());
|
||||
this.signupUrl = CorePath.concatenatePaths(this.siteConfig.httpswwwroot, 'login/signup.php');
|
||||
|
||||
if (this.treatSiteConfig()) {
|
||||
const configValid = await this.treatSiteConfig();
|
||||
if (configValid) {
|
||||
// Check content verification.
|
||||
if (this.ageDigitalConsentVerification === undefined) {
|
||||
|
||||
|
@ -176,7 +175,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
CoreWS.callAjax<IsAgeVerificationEnabledWSResponse>(
|
||||
'core_auth_is_age_digital_consent_verification_enabled',
|
||||
{},
|
||||
{ siteUrl: this.siteUrl },
|
||||
{ siteUrl: this.site.getURL() },
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -203,7 +202,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
this.settings = await CoreWS.callAjax<AuthEmailSignupSettings>(
|
||||
'auth_email_get_signup_settings',
|
||||
{},
|
||||
{ siteUrl: this.siteUrl },
|
||||
{ siteUrl: this.site.getURL() },
|
||||
);
|
||||
|
||||
if (CoreUserProfileFieldDelegate.hasRequiredUnsupportedField(this.settings.profilefields)) {
|
||||
|
@ -238,9 +237,10 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
*
|
||||
* @returns True if success.
|
||||
*/
|
||||
protected treatSiteConfig(): boolean {
|
||||
protected async treatSiteConfig(): Promise<boolean> {
|
||||
if (this.siteConfig?.registerauth == 'email' && !CoreLoginHelper.isEmailSignupDisabled(this.siteConfig)) {
|
||||
this.siteName = this.isDemoModeSite ? CoreConstants.CONFIG.appname : this.siteConfig.sitename;
|
||||
this.siteName = await this.site.getSiteName();
|
||||
|
||||
this.authInstructions = this.siteConfig.authinstructions;
|
||||
this.ageDigitalConsentVerification = this.siteConfig.agedigitalconsentverification;
|
||||
this.supportName = this.siteConfig.supportname;
|
||||
|
@ -306,7 +306,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
};
|
||||
|
||||
if (this.siteConfig?.launchurl) {
|
||||
params.redirect = CoreLoginHelper.prepareForSSOLogin(this.siteUrl, undefined, this.siteConfig.launchurl);
|
||||
params.redirect = CoreLoginHelper.prepareForSSOLogin(this.site.getURL(), undefined, this.siteConfig.launchurl);
|
||||
}
|
||||
|
||||
// Get the recaptcha response (if needed).
|
||||
|
@ -326,7 +326,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
const result = await CoreWS.callAjax<SignupUserWSResult>(
|
||||
'auth_email_signup_user',
|
||||
params,
|
||||
{ siteUrl: this.siteUrl },
|
||||
{ siteUrl: this.site.getURL() },
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
|
@ -381,7 +381,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
*/
|
||||
showContactOnSite(): void {
|
||||
CoreUtils.openInBrowser(
|
||||
CorePath.concatenatePaths(this.siteUrl, '/login/verify_age_location.php'),
|
||||
CorePath.concatenatePaths(this.site.getURL(), '/login/verify_age_location.php'),
|
||||
{ showBrowserWarning: false },
|
||||
);
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
params.age = parseInt(params.age, 10); // Use just the integer part.
|
||||
|
||||
try {
|
||||
const result = await CoreWS.callAjax<IsMinorWSResult>('core_auth_is_minor', params, { siteUrl: this.siteUrl });
|
||||
const result = await CoreWS.callAjax<IsMinorWSResult>('core_auth_is_minor', params, { siteUrl: this.site.getURL() });
|
||||
|
||||
CoreForms.triggerFormSubmittedEvent(this.ageFormElement, true);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import { Translate } from '@singletons';
|
|||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreForms } from '@singletons/form';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreUserSupportConfig } from '@features/user/classes/support/support-config';
|
||||
import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config';
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</ion-header>
|
||||
<ion-content class="ion-padding" (keydown)="keyDown($event)" (keyup)="keyUp($event)">
|
||||
<core-loading [hideUntil]="!showLoading">
|
||||
<div class="list-item-limited-width">
|
||||
<div class="list-item-limited-width" *ngIf="site">
|
||||
<ion-card *ngIf="!isLoggedOut" class="core-warning-card core-login-reconnect-warning">
|
||||
<ion-item>
|
||||
<ion-icon name="fas-triangle-exclamation" slot="start" aria-hidden="true"></ion-icon>
|
||||
|
@ -31,16 +31,14 @@
|
|||
|
||||
<div class="ion-text-wrap ion-text-center core-login-info-box">
|
||||
<div class="core-login-site">
|
||||
<div class="core-login-site-logo" *ngIf="!showUserAvatar">
|
||||
<!-- Show site logo or a default image. -->
|
||||
<img *ngIf="logoUrl" [src]="logoUrl" role="presentation" onError="this.src='assets/img/login_logo.png'" alt="">
|
||||
<img *ngIf="!logoUrl" src="assets/img/login_logo.png" role="presentation" alt="">
|
||||
<div class="core-login-site-logo" *ngIf="!showUserAvatar && logoUrl">
|
||||
<img [src]="logoUrl" role="presentation" onError="this.src='assets/img/login_logo.png'" alt="">
|
||||
</div>
|
||||
|
||||
<p *ngIf="siteInfo?.siteName" class="ion-no-margin ion-no-padding core-sitename">
|
||||
<core-format-text [text]="siteInfo?.siteName" [filter]="false"></core-format-text>
|
||||
</p>
|
||||
<p class="core-siteurl" *ngIf="displaySiteUrl">{{siteUrl}}</p>
|
||||
<p class="core-siteurl" *ngIf="displaySiteUrl">{{site.siteUrl}}</p>
|
||||
</div>
|
||||
|
||||
<div class="core-login-user">
|
||||
|
@ -90,7 +88,7 @@
|
|||
</ng-container>
|
||||
|
||||
<!-- Additional Login methods -->
|
||||
<core-login-methods *ngIf="siteConfig" [siteConfig]="siteConfig" [reconnect]="true" [siteUrl]="siteUrl"
|
||||
<core-login-methods *ngIf="siteConfig" [siteConfig]="siteConfig" [reconnect]="true" [siteUrl]="site.siteUrl"
|
||||
[redirectData]="redirectData"></core-login-methods>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -21,7 +21,7 @@ import { CoreSiteBasicInfo, CoreSites, CoreSitesReadingStrategy } from '@service
|
|||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreSite, CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreNavigator, CoreRedirectPayload } from '@services/navigator';
|
||||
|
@ -31,6 +31,7 @@ import { CoreUserSupportConfig } from '@features/user/classes/support/support-co
|
|||
import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config';
|
||||
import { Translate } from '@singletons';
|
||||
import { SafeHtml } from '@angular/platform-browser';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Page to enter the user password to reconnect to a site.
|
||||
|
@ -45,8 +46,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
@ViewChild('reconnectForm') formElement?: ElementRef;
|
||||
|
||||
credForm: FormGroup;
|
||||
siteUrl!: string;
|
||||
isDemoModeSite = false;
|
||||
site!: CoreSite;
|
||||
logoUrl?: string;
|
||||
displaySiteUrl = false;
|
||||
showForgottenPassword = true;
|
||||
|
@ -96,37 +96,34 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
};
|
||||
}
|
||||
|
||||
const site = await CoreSites.getSite(this.siteId);
|
||||
this.site = await CoreSites.getSite(this.siteId);
|
||||
|
||||
if (!site.infos) {
|
||||
if (!this.site.infos) {
|
||||
throw new CoreError('Invalid site');
|
||||
}
|
||||
|
||||
this.siteUrl = site.getURL();
|
||||
this.isDemoModeSite = site.isDemoModeSite();
|
||||
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(site);
|
||||
|
||||
this.siteInfo = {
|
||||
id: this.siteId,
|
||||
siteUrl: this.siteUrl,
|
||||
siteUrlWithoutProtocol: this.siteUrl.replace(/^https?:\/\//, '').toLowerCase(),
|
||||
fullname: site.infos.fullname,
|
||||
firstname: site.infos.firstname,
|
||||
lastname: site.infos.lastname,
|
||||
siteName: await site.getSiteName(),
|
||||
userpictureurl: site.infos.userpictureurl,
|
||||
siteUrl: this.site.getURL(),
|
||||
siteUrlWithoutProtocol: this.site.getURL().replace(/^https?:\/\//, '').toLowerCase(),
|
||||
fullname: this.site.infos.fullname,
|
||||
firstname: this.site.infos.firstname,
|
||||
lastname: this.site.infos.lastname,
|
||||
siteName: await this.site.getSiteName(),
|
||||
userpictureurl: this.site.infos.userpictureurl,
|
||||
loggedOut: true, // Not used.
|
||||
};
|
||||
|
||||
this.username = site.infos.username;
|
||||
this.supportConfig = new CoreUserAuthenticatedSupportConfig(site);
|
||||
this.displaySiteUrl = this.site.shouldDisplayInformativeLinks();
|
||||
this.username = this.site.infos.username;
|
||||
this.supportConfig = new CoreUserAuthenticatedSupportConfig(this.site);
|
||||
|
||||
const availableSites = await CoreLoginHelper.getAvailableSites();
|
||||
|
||||
// Show logo instead of avatar if it's a fixed site.
|
||||
this.showUserAvatar = !availableSites.length;
|
||||
|
||||
await this.checkSiteConfig(site);
|
||||
await this.checkSiteConfig();
|
||||
|
||||
this.showLoading = false;
|
||||
} catch (error) {
|
||||
|
@ -165,8 +162,8 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
/**
|
||||
* Get some data (like identity providers) from the site config.
|
||||
*/
|
||||
protected async checkSiteConfig(site: CoreSite): Promise<void> {
|
||||
this.siteConfig = await CoreUtils.ignoreErrors(site.getPublicConfig({
|
||||
protected async checkSiteConfig(): Promise<void> {
|
||||
this.siteConfig = await CoreUtils.ignoreErrors(this.site.getPublicConfig({
|
||||
readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK,
|
||||
}));
|
||||
|
||||
|
@ -186,10 +183,9 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
this.isBrowserSSO = CoreLoginHelper.isSSOLoginNeeded(this.siteConfig.typeoflogin);
|
||||
this.logoUrl = this.site.getLogoUrl();
|
||||
|
||||
await CoreSites.checkApplication(this.siteConfig);
|
||||
|
||||
this.logoUrl = this.isDemoModeSite ? undefined : CoreLoginHelper.getLogoUrl(this.siteConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,14 +237,14 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
|
||||
try {
|
||||
// Start the authentication process.
|
||||
const data = await CoreSites.getUserToken(this.siteUrl, this.username, password);
|
||||
const data = await CoreSites.getUserToken(this.site.getURL(), this.username, password);
|
||||
|
||||
await CoreSites.updateSiteToken(this.siteUrl, this.username, data.token, data.privateToken);
|
||||
await CoreSites.updateSiteToken(this.site.getURL(), this.username, data.token, data.privateToken);
|
||||
|
||||
CoreForms.triggerFormSubmittedEvent(this.formElement, true);
|
||||
|
||||
// Update site info too.
|
||||
await CoreSites.updateSiteInfoByUrl(this.siteUrl, this.username);
|
||||
await CoreSites.updateSiteInfoByUrl(this.site.getURL(), this.username);
|
||||
|
||||
// Reset fields so the data is not in the view anymore.
|
||||
this.credForm.controls['password'].reset();
|
||||
|
@ -260,7 +256,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
params: this.redirectData,
|
||||
});
|
||||
} catch (error) {
|
||||
CoreLoginHelper.treatUserTokenError(this.siteUrl, error, this.username, password);
|
||||
CoreLoginHelper.treatUserTokenError(this.site.getURL(), error, this.username, password);
|
||||
|
||||
if (error.loggedout) {
|
||||
this.cancel();
|
||||
|
@ -294,7 +290,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
* Forgotten password button clicked.
|
||||
*/
|
||||
forgottenPassword(): void {
|
||||
CoreLoginHelper.forgottenPasswordClicked(this.siteUrl, this.username, this.siteConfig);
|
||||
CoreLoginHelper.forgottenPasswordClicked(this.site.getURL(), this.username, this.siteConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -306,7 +302,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
CoreLoginHelper.openBrowserForSSOLogin(
|
||||
this.siteUrl,
|
||||
this.site.getURL(),
|
||||
this.siteConfig.typeoflogin,
|
||||
undefined,
|
||||
this.siteConfig.launchurl,
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
</ion-thumbnail>
|
||||
<ion-label>
|
||||
<p *ngIf="site.title" class="item-heading ion-text-wrap">{{site.title}}</p>
|
||||
<p *ngIf="displaySiteUrl(site.noProtocolUrl)">{{site.noProtocolUrl}}</p>
|
||||
<p *ngIf="displaySiteUrl(site.siteUrl)">{{site.noProtocolUrl}}</p>
|
||||
<p *ngIf="site.location">{{site.location}}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
|
|
@ -47,6 +47,7 @@ import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest
|
|||
import { CoreLoginError } from '@classes/errors/loginerror';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreReferrer } from '@services/referrer';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Site (url) chooser when adding a new site.
|
||||
|
@ -393,7 +394,6 @@ export class CoreLoginSitePage implements OnInit {
|
|||
const pageParams = { siteCheck };
|
||||
if (foundSite && !this.fixedSites) {
|
||||
pageParams['siteName'] = foundSite.name;
|
||||
pageParams['logoUrl'] = foundSite.imageurl;
|
||||
}
|
||||
|
||||
CoreNavigator.navigate('/login/credentials', {
|
||||
|
@ -635,12 +635,8 @@ export class CoreLoginSitePage implements OnInit {
|
|||
* @param siteUrl Site URL.
|
||||
* @returns Whether to display URL.
|
||||
*/
|
||||
displaySiteUrl(siteUrl?: string): boolean {
|
||||
if (!siteUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CoreSites.shouldDisplayInformativeLinks(siteUrl);
|
||||
displaySiteUrl(siteUrl: string): boolean {
|
||||
return CoreSitesFactory.makeUnauthenticatedSite(siteUrl).shouldDisplayInformativeLinks();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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, CoreSiteQRCodeType, TypeOfLogin } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { DomSanitizer, makeSingleton, Translate } from '@singletons';
|
||||
|
@ -41,6 +41,12 @@ import { CorePromisedValue } from '@classes/promised-value';
|
|||
import { SafeHtml } from '@angular/platform-browser';
|
||||
import { CoreLoginError } from '@classes/errors/loginerror';
|
||||
import { CoreSettingsHelper } from '@features/settings/services/settings-helper';
|
||||
import {
|
||||
CoreSiteIdentityProvider,
|
||||
CoreSitePublicConfigResponse,
|
||||
CoreSiteQRCodeType,
|
||||
TypeOfLogin,
|
||||
} from '@classes/sites/unauthenticated-site';
|
||||
|
||||
const PASSWORD_RESETS_CONFIG_KEY = 'password-resets';
|
||||
|
||||
|
@ -301,6 +307,7 @@ export class CoreLoginHelperProvider {
|
|||
*
|
||||
* @param config Site public config.
|
||||
* @returns Logo URL.
|
||||
* @deprecated since 4.2. Please use getLogoUrl in a site instance.
|
||||
*/
|
||||
getLogoUrl(config: CoreSitePublicConfigResponse): string | undefined {
|
||||
return !CoreConstants.CONFIG.forceLoginLogo && config ? (config.logourl || config.compactlogourl) : undefined;
|
||||
|
@ -1515,23 +1522,6 @@ export class CoreLoginHelperProvider {
|
|||
return CoreTextUtils.parseJSON<Record<string, number>>(passwordResetsJson, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL belongs to the demo mode site.
|
||||
*
|
||||
* @returns Whether the URL belongs to the demo mode site.
|
||||
*/
|
||||
isDemoModeSite(url: string): boolean {
|
||||
const demoSiteData = CoreLoginHelper.getDemoModeSiteInfo();
|
||||
if (!demoSiteData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const demoSiteUrl = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(demoSiteData.url));
|
||||
url = CoreTextUtils.addEndingSlash(CoreUrlUtils.removeProtocolAndWWW(url));
|
||||
|
||||
return demoSiteUrl.indexOf(url) === 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreLoginHelper = makeSingleton(CoreLoginHelperProvider);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { CoreSiteInfo } from '@classes/sites/site';
|
||||
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreUserTourDirectiveOptions } from '@directives/user-tour';
|
||||
import { CoreUserToursAlignment, CoreUserToursSide } from '@features/usertours/services/user-tours';
|
||||
import { IonRouterOutlet } from '@ionic/angular';
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { CoreSite, CoreSiteInfo } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreFilter } from '@features/filter/services/filter';
|
||||
import { CoreLoginSitesModalComponent } from '@features/login/components/sites-modal/sites-modal';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
|
@ -71,7 +72,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount');
|
||||
this.displayContactSupport = new CoreUserAuthenticatedSupportConfig(currentSite).canContactSupport();
|
||||
this.removeAccountOnLogout = !!CoreConstants.CONFIG.removeaccountonlogout;
|
||||
this.displaySiteUrl = CoreSites.shouldDisplayInformativeLinks(currentSite);
|
||||
this.displaySiteUrl = currentSite.shouldDisplayInformativeLinks();
|
||||
|
||||
this.loadSiteLogo(currentSite);
|
||||
|
||||
|
@ -115,8 +116,8 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
* @returns Promise resolved when done.
|
||||
*/
|
||||
protected async loadSiteLogo(currentSite: CoreSite): Promise<void> {
|
||||
if (CoreConstants.CONFIG.forceLoginLogo || currentSite.isDemoModeSite()) {
|
||||
this.siteLogo = 'assets/img/login_logo.png';
|
||||
if (currentSite.forcesLocalLogo()) {
|
||||
this.siteLogo = currentSite.getLogoUrl();
|
||||
this.siteLogoLoaded = true;
|
||||
|
||||
return;
|
||||
|
@ -125,7 +126,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
try {
|
||||
const siteConfig = await currentSite.getPublicConfig();
|
||||
|
||||
this.siteLogo = CoreLoginHelper.getLogoUrl(siteConfig);
|
||||
this.siteLogo = currentSite.getLogoUrl(siteConfig);
|
||||
} catch {
|
||||
// Ignore errors.
|
||||
} finally {
|
||||
|
|
|
@ -24,7 +24,7 @@ import { CoreUtils } from '@services/utils/utils';
|
|||
import { CoreTextUtils } from '@services/utils/text';
|
||||
import { CoreConfig } from '@services/config';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { CoreSite, CoreSiteInfo } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { makeSingleton, Badge, Push, Device, Translate, ApplicationInit, NgZone } from '@singletons';
|
||||
import { CoreLogger } from '@singletons/logger';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
|
@ -48,6 +48,7 @@ import { CoreObject } from '@singletons/object';
|
|||
import { lazyMap, LazyMap } from '@/core/utils/lazy-map';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Service to handle push notifications.
|
||||
|
|
|
@ -28,6 +28,7 @@ import { CoreNavigator } from '@services/navigator';
|
|||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
|
||||
/**
|
||||
* Device Info to be shown and copied to clipboard.
|
||||
|
@ -202,7 +203,8 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
|
|||
|
||||
this.deviceInfo.siteUrl = currentSite?.getURL() || firstUrl || undefined;
|
||||
this.deviceInfo.isPrefixedUrl = !!sites.length;
|
||||
this.displaySiteUrl = !!this.deviceInfo.siteUrl && CoreSites.shouldDisplayInformativeLinks(this.deviceInfo.siteUrl);
|
||||
this.displaySiteUrl = !!this.deviceInfo.siteUrl &&
|
||||
(currentSite ?? CoreSitesFactory.makeUnauthenticatedSite(this.deviceInfo.siteUrl)).shouldDisplayInformativeLinks();
|
||||
|
||||
if (fileProvider.isAvailable()) {
|
||||
const basepath = await fileProvider.getBasePath();
|
||||
|
|
|
@ -17,7 +17,7 @@ import { CoreSites } from '@services/sites';
|
|||
import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate';
|
||||
import { CoreSiteHome } from '../sitehome';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/sites/site';
|
||||
import { CoreSiteInfoUserHomepage } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Handler to add site home into home page.
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreApp } from '@services/app';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreSite, CoreSiteConfigSupportAvailability } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUserSupportConfig } from './support-config';
|
||||
import { CoreSiteConfigSupportAvailability } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Support config for an authenticated user.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreSiteConfigSupportAvailability, CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSiteConfigSupportAvailability, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { CoreSite, CoreSiteConfig, CoreSiteInfo } from '@classes/sites/site';
|
||||
import { CoreSite, CoreSiteConfig } from '@classes/sites/site';
|
||||
import { CoreUnauthenticatedSite, CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
import { makeSingleton } from '@singletons';
|
||||
|
||||
/*
|
||||
|
@ -47,6 +48,16 @@ export class CoreSitesFactoryService {
|
|||
return new CoreSite(id, siteUrl, token, info, privateToken, config, loggedOut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an unauthenticated site instance.
|
||||
*
|
||||
* @param siteUrl Site URL.
|
||||
* @returns Unauthenticated site instance.
|
||||
*/
|
||||
makeUnauthenticatedSite(siteUrl: string): CoreUnauthenticatedSite {
|
||||
return new CoreUnauthenticatedSite(siteUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreSitesFactory = makeSingleton(CoreSitesFactoryService);
|
||||
|
|
|
@ -27,10 +27,7 @@ import { CoreConstants } from '@/core/constants';
|
|||
import {
|
||||
CoreSite,
|
||||
CoreSiteWSPreSets,
|
||||
CoreSiteInfo,
|
||||
CoreSiteConfig,
|
||||
CoreSitePublicConfigResponse,
|
||||
CoreSiteInfoResponse,
|
||||
} from '@classes/sites/site';
|
||||
import { SQLiteDB, SQLiteDBRecordValues, SQLiteDBTableSchema } from '@classes/sqlitedb';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
|
@ -67,6 +64,7 @@ import { CoreNative } from '@features/native/services/native';
|
|||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||
import { CoreAutoLogoutType, CoreAutoLogout } from '@features/autologout/services/autologout';
|
||||
import { CoreCacheManager } from '@services/cache-manager';
|
||||
import { CoreSiteInfo, CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
export const CORE_SITE_SCHEMAS = new InjectionToken<CoreSiteSchema[]>('CORE_SITE_SCHEMAS');
|
||||
export const CORE_SITE_CURRENT_SITE_ID_CONFIG = 'current_site_id';
|
||||
|
@ -273,7 +271,7 @@ export class CoreSitesProvider {
|
|||
siteUrl = siteUrl.replace(/^https?:\/\//i, protocol);
|
||||
|
||||
// Create a temporary site to fetch site info.
|
||||
let temporarySite = CoreSitesFactory.makeSite(undefined, siteUrl);
|
||||
const temporarySite = CoreSitesFactory.makeUnauthenticatedSite(siteUrl);
|
||||
let config: CoreSitePublicConfigResponse | undefined;
|
||||
|
||||
try {
|
||||
|
@ -285,7 +283,7 @@ export class CoreSitesProvider {
|
|||
}
|
||||
|
||||
// Try to add or remove 'www'.
|
||||
temporarySite = CoreSitesFactory.makeSite(undefined, CoreUrlUtils.addOrRemoveWWW(siteUrl));
|
||||
temporarySite.setURL(CoreUrlUtils.addOrRemoveWWW(temporarySite.getURL()));
|
||||
|
||||
try {
|
||||
config = await temporarySite.getPublicConfig();
|
||||
|
@ -1243,12 +1241,12 @@ export class CoreSitesProvider {
|
|||
* @param ids IDs of sites to return, undefined to return them all.
|
||||
* @returns Sites basic info.
|
||||
*/
|
||||
protected siteDBRecordsToBasicInfo(sites: SiteDBEntry[], ids?: string[]): CoreSiteBasicInfo[] {
|
||||
protected async siteDBRecordsToBasicInfo(sites: SiteDBEntry[], ids?: string[]): Promise<CoreSiteBasicInfo[]> {
|
||||
const formattedSites: CoreSiteBasicInfo[] = [];
|
||||
|
||||
sites.forEach((site) => {
|
||||
await Promise.all(sites.map(async (site) => {
|
||||
if (!ids || ids.indexOf(site.id) > -1) {
|
||||
const isDemoModeSite = CoreLoginHelper.isDemoModeSite(site.siteUrl);
|
||||
const siteName = await CoreSitesFactory.makeUnauthenticatedSite(site.siteUrl).getSiteName();
|
||||
const siteInfo = site.info ? <CoreSiteInfo> CoreTextUtils.parseJSON(site.info) : undefined;
|
||||
|
||||
const basicInfo: CoreSiteBasicInfo = {
|
||||
|
@ -1259,14 +1257,15 @@ export class CoreSitesProvider {
|
|||
fullname: siteInfo?.fullname,
|
||||
firstname: siteInfo?.firstname,
|
||||
lastname: siteInfo?.lastname,
|
||||
siteName: isDemoModeSite ? CoreConstants.CONFIG.appname : siteInfo?.sitename,
|
||||
siteName,
|
||||
userpictureurl: siteInfo?.userpictureurl,
|
||||
siteHomeId: siteInfo?.siteid || 1,
|
||||
loggedOut: !!site.loggedOut,
|
||||
info: siteInfo,
|
||||
};
|
||||
formattedSites.push(basicInfo);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
return formattedSites;
|
||||
}
|
||||
|
@ -1666,7 +1665,7 @@ export class CoreSitesProvider {
|
|||
* @returns Promise resolved with the public config.
|
||||
*/
|
||||
getSitePublicConfig(siteUrl: string): Promise<CoreSitePublicConfigResponse> {
|
||||
const temporarySite = CoreSitesFactory.makeSite(undefined, siteUrl);
|
||||
const temporarySite = CoreSitesFactory.makeUnauthenticatedSite(siteUrl);
|
||||
|
||||
return temporarySite.getPublicConfig();
|
||||
}
|
||||
|
@ -2071,30 +2070,6 @@ export class CoreSitesProvider {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether informative links should be displayed for a certain site, or current site.
|
||||
*
|
||||
* @param siteOrUrl Site instance or site URL. If not defined, current site.
|
||||
* @returns Whether informative links should be displayed.
|
||||
*/
|
||||
shouldDisplayInformativeLinks(siteOrUrl?: CoreSite | string): boolean {
|
||||
if (CoreConstants.CONFIG.hideInformativeLinks) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't display informative links for demo sites either.
|
||||
siteOrUrl = siteOrUrl ?? this.getCurrentSite();
|
||||
if (!siteOrUrl) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeof siteOrUrl === 'string') {
|
||||
return !CoreLoginHelper.isDemoModeSite(siteOrUrl);
|
||||
} else {
|
||||
return !siteOrUrl.isDemoModeSite();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreSites = makeSingleton(CoreSitesProvider);
|
||||
|
@ -2160,6 +2135,7 @@ export type CoreSiteBasicInfo = {
|
|||
badge?: number; // Badge to display in the site.
|
||||
siteHomeId?: number; // Site home ID.
|
||||
loggedOut: boolean; // If Site is logged out.
|
||||
info?: CoreSiteInfo; // Site info.
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,11 +15,12 @@
|
|||
import { Subject } from 'rxjs';
|
||||
|
||||
import { CoreLogger } from '@singletons/logger';
|
||||
import { CoreSite, CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/site';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreFilepoolComponentFileEventData } from '@services/filepool';
|
||||
import { CoreRedirectPayload } from '@services/navigator';
|
||||
import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper';
|
||||
import { CoreScreenOrientation } from '@services/screen';
|
||||
import { CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
|
||||
|
||||
/**
|
||||
* Observer instance to stop listening to an event.
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreSite, CoreSiteConfigResponse, CoreSiteInfo, CoreSiteWSPreSets, WSObservable } from '@classes/sites/site';
|
||||
import { CoreSite, CoreSiteConfigResponse, CoreSiteWSPreSets, WSObservable } from '@classes/sites/site';
|
||||
import { CoreSiteInfo } from '@classes/sites/unauthenticated-site';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
export interface CoreSiteFixture {
|
||||
|
|
Loading…
Reference in New Issue