MOBILE-3013 core: Support URLs without protocol in new schemes
parent
99f79b9ff9
commit
15aac08bdd
|
@ -140,8 +140,23 @@ export class CoreCustomURLSchemesProvider {
|
||||||
|
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
if (!currentSite || currentSite.getToken() != data.token) {
|
if (!currentSite || currentSite.getToken() != data.token) {
|
||||||
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken);
|
// Token belongs to a different site, create it. It doesn't matter if it already exists.
|
||||||
|
let promise;
|
||||||
|
|
||||||
|
if (!data.siteUrl.match(/^https?:\/\//)) {
|
||||||
|
// URL doesn't have a protocol and it's required to be able to create the site. Check which one to use.
|
||||||
|
promise = this.sitesProvider.checkSite(data.siteUrl).then((result) => {
|
||||||
|
data.siteUrl = result.siteUrl;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then(() => {
|
||||||
|
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// Token belongs to current site, no need to create it.
|
||||||
return this.sitesProvider.getCurrentSiteId();
|
return this.sitesProvider.getCurrentSiteId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,12 +313,33 @@ export class CoreCustomURLSchemesProvider {
|
||||||
url = url.substr(0, url.indexOf('?'));
|
url = url.substr(0, url.indexOf('?'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({
|
let promise;
|
||||||
siteUrl: url,
|
|
||||||
username: username,
|
if (!url.match(/https?:\/\//)) {
|
||||||
token: params.token,
|
// Url doesn't have a protocol. Check if the site is stored in the app to be able to determine the protocol.
|
||||||
privateToken: params.privateToken,
|
promise = this.sitesProvider.getSiteIdsFromUrl(url, true, username).then((siteIds) => {
|
||||||
redirect: params.redirect
|
if (siteIds.length) {
|
||||||
|
// There is at least 1 site with this URL. Use it to know the full URL.
|
||||||
|
return this.sitesProvider.getSite(siteIds[0]).then((site) => {
|
||||||
|
return site.getURL();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// No site stored with this URL, just use the URL as it is.
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise = Promise.resolve(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then((url) => {
|
||||||
|
return {
|
||||||
|
siteUrl: url,
|
||||||
|
username: username,
|
||||||
|
token: params.token,
|
||||||
|
privateToken: params.privateToken,
|
||||||
|
redirect: params.redirect
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ export class CoreUrlUtilsProvider {
|
||||||
getUsernameFromUrl(url: string): string {
|
getUsernameFromUrl(url: string): string {
|
||||||
if (url.indexOf('@') > -1) {
|
if (url.indexOf('@') > -1) {
|
||||||
// Get URL without protocol.
|
// Get URL without protocol.
|
||||||
const withoutProtocol = url.replace(/.*?:\/\//, ''),
|
const withoutProtocol = url.replace(/^[^?@\/]*:\/\//, ''),
|
||||||
matches = withoutProtocol.match(/[^@]*/);
|
matches = withoutProtocol.match(/[^@]*/);
|
||||||
|
|
||||||
// Make sure that @ is at the start of the URL, not in a param at the end.
|
// Make sure that @ is at the start of the URL, not in a param at the end.
|
||||||
|
|
Loading…
Reference in New Issue