forked from EVOgeek/Vmeda.Online
MOBILE-2853 login: Hide password in reconnect if OAuth
parent
80c2aef0d0
commit
f5a28ad584
|
@ -233,6 +233,7 @@ export class CoreSite {
|
||||||
protected requestQueueTimeout = null;
|
protected requestQueueTimeout = null;
|
||||||
protected tokenPluginFileWorks: boolean;
|
protected tokenPluginFileWorks: boolean;
|
||||||
protected tokenPluginFileWorksPromise: Promise<boolean>;
|
protected tokenPluginFileWorksPromise: Promise<boolean>;
|
||||||
|
protected oauthId: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a site.
|
* Create a site.
|
||||||
|
@ -404,6 +405,15 @@ export class CoreSite {
|
||||||
return !!this.loggedOut;
|
return !!this.loggedOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get OAuth ID.
|
||||||
|
*
|
||||||
|
* @return OAuth ID.
|
||||||
|
*/
|
||||||
|
getOAuthId(): number {
|
||||||
|
return this.oauthId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set site info.
|
* Set site info.
|
||||||
*
|
*
|
||||||
|
@ -444,6 +454,24 @@ export class CoreSite {
|
||||||
this.loggedOut = !!loggedOut;
|
this.loggedOut = !!loggedOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set OAuth ID.
|
||||||
|
*
|
||||||
|
* @param oauth OAuth ID.
|
||||||
|
*/
|
||||||
|
setOAuthId(oauthId: number): void {
|
||||||
|
this.oauthId = oauthId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user authenticated in the site using an OAuth method.
|
||||||
|
*
|
||||||
|
* @return {boolean} Whether the user authenticated in the site using an OAuth method.
|
||||||
|
*/
|
||||||
|
isOAuth(): boolean {
|
||||||
|
return this.oauthId != null && typeof this.oauthId != 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can the user access their private files?
|
* Can the user access their private files?
|
||||||
*
|
*
|
||||||
|
|
|
@ -565,7 +565,7 @@ export class LocalNotificationsMock extends LocalNotifications {
|
||||||
const notifications = await this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE);
|
const notifications = await this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE);
|
||||||
notifications.forEach((notification) => {
|
notifications.forEach((notification) => {
|
||||||
notification.trigger = {
|
notification.trigger = {
|
||||||
at: new Date(notification.at)
|
at: new Date(notification.at),
|
||||||
};
|
};
|
||||||
notification.data = this.textUtils.parseJSON(notification.data);
|
notification.data = this.textUtils.parseJSON(notification.data);
|
||||||
notification.triggered = !!notification.triggered;
|
notification.triggered = !!notification.triggered;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<ion-icon padding name="alert"></ion-icon> {{ 'core.login.reconnectdescription' | translate }}
|
<ion-icon padding name="alert"></ion-icon> {{ 'core.login.reconnectdescription' | translate }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form ion-list [formGroup]="credForm" (ngSubmit)="login($event)" class="core-login-form">
|
<form ion-list *ngIf="!isOAuth" [formGroup]="credForm" (ngSubmit)="login($event)" class="core-login-form">
|
||||||
<ion-item text-wrap class="core-username">
|
<ion-item text-wrap class="core-username">
|
||||||
<p>{{username}}</p>
|
<p>{{username}}</p>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Forgotten password button. -->
|
<!-- Forgotten password button. -->
|
||||||
<div *ngIf="showForgottenPassword" padding-top class="core-login-forgotten-password">
|
<div *ngIf="showForgottenPassword && !isOAuth" padding-top class="core-login-forgotten-password">
|
||||||
<button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button>
|
<button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -63,5 +63,12 @@
|
||||||
{{provider.name}}
|
{{provider.name}}
|
||||||
</button>
|
</button>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
|
<!-- If OAuth, display cancel button since the form isn't displayed. -->
|
||||||
|
<ion-list *ngIf="isOAuth">
|
||||||
|
<ion-item>
|
||||||
|
<a ion-button block color="light" (click)="cancel($event)">{{ 'core.login.cancel' | translate }}</a>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class CoreLoginReconnectPage {
|
||||||
site: any;
|
site: any;
|
||||||
showForgottenPassword = true;
|
showForgottenPassword = true;
|
||||||
showSiteAvatar = false;
|
showSiteAvatar = false;
|
||||||
|
isOAuth = false;
|
||||||
|
|
||||||
protected infoSiteUrl: string;
|
protected infoSiteUrl: string;
|
||||||
protected pageName: string;
|
protected pageName: string;
|
||||||
|
@ -87,6 +88,7 @@ export class CoreLoginReconnectPage {
|
||||||
this.username = site.infos.username;
|
this.username = site.infos.username;
|
||||||
this.siteUrl = site.infos.siteurl;
|
this.siteUrl = site.infos.siteurl;
|
||||||
this.siteName = site.getSiteName();
|
this.siteName = site.getSiteName();
|
||||||
|
this.isOAuth = site.isOAuth();
|
||||||
|
|
||||||
// Show logo instead of avatar if it's a fixed site.
|
// Show logo instead of avatar if it's a fixed site.
|
||||||
this.showSiteAvatar = this.site.avatar && !this.loginHelper.getFixedSites();
|
this.showSiteAvatar = this.site.avatar && !this.loginHelper.getFixedSites();
|
||||||
|
|
|
@ -62,6 +62,11 @@ export interface CoreLoginSSOData {
|
||||||
* Params to page to the page.
|
* Params to page to the page.
|
||||||
*/
|
*/
|
||||||
pageParams?: any;
|
pageParams?: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Other params added to the login url.
|
||||||
|
*/
|
||||||
|
ssoUrlParams?: {[name: string]: any};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +185,8 @@ export class CoreLoginHelperProvider {
|
||||||
}).then((data) => {
|
}).then((data) => {
|
||||||
siteData = data;
|
siteData = data;
|
||||||
|
|
||||||
return this.handleSSOLoginAuthentication(siteData.siteUrl, siteData.token, siteData.privateToken);
|
return this.handleSSOLoginAuthentication(siteData.siteUrl, siteData.token, siteData.privateToken,
|
||||||
|
this.getOAuthIdFromParams(data.ssoUrlParams));
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (siteData.pageName) {
|
if (siteData.pageName) {
|
||||||
// State defined, go to that state instead of site initial page.
|
// State defined, go to that state instead of site initial page.
|
||||||
|
@ -396,6 +402,16 @@ export class CoreLoginHelperProvider {
|
||||||
return 'core.mainmenu.' + (config && config.tool_mobile_forcelogout == '1' ? 'logout' : 'changesite');
|
return 'core.mainmenu.' + (config && config.tool_mobile_forcelogout == '1' ? 'logout' : 'changesite');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the OAuth ID of some URL params (if it has an OAuth ID).
|
||||||
|
*
|
||||||
|
* @param params Params.
|
||||||
|
* @return OAuth ID.
|
||||||
|
*/
|
||||||
|
getOAuthIdFromParams(params: {[name: string]: any}): number {
|
||||||
|
return params && typeof params.oauthsso != 'undefined' ? Number(params.oauthsso) : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the site policy.
|
* Get the site policy.
|
||||||
*
|
*
|
||||||
|
@ -548,11 +564,12 @@ export class CoreLoginHelperProvider {
|
||||||
* @param siteUrl Site's URL.
|
* @param siteUrl Site's URL.
|
||||||
* @param token User's token.
|
* @param token User's token.
|
||||||
* @param privateToken User's private token.
|
* @param privateToken User's private token.
|
||||||
|
* @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
|
||||||
* @return Promise resolved when the user is authenticated with the token.
|
* @return Promise resolved when the user is authenticated with the token.
|
||||||
*/
|
*/
|
||||||
handleSSOLoginAuthentication(siteUrl: string, token: string, privateToken?: string): Promise<any> {
|
handleSSOLoginAuthentication(siteUrl: string, token: string, privateToken?: string, oauthId?: number): Promise<any> {
|
||||||
// Always create a new site to prevent overriding data if another user credentials were introduced.
|
// Always create a new site to prevent overriding data if another user credentials were introduced.
|
||||||
return this.sitesProvider.newSite(siteUrl, token, privateToken);
|
return this.sitesProvider.newSite(siteUrl, token, privateToken, true, oauthId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -778,15 +795,16 @@ export class CoreLoginHelperProvider {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const service = this.sitesProvider.determineService(siteUrl),
|
const params = this.urlUtils.extractUrlParams(provider.url);
|
||||||
params = this.urlUtils.extractUrlParams(provider.url);
|
|
||||||
let loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, pageName, pageParams);
|
|
||||||
|
|
||||||
if (!params.id) {
|
if (!params.id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
loginUrl += '&oauthsso=' + params.id;
|
const service = this.sitesProvider.determineService(siteUrl);
|
||||||
|
const loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, pageName, pageParams, {
|
||||||
|
oauthsso: params.id,
|
||||||
|
});
|
||||||
|
|
||||||
if (this.appProvider.isLinux()) {
|
if (this.appProvider.isLinux()) {
|
||||||
// In Linux desktop app, always use embedded browser.
|
// In Linux desktop app, always use embedded browser.
|
||||||
|
@ -924,8 +942,12 @@ export class CoreLoginHelperProvider {
|
||||||
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used.
|
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used.
|
||||||
* @param pageName Name of the page to go once authenticated. If not defined, site initial page.
|
* @param pageName Name of the page to go once authenticated. If not defined, site initial page.
|
||||||
* @param pageParams Params of the state to go once authenticated.
|
* @param pageParams Params of the state to go once authenticated.
|
||||||
|
* @param urlParams Other params to add to the URL.
|
||||||
|
* @return Login Url.
|
||||||
*/
|
*/
|
||||||
prepareForSSOLogin(siteUrl: string, service?: string, launchUrl?: string, pageName?: string, pageParams?: any): string {
|
prepareForSSOLogin(siteUrl: string, service?: string, launchUrl?: string, pageName?: string, pageParams?: any,
|
||||||
|
urlParams?: {[name: string]: any}): string {
|
||||||
|
|
||||||
service = service || CoreConfigConstants.wsextservice;
|
service = service || CoreConfigConstants.wsextservice;
|
||||||
launchUrl = launchUrl || siteUrl + '/local/mobile/launch.php';
|
launchUrl = launchUrl || siteUrl + '/local/mobile/launch.php';
|
||||||
|
|
||||||
|
@ -935,13 +957,18 @@ export class CoreLoginHelperProvider {
|
||||||
loginUrl += '&passport=' + passport;
|
loginUrl += '&passport=' + passport;
|
||||||
loginUrl += '&urlscheme=' + CoreConfigConstants.customurlscheme;
|
loginUrl += '&urlscheme=' + CoreConfigConstants.customurlscheme;
|
||||||
|
|
||||||
|
if (urlParams) {
|
||||||
|
loginUrl = this.urlUtils.addParamsToUrl(loginUrl, urlParams);
|
||||||
|
}
|
||||||
|
|
||||||
// Store the siteurl and passport in CoreConfigProvider for persistence.
|
// Store the siteurl and passport in CoreConfigProvider for persistence.
|
||||||
// We are "configuring" the app to wait for an SSO. CoreConfigProvider shouldn't be used as a temporary storage.
|
// We are "configuring" the app to wait for an SSO. CoreConfigProvider shouldn't be used as a temporary storage.
|
||||||
this.configProvider.set(CoreConstants.LOGIN_LAUNCH_DATA, JSON.stringify({
|
this.configProvider.set(CoreConstants.LOGIN_LAUNCH_DATA, JSON.stringify({
|
||||||
siteUrl: siteUrl,
|
siteUrl: siteUrl,
|
||||||
passport: passport,
|
passport: passport,
|
||||||
pageName: pageName || '',
|
pageName: pageName || '',
|
||||||
pageParams: pageParams || {}
|
pageParams: pageParams || {},
|
||||||
|
ssoUrlParams: urlParams || {},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return loginUrl;
|
return loginUrl;
|
||||||
|
@ -1331,7 +1358,8 @@ export class CoreLoginHelperProvider {
|
||||||
token: params[1],
|
token: params[1],
|
||||||
privateToken: params[2],
|
privateToken: params[2],
|
||||||
pageName: data.pageName,
|
pageName: data.pageName,
|
||||||
pageParams: data.pageParams
|
pageParams: data.pageParams,
|
||||||
|
ssoUrlParams: data.ssoUrlParams,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.logger.debug('Invalid signature in the URL request yours: ' + params[0] + ' mine: '
|
this.logger.debug('Invalid signature in the URL request yours: ' + params[0] + ' mine: '
|
||||||
|
|
|
@ -109,9 +109,9 @@ export class CorePushNotificationsProvider {
|
||||||
{
|
{
|
||||||
name: 'number',
|
name: 'number',
|
||||||
type: 'INTEGER'
|
type: 'INTEGER'
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
primaryKeys: ['siteid', 'addon']
|
primaryKeys: ['siteid', 'addon'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE,
|
name: CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE,
|
||||||
|
@ -132,10 +132,10 @@ export class CorePushNotificationsProvider {
|
||||||
{
|
{
|
||||||
name: 'info',
|
name: 'info',
|
||||||
type: 'TEXT'
|
type: 'TEXT'
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
protected siteSchema: CoreSiteSchema = {
|
protected siteSchema: CoreSiteSchema = {
|
||||||
name: 'AddonPushNotificationsProvider', // The name still contains "Addon" for backwards compatibility.
|
name: 'AddonPushNotificationsProvider', // The name still contains "Addon" for backwards compatibility.
|
||||||
|
@ -583,7 +583,7 @@ export class CorePushNotificationsProvider {
|
||||||
siteid: site.id,
|
siteid: site.id,
|
||||||
siteurl: site.getURL(),
|
siteurl: site.getURL(),
|
||||||
token: site.getToken(),
|
token: site.getToken(),
|
||||||
info: JSON.stringify(site.getInfo())
|
info: JSON.stringify(site.getInfo()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,9 @@ export class CoreAppProvider {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'version',
|
name: 'version',
|
||||||
type: 'INTEGER'
|
type: 'INTEGER',
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
|
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
|
||||||
|
|
|
@ -39,8 +39,8 @@ export class CoreConfigProvider {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'value'
|
name: 'value'
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -107,8 +107,8 @@ export class CoreCronDelegate {
|
||||||
{
|
{
|
||||||
name: 'value',
|
name: 'value',
|
||||||
type: 'INTEGER'
|
type: 'INTEGER'
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -274,11 +274,11 @@ export class CoreFilepoolProvider {
|
||||||
{
|
{
|
||||||
name: 'links',
|
name: 'links',
|
||||||
type: 'TEXT'
|
type: 'TEXT'
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
primaryKeys: ['siteId', 'fileId']
|
primaryKeys: ['siteId', 'fileId'],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
protected siteSchema: CoreSiteSchema = {
|
protected siteSchema: CoreSiteSchema = {
|
||||||
name: 'CoreFilepoolProvider',
|
name: 'CoreFilepoolProvider',
|
||||||
|
|
|
@ -56,8 +56,8 @@ export class CoreLocalNotificationsProvider {
|
||||||
name: 'code',
|
name: 'code',
|
||||||
type: 'INTEGER',
|
type: 'INTEGER',
|
||||||
notNull: true
|
notNull: true
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.COMPONENTS_TABLE,
|
name: this.COMPONENTS_TABLE,
|
||||||
|
@ -71,8 +71,8 @@ export class CoreLocalNotificationsProvider {
|
||||||
name: 'code',
|
name: 'code',
|
||||||
type: 'INTEGER',
|
type: 'INTEGER',
|
||||||
notNull: true
|
notNull: true
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.TRIGGERED_TABLE,
|
name: this.TRIGGERED_TABLE,
|
||||||
|
@ -86,10 +86,10 @@ export class CoreLocalNotificationsProvider {
|
||||||
name: 'at',
|
name: 'at',
|
||||||
type: 'INTEGER',
|
type: 'INTEGER',
|
||||||
notNull: true
|
notNull: true
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
protected logger;
|
protected logger;
|
||||||
|
|
|
@ -170,7 +170,7 @@ export const enum CoreSitesReadingStrategy {
|
||||||
* their own database tables. Example:
|
* their own database tables. Example:
|
||||||
*
|
*
|
||||||
* constructor(sitesProvider: CoreSitesProvider) {
|
* constructor(sitesProvider: CoreSitesProvider) {
|
||||||
* this.sitesProvider.registerSiteSchema(this.siteSchema);
|
* this.sitesProvider.registerSiteSchema(this.tableSchema);
|
||||||
*
|
*
|
||||||
* This provider will automatically create the tables in the databases of all the instantiated sites, and also to the
|
* This provider will automatically create the tables in the databases of all the instantiated sites, and also to the
|
||||||
* databases of sites instantiated from now on.
|
* databases of sites instantiated from now on.
|
||||||
|
@ -178,15 +178,15 @@ export const enum CoreSitesReadingStrategy {
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CoreSitesProvider {
|
export class CoreSitesProvider {
|
||||||
// Variables for the database.
|
// Variables for the database.
|
||||||
protected SITES_TABLE = 'sites';
|
static SITES_TABLE = 'sites_2';
|
||||||
protected CURRENT_SITE_TABLE = 'current_site';
|
static CURRENT_SITE_TABLE = 'current_site';
|
||||||
protected SCHEMA_VERSIONS_TABLE = 'schema_versions';
|
static SCHEMA_VERSIONS_TABLE = 'schema_versions';
|
||||||
protected appTablesSchema: CoreAppSchema = {
|
protected appTablesSchema: CoreAppSchema = {
|
||||||
name: 'CoreSitesProvider',
|
name: 'CoreSitesProvider',
|
||||||
version: 1,
|
version: 2,
|
||||||
tables: [
|
tables: [
|
||||||
{
|
{
|
||||||
name: this.SITES_TABLE,
|
name: CoreSitesProvider.SITES_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
@ -217,11 +217,15 @@ export class CoreSitesProvider {
|
||||||
{
|
{
|
||||||
name: 'loggedOut',
|
name: 'loggedOut',
|
||||||
type: 'INTEGER'
|
type: 'INTEGER'
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
name: 'oauthId',
|
||||||
|
type: 'INTEGER'
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.CURRENT_SITE_TABLE,
|
name: CoreSitesProvider.CURRENT_SITE_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
|
@ -233,10 +237,36 @@ export class CoreSitesProvider {
|
||||||
type: 'TEXT',
|
type: 'TEXT',
|
||||||
notNull: true,
|
notNull: true,
|
||||||
unique: true
|
unique: true
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
async migrate(db: SQLiteDB, oldVersion: number): Promise<any> {
|
||||||
|
if (oldVersion < 2) {
|
||||||
|
const newTable = CoreSitesProvider.SITES_TABLE;
|
||||||
|
const oldTable = 'sites';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if V1 table exists.
|
||||||
|
await db.tableExists(oldTable);
|
||||||
|
|
||||||
|
// Move the records from the old table.
|
||||||
|
const sites = await db.getAllRecords(oldTable);
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
|
sites.forEach((site) => {
|
||||||
|
promises.push(db.insertRecord(newTable, site));
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
// Data moved, drop the old table.
|
||||||
|
await db.dropTable(oldTable);
|
||||||
|
} catch (error) {
|
||||||
|
// Old table does not exist, ignore.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Constants to validate a site version.
|
// Constants to validate a site version.
|
||||||
|
@ -260,7 +290,7 @@ export class CoreSitesProvider {
|
||||||
protected siteSchemas: { [name: string]: CoreSiteSchema } = {};
|
protected siteSchemas: { [name: string]: CoreSiteSchema } = {};
|
||||||
protected siteTablesSchemas: SQLiteDBTableSchema[] = [
|
protected siteTablesSchemas: SQLiteDBTableSchema[] = [
|
||||||
{
|
{
|
||||||
name: this.SCHEMA_VERSIONS_TABLE,
|
name: CoreSitesProvider.SCHEMA_VERSIONS_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
|
@ -607,16 +637,17 @@ export class CoreSitesProvider {
|
||||||
* @param token User's token.
|
* @param token User's token.
|
||||||
* @param privateToken User's private token.
|
* @param privateToken User's private token.
|
||||||
* @param login Whether to login the user in the site. Defaults to true.
|
* @param login Whether to login the user in the site. Defaults to true.
|
||||||
|
* @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
|
||||||
* @return A promise resolved with siteId when the site is added and the user is authenticated.
|
* @return A promise resolved with siteId when the site is added and the user is authenticated.
|
||||||
*/
|
*/
|
||||||
newSite(siteUrl: string, token: string, privateToken: string = '', login: boolean = true): Promise<string> {
|
newSite(siteUrl: string, token: string, privateToken: string = '', login: boolean = true, oauthId?: number): Promise<string> {
|
||||||
if (typeof login != 'boolean') {
|
if (typeof login != 'boolean') {
|
||||||
login = true;
|
login = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a "candidate" site to fetch the site info.
|
// Create a "candidate" site to fetch the site info.
|
||||||
let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken),
|
let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken, undefined, undefined);
|
||||||
isNewSite = true;
|
let isNewSite = true;
|
||||||
|
|
||||||
return candidateSite.fetchSiteInfo().then((info) => {
|
return candidateSite.fetchSiteInfo().then((info) => {
|
||||||
const result = this.isValidMoodleVersion(info);
|
const result = this.isValidMoodleVersion(info);
|
||||||
|
@ -634,12 +665,14 @@ export class CoreSitesProvider {
|
||||||
candidateSite.setToken(token);
|
candidateSite.setToken(token);
|
||||||
candidateSite.setPrivateToken(privateToken);
|
candidateSite.setPrivateToken(privateToken);
|
||||||
candidateSite.setInfo(info);
|
candidateSite.setInfo(info);
|
||||||
|
candidateSite.setOAuthId(oauthId);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// New site, set site ID and info.
|
// New site, set site ID and info.
|
||||||
isNewSite = true;
|
isNewSite = true;
|
||||||
candidateSite.setId(siteId);
|
candidateSite.setId(siteId);
|
||||||
candidateSite.setInfo(info);
|
candidateSite.setInfo(info);
|
||||||
|
candidateSite.setOAuthId(oauthId);
|
||||||
|
|
||||||
// Create database tables before login and before any WS call.
|
// Create database tables before login and before any WS call.
|
||||||
return this.migrateSiteSchemas(candidateSite);
|
return this.migrateSiteSchemas(candidateSite);
|
||||||
|
@ -659,7 +692,7 @@ export class CoreSitesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add site to sites list.
|
// Add site to sites list.
|
||||||
this.addSite(siteId, siteUrl, token, info, privateToken, config);
|
this.addSite(siteId, siteUrl, token, info, privateToken, config, oauthId);
|
||||||
this.sites[siteId] = candidateSite;
|
this.sites[siteId] = candidateSite;
|
||||||
|
|
||||||
if (login) {
|
if (login) {
|
||||||
|
@ -864,9 +897,11 @@ export class CoreSitesProvider {
|
||||||
* @param info Site's info.
|
* @param info Site's info.
|
||||||
* @param privateToken User's private token.
|
* @param privateToken User's private token.
|
||||||
* @param config Site config (from tool_mobile_get_config).
|
* @param config Site config (from tool_mobile_get_config).
|
||||||
|
* @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
async addSite(id: string, siteUrl: string, token: string, info: any, privateToken: string = '', config?: any): Promise<any> {
|
async addSite(id: string, siteUrl: string, token: string, info: any, privateToken: string = '', config?: any,
|
||||||
|
oauthId?: number): Promise<any> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const entry = {
|
const entry = {
|
||||||
|
@ -876,10 +911,11 @@ export class CoreSitesProvider {
|
||||||
info: info ? JSON.stringify(info) : info,
|
info: info ? JSON.stringify(info) : info,
|
||||||
privateToken: privateToken,
|
privateToken: privateToken,
|
||||||
config: config ? JSON.stringify(config) : config,
|
config: config ? JSON.stringify(config) : config,
|
||||||
loggedOut: 0
|
loggedOut: 0,
|
||||||
|
oauthId: oauthId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.appDB.insertRecord(this.SITES_TABLE, entry);
|
return this.appDB.insertRecord(CoreSitesProvider.SITES_TABLE, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1096,7 +1132,7 @@ export class CoreSitesProvider {
|
||||||
delete this.sites[siteId];
|
delete this.sites[siteId];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.appDB.deleteRecords(this.SITES_TABLE, { id: siteId });
|
await this.appDB.deleteRecords(CoreSitesProvider.SITES_TABLE, { id: siteId });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// DB remove shouldn't fail, but we'll go ahead even if it does.
|
// DB remove shouldn't fail, but we'll go ahead even if it does.
|
||||||
}
|
}
|
||||||
|
@ -1115,7 +1151,7 @@ export class CoreSitesProvider {
|
||||||
async hasSites(): Promise<boolean> {
|
async hasSites(): Promise<boolean> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const count = await this.appDB.countRecords(this.SITES_TABLE);
|
const count = await this.appDB.countRecords(CoreSitesProvider.SITES_TABLE);
|
||||||
|
|
||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
|
@ -1141,7 +1177,7 @@ export class CoreSitesProvider {
|
||||||
return this.sites[siteId];
|
return this.sites[siteId];
|
||||||
} else {
|
} else {
|
||||||
// Retrieve and create the site.
|
// Retrieve and create the site.
|
||||||
const data = await this.appDB.getRecord(this.SITES_TABLE, { id: siteId });
|
const data = await this.appDB.getRecord(CoreSitesProvider.SITES_TABLE, { id: siteId });
|
||||||
|
|
||||||
return this.makeSiteFromSiteListEntry(data);
|
return this.makeSiteFromSiteListEntry(data);
|
||||||
}
|
}
|
||||||
|
@ -1164,6 +1200,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
site = this.sitesFactory.makeSite(entry.id, entry.siteUrl, entry.token,
|
site = this.sitesFactory.makeSite(entry.id, entry.siteUrl, entry.token,
|
||||||
info, entry.privateToken, config, entry.loggedOut == 1);
|
info, entry.privateToken, config, entry.loggedOut == 1);
|
||||||
|
site.setOAuthId(entry.oauthId);
|
||||||
|
|
||||||
return this.migrateSiteSchemas(site).then(() => {
|
return this.migrateSiteSchemas(site).then(() => {
|
||||||
// Set site after migrating schemas, or a call to getSite could get the site while tables are being created.
|
// Set site after migrating schemas, or a call to getSite could get the site while tables are being created.
|
||||||
|
@ -1222,20 +1259,20 @@ export class CoreSitesProvider {
|
||||||
async getSites(ids?: string[]): Promise<CoreSiteBasicInfo[]> {
|
async getSites(ids?: string[]): Promise<CoreSiteBasicInfo[]> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const sites = await this.appDB.getAllRecords(this.SITES_TABLE);
|
const sites = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
|
||||||
|
|
||||||
const formattedSites = [];
|
const formattedSites = [];
|
||||||
sites.forEach((site) => {
|
sites.forEach((site) => {
|
||||||
if (!ids || ids.indexOf(site.id) > -1) {
|
if (!ids || ids.indexOf(site.id) > -1) {
|
||||||
// Parse info.
|
// Parse info.
|
||||||
const siteInfo = site.info ? this.textUtils.parseJSON(site.info) : site.info,
|
const siteInfo = site.info ? this.textUtils.parseJSON(site.info) : site.info;
|
||||||
basicInfo: CoreSiteBasicInfo = {
|
const basicInfo: CoreSiteBasicInfo = {
|
||||||
id: site.id,
|
id: site.id,
|
||||||
siteUrl: site.siteUrl,
|
siteUrl: site.siteUrl,
|
||||||
fullName: siteInfo && siteInfo.fullname,
|
fullName: siteInfo && siteInfo.fullname,
|
||||||
siteName: CoreConfigConstants.sitename ? CoreConfigConstants.sitename : siteInfo && siteInfo.sitename,
|
siteName: CoreConfigConstants.sitename ? CoreConfigConstants.sitename : siteInfo && siteInfo.sitename,
|
||||||
avatar: siteInfo && siteInfo.userpictureurl,
|
avatar: siteInfo && siteInfo.userpictureurl,
|
||||||
siteHomeId: siteInfo && siteInfo.siteid || 1
|
siteHomeId: siteInfo && siteInfo.siteid || 1,
|
||||||
};
|
};
|
||||||
formattedSites.push(basicInfo);
|
formattedSites.push(basicInfo);
|
||||||
}
|
}
|
||||||
|
@ -1282,7 +1319,7 @@ export class CoreSitesProvider {
|
||||||
async getLoggedInSitesIds(): Promise<string[]> {
|
async getLoggedInSitesIds(): Promise<string[]> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const sites = await this.appDB.getRecords(this.SITES_TABLE, {loggedOut : 0});
|
const sites = await this.appDB.getRecords(CoreSitesProvider.SITES_TABLE, {loggedOut : 0});
|
||||||
|
|
||||||
return sites.map((site) => {
|
return sites.map((site) => {
|
||||||
return site.id;
|
return site.id;
|
||||||
|
@ -1297,7 +1334,7 @@ export class CoreSitesProvider {
|
||||||
async getSitesIds(): Promise<string[]> {
|
async getSitesIds(): Promise<string[]> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const sites = await this.appDB.getAllRecords(this.SITES_TABLE);
|
const sites = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
|
||||||
|
|
||||||
return sites.map((site) => {
|
return sites.map((site) => {
|
||||||
return site.id;
|
return site.id;
|
||||||
|
@ -1318,7 +1355,7 @@ export class CoreSitesProvider {
|
||||||
siteId: siteId
|
siteId: siteId
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.appDB.insertRecord(this.CURRENT_SITE_TABLE, entry);
|
await this.appDB.insertRecord(CoreSitesProvider.CURRENT_SITE_TABLE, entry);
|
||||||
|
|
||||||
this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {}, siteId);
|
this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {}, siteId);
|
||||||
}
|
}
|
||||||
|
@ -1344,7 +1381,7 @@ export class CoreSitesProvider {
|
||||||
promises.push(this.setSiteLoggedOut(siteId, true));
|
promises.push(this.setSiteLoggedOut(siteId, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, { id: 1 }));
|
promises.push(this.appDB.deleteRecords(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1369,7 +1406,7 @@ export class CoreSitesProvider {
|
||||||
this.sessionRestored = true;
|
this.sessionRestored = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const currentSite = await this.appDB.getRecord(this.CURRENT_SITE_TABLE, { id: 1 });
|
const currentSite = await this.appDB.getRecord(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 });
|
||||||
const siteId = currentSite.siteId;
|
const siteId = currentSite.siteId;
|
||||||
this.logger.debug(`Restore session in site ${siteId}`);
|
this.logger.debug(`Restore session in site ${siteId}`);
|
||||||
|
|
||||||
|
@ -1397,7 +1434,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
site.setLoggedOut(loggedOut);
|
site.setLoggedOut(loggedOut);
|
||||||
|
|
||||||
return this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
|
return this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1439,14 +1476,14 @@ export class CoreSitesProvider {
|
||||||
const newValues = {
|
const newValues = {
|
||||||
token: token,
|
token: token,
|
||||||
privateToken: privateToken,
|
privateToken: privateToken,
|
||||||
loggedOut: 0
|
loggedOut: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
site.token = token;
|
site.token = token;
|
||||||
site.privateToken = privateToken;
|
site.privateToken = privateToken;
|
||||||
site.setLoggedOut(false); // Token updated means the user authenticated again, not logged out anymore.
|
site.setLoggedOut(false); // Token updated means the user authenticated again, not logged out anymore.
|
||||||
|
|
||||||
return this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
|
return this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1482,7 +1519,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
const newValues: any = {
|
const newValues: any = {
|
||||||
info: JSON.stringify(info),
|
info: JSON.stringify(info),
|
||||||
loggedOut: site.isLoggedOut() ? 1 : 0
|
loggedOut: site.isLoggedOut() ? 1 : 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof config != 'undefined') {
|
if (typeof config != 'undefined') {
|
||||||
|
@ -1491,7 +1528,7 @@ export class CoreSitesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
|
await this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
|
||||||
} finally {
|
} finally {
|
||||||
this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, info, siteId);
|
this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, info, siteId);
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1587,7 @@ export class CoreSitesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const siteEntries = await this.appDB.getAllRecords(this.SITES_TABLE);
|
const siteEntries = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
|
||||||
const ids = [];
|
const ids = [];
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
|
@ -1583,7 +1620,7 @@ export class CoreSitesProvider {
|
||||||
async getStoredCurrentSiteId(): Promise<string> {
|
async getStoredCurrentSiteId(): Promise<string> {
|
||||||
await this.dbReady;
|
await this.dbReady;
|
||||||
|
|
||||||
const currentSite = await this.appDB.getRecord(this.CURRENT_SITE_TABLE, { id: 1 });
|
const currentSite = await this.appDB.getRecord(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 });
|
||||||
|
|
||||||
return currentSite.siteId;
|
return currentSite.siteId;
|
||||||
}
|
}
|
||||||
|
@ -1731,7 +1768,7 @@ export class CoreSitesProvider {
|
||||||
const db = site.getDb();
|
const db = site.getDb();
|
||||||
|
|
||||||
// Fetch installed versions of the schema.
|
// Fetch installed versions of the schema.
|
||||||
return db.getAllRecords(this.SCHEMA_VERSIONS_TABLE).then((records) => {
|
return db.getAllRecords(CoreSitesProvider.SCHEMA_VERSIONS_TABLE).then((records) => {
|
||||||
const versions = {};
|
const versions = {};
|
||||||
records.forEach((record) => {
|
records.forEach((record) => {
|
||||||
versions[record.name] = record.version;
|
versions[record.name] = record.version;
|
||||||
|
@ -1756,7 +1793,8 @@ export class CoreSitesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set installed version.
|
// Set installed version.
|
||||||
promise = promise.then(() => db.insertRecord(this.SCHEMA_VERSIONS_TABLE, {name, version: schema.version}));
|
promise = promise.then(() => db.insertRecord(CoreSitesProvider.SCHEMA_VERSIONS_TABLE,
|
||||||
|
{name, version: schema.version}));
|
||||||
|
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { CoreDomUtilsProvider } from './utils/dom';
|
||||||
import { CoreTextUtilsProvider } from './utils/text';
|
import { CoreTextUtilsProvider } from './utils/text';
|
||||||
import { CoreUrlUtilsProvider } from './utils/url';
|
import { CoreUrlUtilsProvider } from './utils/url';
|
||||||
import { CoreUtilsProvider } from './utils/utils';
|
import { CoreUtilsProvider } from './utils/utils';
|
||||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
import { CoreLoginHelperProvider, CoreLoginSSOData } from '@core/login/providers/helper';
|
||||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||||
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
|
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
|
||||||
|
@ -32,21 +32,7 @@ import { CoreConstants } from '@core/constants';
|
||||||
/**
|
/**
|
||||||
* All params that can be in a custom URL scheme.
|
* All params that can be in a custom URL scheme.
|
||||||
*/
|
*/
|
||||||
export interface CoreCustomURLSchemesParams {
|
export interface CoreCustomURLSchemesParams extends CoreLoginSSOData {
|
||||||
/**
|
|
||||||
* The site's URL.
|
|
||||||
*/
|
|
||||||
siteUrl: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User's token. If set, user will be authenticated.
|
|
||||||
*/
|
|
||||||
token?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User's private token.
|
|
||||||
*/
|
|
||||||
privateToken?: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Username.
|
* Username.
|
||||||
|
@ -57,16 +43,6 @@ export interface CoreCustomURLSchemesParams {
|
||||||
* URL to open once authenticated.
|
* URL to open once authenticated.
|
||||||
*/
|
*/
|
||||||
redirect?: any;
|
redirect?: any;
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the page to go once authenticated.
|
|
||||||
*/
|
|
||||||
pageName?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Params to pass to the page.
|
|
||||||
*/
|
|
||||||
pageParams?: any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -162,7 +138,8 @@ export class CoreCustomURLSchemesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise.then(() => {
|
return promise.then(() => {
|
||||||
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken);
|
return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken,
|
||||||
|
this.loginHelper.getOAuthIdFromParams(data.ssoUrlParams));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Token belongs to current site, no need to create it.
|
// Token belongs to current site, no need to create it.
|
||||||
|
|
Loading…
Reference in New Issue