Skip to content

Commit 581a695

Browse files
authored
Merge pull request #4705 from dpalou/MOBILE-4974
Mobile 4974
2 parents 51daf35 + fc740ad commit 581a695

File tree

5 files changed

+48
-73
lines changed

5 files changed

+48
-73
lines changed

src/core/classes/errors/ajaxerror.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class CoreAjaxError extends CoreSiteError {
2121

2222
status?: number;
2323

24-
constructor(messageOrOptions: string | CoreSiteErrorOptions, available?: number, status?: number) {
24+
constructor(messageOrOptions: string | CoreSiteErrorOptions, status?: number) {
2525
super(typeof messageOrOptions === 'string' ? { message: messageOrOptions } : messageOrOptions);
2626

2727
this.status = status;

src/core/features/login/pages/site/site.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class CoreLoginSitePage implements OnInit {
6868
siteForm!: FormGroup;
6969
fixedSites?: CoreLoginSiteInfoExtended[];
7070
filteredSites?: CoreLoginSiteInfoExtended[];
71-
siteSelector: CoreLoginSiteSelectorListMethod = 'sitefinder';
71+
siteSelector = CoreLoginSiteSelectorListMethod.SITE_FINDER;
7272
showKeyboard = false;
7373
filter = '';
7474
sites: CoreLoginSiteInfoExtended[] = [];
@@ -149,7 +149,7 @@ export default class CoreLoginSitePage implements OnInit {
149149
protected async initSiteSelector(): Promise<string> {
150150
const availableSites = await CoreLoginHelper.getAvailableSites();
151151
this.fixedSites = this.extendCoreLoginSiteInfo(<CoreLoginSiteInfoExtended[]> availableSites);
152-
this.siteSelector = 'list'; // In case it's not defined
152+
this.siteSelector = CoreLoginSiteSelectorListMethod.LIST; // In case it's not defined
153153

154154
// Do not show images if none are set.
155155
if (!this.fixedSites.some((site) => !!site.imageurl)) {
@@ -304,7 +304,7 @@ export default class CoreLoginSitePage implements OnInit {
304304
// Attempt guessing the domain if the initial check failed
305305
const domain = CoreUrl.guessMoodleDomain(url);
306306

307-
if (domain && domain != url) {
307+
if (domain && domain !== url) {
308308
try {
309309
checkResult = await CoreSites.checkSite(domain, undefined, 'Site URL page');
310310
} catch (secondError) {
@@ -540,7 +540,7 @@ export default class CoreLoginSitePage implements OnInit {
540540
// Not a custom URL scheme, check if it's a URL scheme to another app.
541541
const scheme = CoreUrl.getUrlProtocol(text);
542542

543-
if (scheme && scheme != 'http' && scheme != 'https') {
543+
if (scheme && scheme !== 'http' && scheme !== 'https') {
544544
CoreAlerts.showError(Translate.instant('core.errorurlschemeinvalidscheme', { $a: text }));
545545

546546
return;

src/core/features/login/services/login-helper.ts

Lines changed: 37 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,6 @@ export class CoreLoginHelperProvider {
106106
this.cleanUpPasswordResets();
107107
}
108108

109-
/**
110-
* Check if a site allows requesting a password reset through the app.
111-
*
112-
* @param siteUrl URL of the site.
113-
* @returns Promise resolved with boolean: whether can be done through the app.
114-
*/
115-
async canRequestPasswordReset(siteUrl: string): Promise<boolean> {
116-
try {
117-
await this.requestPasswordReset(siteUrl);
118-
119-
return true;
120-
} catch (error) {
121-
return error.available == 1 || (error.errorcode && error.errorcode != 'invalidrecord');
122-
}
123-
}
124-
125109
/**
126110
* Function called when an SSO InAppBrowser is closed or the app is resumed. Check if user needs to be logged out.
127111
*/
@@ -157,19 +141,13 @@ export class CoreLoginHelperProvider {
157141
const modal = await CoreLoadings.show();
158142

159143
try {
160-
const canReset = await this.canRequestPasswordReset(siteUrl);
161-
162-
if (canReset) {
163-
await CoreNavigator.navigate('/login/forgottenpassword', {
164-
params: {
165-
siteUrl,
166-
siteConfig,
167-
username,
168-
},
169-
});
170-
} else {
171-
this.openForgottenPassword(siteUrl);
172-
}
144+
await CoreNavigator.navigate('/login/forgottenpassword', {
145+
params: {
146+
siteUrl,
147+
siteConfig,
148+
username,
149+
},
150+
});
173151
} finally {
174152
modal.dismiss();
175153
}
@@ -196,7 +174,7 @@ export class CoreLoginHelperProvider {
196174
site = site || CoreSites.getCurrentSite();
197175
const config = site?.getStoredConfig();
198176

199-
return `core.mainmenu.${config && config.tool_mobile_forcelogout == '1' ? 'logout' : 'switchaccount'}`;
177+
return `core.mainmenu.${config && config.tool_mobile_forcelogout === '1' ? 'logout' : 'switchaccount'}`;
200178
}
201179

202180
/**
@@ -402,8 +380,11 @@ export class CoreLoginHelperProvider {
402380

403381
return sites.some((site) => CoreUrl.sameDomainAndPath(siteUrl, site.url)) ||
404382
(!!demoModeSite && CoreUrl.sameDomainAndPath(siteUrl, demoModeSite.url));
405-
} else if (CoreConstants.CONFIG.multisitesdisplay == 'sitefinder' && CoreConstants.CONFIG.onlyallowlistedsites &&
406-
checkSiteFinder) {
383+
} else if (
384+
CoreConstants.CONFIG.multisitesdisplay === CoreLoginSiteSelectorListMethod.SITE_FINDER &&
385+
CoreConstants.CONFIG.onlyallowlistedsites &&
386+
checkSiteFinder
387+
) {
407388
// Call the sites finder to validate the site.
408389
const result = await CoreSites.findSites(siteUrl.replace(/^https?:\/\/|\.\w{2,3}\/?$/g, ''));
409390

@@ -418,20 +399,20 @@ export class CoreLoginHelperProvider {
418399
* Check if SSO login should use an embedded browser.
419400
*
420401
* @param code Code to check.
421-
* @returns True if embedded browser, false othwerise.
402+
* @returns True if embedded browser, false otherwise.
422403
*/
423404
isSSOEmbeddedBrowser(code: TypeOfLogin): boolean {
424-
return code == TypeOfLogin.EMBEDDED;
405+
return code === TypeOfLogin.EMBEDDED;
425406
}
426407

427408
/**
428409
* Check if SSO login is needed based on code returned by the WS.
429410
*
430411
* @param code Code to check.
431-
* @returns True if SSO login is needed, false othwerise.
412+
* @returns True if SSO login is needed, false otherwise.
432413
*/
433414
isSSOLoginNeeded(code: TypeOfLogin): boolean {
434-
return code == TypeOfLogin.BROWSER || code == TypeOfLogin.EMBEDDED;
415+
return code === TypeOfLogin.BROWSER || code === TypeOfLogin.EMBEDDED;
435416
}
436417

437418
/**
@@ -541,15 +522,6 @@ export class CoreLoginHelperProvider {
541522
CoreOpener.openInApp(`${siteUrl}/login/change_password.php`);
542523
}
543524

544-
/**
545-
* Open forgotten password in inappbrowser.
546-
*
547-
* @param siteUrl URL of the site.
548-
*/
549-
openForgottenPassword(siteUrl: string): void {
550-
CoreOpener.openInApp(`${siteUrl}/login/forgot_password.php`);
551-
}
552-
553525
/**
554526
* Function to open in app browser to change password or complete user profile.
555527
*
@@ -815,6 +787,8 @@ export class CoreLoginHelperProvider {
815787

816788
/**
817789
* Show a modal warning that the credentials introduced were not correct.
790+
*
791+
* @param error Error object.
818792
*/
819793
protected showInvalidLoginModal(error: CoreError): void {
820794
const errorDetails = error instanceof CoreSiteError ? error.debug?.details : null;
@@ -995,17 +969,17 @@ export class CoreLoginHelperProvider {
995969

996970
// Validate the signature.
997971
// We need to check both http and https.
998-
let signature = Md5.hashAsciiStr(launchSiteURL + passport);
999-
if (signature != params[0]) {
1000-
if (launchSiteURL.indexOf('https://') != -1) {
972+
let signature: string = Md5.hashAsciiStr(launchSiteURL + passport);
973+
if (signature !== params[0]) {
974+
if (launchSiteURL.includes('https://')) {
1001975
launchSiteURL = launchSiteURL.replace('https://', 'http://');
1002976
} else {
1003977
launchSiteURL = launchSiteURL.replace('http://', 'https://');
1004978
}
1005979
signature = Md5.hashAsciiStr(launchSiteURL + passport);
1006980
}
1007981

1008-
if (signature == params[0]) {
982+
if (signature === params[0]) {
1009983
this.logger.debug('Signature validated');
1010984

1011985
return {
@@ -1131,7 +1105,7 @@ export class CoreLoginHelperProvider {
11311105
// Not a custom URL scheme, check if it's a URL scheme to another app.
11321106
const scheme = CoreUrl.getUrlProtocol(text);
11331107

1134-
if (scheme && scheme != 'http' && scheme != 'https') {
1108+
if (scheme && scheme !== 'http' && scheme !== 'https') {
11351109
CoreAlerts.showError(Translate.instant('core.errorurlschemeinvalidscheme', { $a: text }));
11361110
} else {
11371111
CoreAlerts.showError(Translate.instant('core.login.errorqrnoscheme'));
@@ -1155,7 +1129,7 @@ export class CoreLoginHelperProvider {
11551129
let siteUrl = '';
11561130

11571131
if (currentSiteId) {
1158-
siteUrl = sites.find((site) => site.id == currentSiteId)?.siteUrlWithoutProtocol ?? '';
1132+
siteUrl = sites.find((site) => site.id === currentSiteId)?.siteUrlWithoutProtocol ?? '';
11591133
}
11601134

11611135
const otherSites: Record<string, CoreSiteBasicInfo[]> = {};
@@ -1166,7 +1140,7 @@ export class CoreLoginHelperProvider {
11661140

11671141
if (site.id === currentSiteId) {
11681142
accountsList.currentSite = site;
1169-
} else if (site.siteUrlWithoutProtocol == siteUrl) {
1143+
} else if (site.siteUrlWithoutProtocol === siteUrl) {
11701144
accountsList.sameSite.push(site);
11711145
} else {
11721146
if (!otherSites[site.siteUrlWithoutProtocol]) {
@@ -1197,8 +1171,8 @@ export class CoreLoginHelperProvider {
11971171
let index = 0;
11981172

11991173
// Found on same site.
1200-
if (accountsList.sameSite.length > 0 && accountsList.sameSite[0].siteUrlWithoutProtocol == siteUrl) {
1201-
index = accountsList.sameSite.findIndex((listedSite) => listedSite.id == site.id);
1174+
if (accountsList.sameSite.length > 0 && accountsList.sameSite[0].siteUrlWithoutProtocol === siteUrl) {
1175+
index = accountsList.sameSite.findIndex((listedSite) => listedSite.id === site.id);
12021176
if (index >= 0) {
12031177
accountsList.sameSite.splice(index, 1);
12041178
accountsList.count--;
@@ -1208,19 +1182,19 @@ export class CoreLoginHelperProvider {
12081182
}
12091183

12101184
const otherSiteIndex = accountsList.otherSites.findIndex((sites) =>
1211-
sites.length > 0 && sites[0].siteUrlWithoutProtocol == siteUrl);
1185+
sites.length > 0 && sites[0].siteUrlWithoutProtocol === siteUrl);
12121186
if (otherSiteIndex < 0) {
12131187
// Site Url not found.
12141188
return;
12151189
}
12161190

1217-
index = accountsList.otherSites[otherSiteIndex].findIndex((listedSite) => listedSite.id == site.id);
1191+
index = accountsList.otherSites[otherSiteIndex].findIndex((listedSite) => listedSite.id === site.id);
12181192
if (index >= 0) {
12191193
accountsList.otherSites[otherSiteIndex].splice(index, 1);
12201194
accountsList.count--;
12211195
}
12221196

1223-
if (accountsList.otherSites[otherSiteIndex].length == 0) {
1197+
if (!accountsList.otherSites[otherSiteIndex].length) {
12241198
accountsList.otherSites.splice(otherSiteIndex, 1);
12251199
}
12261200
}
@@ -1400,11 +1374,12 @@ type StoredLoginLaunchData = CoreRedirectPayload & {
14001374
ssoUrlParams: CoreUrlParams;
14011375
};
14021376

1403-
export type CoreLoginSiteSelectorListMethod =
1404-
'url'|
1405-
'sitefinder'|
1406-
'list'|
1407-
'';
1377+
export const enum CoreLoginSiteSelectorListMethod {
1378+
URL = 'url',
1379+
SITE_FINDER = 'sitefinder',
1380+
LIST = 'list',
1381+
NONE = '',
1382+
}
14081383

14091384
export type CoreLoginMethod = {
14101385
name: string; // Name of the login method.

src/core/services/ws.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class CoreWSProvider {
189189
}
190190
value = stripped;
191191
}
192-
} else if (typeof value == 'boolean') {
192+
} else if (typeof value === 'boolean') {
193193
/* Moodle does not allow "true" or "false" in WS parameters, only in POST parameters.
194194
We've been using "true" and "false" for WS settings "filter" and "fileurl",
195195
we keep it this way to avoid changing cache keys. */
@@ -198,7 +198,7 @@ export class CoreWSProvider {
198198
} else {
199199
value = value ? '1' : '0';
200200
}
201-
} else if (typeof value == 'number') {
201+
} else if (typeof value === 'number') {
202202
value = String(value);
203203
} else {
204204
// Unknown type.
@@ -621,7 +621,7 @@ export class CoreWSProvider {
621621
}
622622
}
623623

624-
throw new CoreAjaxError(options, 1, data.status);
624+
throw new CoreAjaxError(options, data.status);
625625
}).catch(error => {
626626
const type = `CoreAjaxError - ${error.errorcode}`;
627627
CoreErrorLogs.addErrorLog({ method, type, message: error, time: new Date().getTime(), data });
@@ -766,7 +766,7 @@ export class CoreWSProvider {
766766
});
767767
} else if (typeof data !== typeExpected) {
768768
// If responseType is text an string will be returned, parse before returning.
769-
if (typeof data == 'string') {
769+
if (typeof data === 'string') {
770770
if (typeExpected === 'number') {
771771
data = Number(data);
772772
if (isNaN(data)) {
@@ -998,7 +998,7 @@ export class CoreWSProvider {
998998
throw new CoreError(Translate.instant('core.serverconnection', {
999999
details: Translate.instant('core.errorinvalidresponse', { method }),
10001000
}));
1001-
} else if (typeof data != preSets.typeExpected) {
1001+
} else if (typeof data !== preSets.typeExpected) {
10021002
this.logger.warn(`Response of type "${typeof data}" received, expecting "${preSets.typeExpected}"`);
10031003
throw new CoreError(Translate.instant('core.errorinvalidresponse', { method }));
10041004
}

src/core/static/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ export class CoreUrl {
815815
* @param url URL to treat.
816816
* @returns Protocol, undefined if no protocol found.
817817
*/
818-
static getUrlProtocol(url: string): string | void {
818+
static getUrlProtocol(url: string): string | undefined {
819819
return CoreUrl.parse(url)?.protocol;
820820
}
821821

0 commit comments

Comments
 (0)