MOBILE-3286 login: Parse url domain if site wasn't found
parent
421ea59db0
commit
28404f8b25
|
@ -0,0 +1,29 @@
|
|||
// (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.
|
||||
|
||||
export class CoreUrl {
|
||||
|
||||
/**
|
||||
* Parse url domain.
|
||||
*
|
||||
* @param url Url.
|
||||
* @return Url domain.
|
||||
*/
|
||||
static parseDomain(url: string): string | null {
|
||||
const match = url.trim().match(/(https?:\/\/|^)([^/]+)/);
|
||||
|
||||
return match ? match[2] : null;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,11 +15,12 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { IonicPage, NavController, ModalController, NavParams } from 'ionic-angular';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreSitesProvider, CoreSiteCheckResponse } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreConfigConstants } from '../../../../configconstants';
|
||||
import { CoreLoginHelperProvider } from '../../providers/helper';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { CoreUrl } from '@classes/utils/url';
|
||||
|
||||
/**
|
||||
* Page to enter or select the site URL to connect to.
|
||||
|
@ -111,27 +112,22 @@ export class CoreLoginSitePage {
|
|||
|
||||
} else {
|
||||
// Not a demo site.
|
||||
this.sitesProvider.checkSite(url).then((result) => {
|
||||
return this.sitesProvider.checkRequiredMinimumVersion(result.config).then(() => {
|
||||
if (result.warning) {
|
||||
this.domUtils.showErrorModal(result.warning, true, 4000);
|
||||
this.sitesProvider.checkSite(url)
|
||||
|
||||
// Attempt parsing the domain after initial check failed
|
||||
.catch((error) => {
|
||||
const domain = CoreUrl.parseDomain(url);
|
||||
|
||||
if (!domain) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (this.loginHelper.isSSOLoginNeeded(result.code)) {
|
||||
// SSO. User needs to authenticate in a browser.
|
||||
this.loginHelper.confirmAndOpenBrowserForSSOLogin(
|
||||
result.siteUrl, result.code, result.service, result.config && result.config.launchurl);
|
||||
} else {
|
||||
this.navCtrl.push('CoreLoginCredentialsPage', { siteUrl: result.siteUrl, siteConfig: result.config });
|
||||
}
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
}, (error) => {
|
||||
this.showLoginIssue(url, error);
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
return this.sitesProvider.checkSite(domain);
|
||||
})
|
||||
|
||||
.then((result) => this.login(result))
|
||||
.catch((error) => this.showLoginIssue(url, error))
|
||||
.finally(() => modal.dismiss());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,4 +169,23 @@ export class CoreLoginSitePage {
|
|||
|
||||
modal.present();
|
||||
}
|
||||
|
||||
private async login(response: CoreSiteCheckResponse): Promise<void> {
|
||||
return this.sitesProvider.checkRequiredMinimumVersion(response.config).then(() => {
|
||||
if (response.warning) {
|
||||
this.domUtils.showErrorModal(response.warning, true, 4000);
|
||||
}
|
||||
|
||||
if (this.loginHelper.isSSOLoginNeeded(response.code)) {
|
||||
// SSO. User needs to authenticate in a browser.
|
||||
this.loginHelper.confirmAndOpenBrowserForSSOLogin(
|
||||
response.siteUrl, response.code, response.service, response.config && response.config.launchurl);
|
||||
} else {
|
||||
this.navCtrl.push('CoreLoginCredentialsPage', { siteUrl: response.siteUrl, siteConfig: response.config });
|
||||
}
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue