Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/classes/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ interface RequestQueueItem {
/**
* Class that represents a site (combination of site + user).
* It will have all the site data and provide utility functions regarding a site.
* To add tables to the site's database, please use CoreSitesProvider.createTablesFromSchema. This will make sure that
* To add tables to the site's database, please use CoreSitesProvider.registerSiteSchema. This will make sure that
* the tables are created in all the sites, not just the current one.
*/
export class CoreSite {
Expand Down Expand Up @@ -233,6 +233,7 @@ export class CoreSite {
protected requestQueueTimeout = null;
protected tokenPluginFileWorks: boolean;
protected tokenPluginFileWorksPromise: Promise<boolean>;
protected oauthId: number;

/**
* Create a site.
Expand Down Expand Up @@ -404,6 +405,15 @@ export class CoreSite {
return !!this.loggedOut;
}

/**
* Get OAuth ID.
*
* @return OAuth ID.
*/
getOAuthId(): number {
return this.oauthId;
}

/**
* Set site info.
*
Expand Down Expand Up @@ -444,6 +454,24 @@ export class CoreSite {
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?
*
Expand Down
100 changes: 57 additions & 43 deletions src/core/emulator/providers/local-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import { Injectable } from '@angular/core';
import { LocalNotifications, ILocalNotification, ILocalNotificationAction } from '@ionic-native/local-notifications';
import { CoreAppProvider } from '@providers/app';
import { CoreAppProvider, CoreAppSchema } from '@providers/app';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
import { SQLiteDB } from '@classes/sqlitedb';
import { CoreConstants } from '@core/constants';
import { CoreConfigConstants } from '../../../configconstants';
import * as moment from 'moment';
Expand All @@ -43,41 +43,48 @@ export class LocalNotificationsMock extends LocalNotifications {

// Variables for database.
protected DESKTOP_NOTIFS_TABLE = 'desktop_local_notifications';
protected tableSchema: SQLiteDBTableSchema = {
name: this.DESKTOP_NOTIFS_TABLE,
columns: [
protected tableSchema: CoreAppSchema = {
name: 'LocalNotificationsMock',
version: 1,
tables: [
{
name: 'id',
type: 'INTEGER',
primaryKey: true
},
{
name: 'title',
type: 'TEXT'
},
{
name: 'text',
type: 'TEXT'
},
{
name: 'at',
type: 'INTEGER'
},
{
name: 'data',
type: 'TEXT'
name: this.DESKTOP_NOTIFS_TABLE,
columns: [
{
name: 'id',
type: 'INTEGER',
primaryKey: true
},
{
name: 'title',
type: 'TEXT'
},
{
name: 'text',
type: 'TEXT'
},
{
name: 'at',
type: 'INTEGER'
},
{
name: 'data',
type: 'TEXT'
},
{
name: 'triggered',
type: 'INTEGER'
}
],
},
{
name: 'triggered',
type: 'INTEGER'
}
]
],
};

protected appDB: SQLiteDB;
protected scheduled: { [i: number]: any } = {};
protected triggered: { [i: number]: any } = {};
protected observers: {[event: string]: Subject<any>};
protected dbReady: Promise<any>; // Promise resolved when the app DB is initialized.
protected defaults = {
actions : [],
attachments : [],
Expand Down Expand Up @@ -117,7 +124,9 @@ export class LocalNotificationsMock extends LocalNotifications {
super();

this.appDB = appProvider.getDB();
this.appDB.createTableFromSchema(this.tableSchema);
this.dbReady = appProvider.createTablesFromSchema(this.tableSchema).catch(() => {
// Ignore errors.
});

// Initialize observers.
this.observers = {
Expand Down Expand Up @@ -550,20 +559,21 @@ export class LocalNotificationsMock extends LocalNotifications {
*
* @return Promise resolved with the notifications.
*/
protected getAllNotifications(): Promise<any> {
return this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE).then((notifications) => {
notifications.forEach((notification) => {
notification.trigger = {
at: new Date(notification.at)
};
notification.data = this.textUtils.parseJSON(notification.data);
notification.triggered = !!notification.triggered;
protected async getAllNotifications(): Promise<any> {
await this.dbReady;

this.mergeWithDefaults(notification);
});
const notifications = await this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE);
notifications.forEach((notification) => {
notification.trigger = {
at: new Date(notification.at),
};
notification.data = this.textUtils.parseJSON(notification.data);
notification.triggered = !!notification.triggered;

return notifications;
this.mergeWithDefaults(notification);
});

return notifications;
}

/**
Expand Down Expand Up @@ -889,7 +899,9 @@ export class LocalNotificationsMock extends LocalNotifications {
* @param id ID of the notification.
* @return Promise resolved when done.
*/
protected removeNotification(id: number): Promise<any> {
protected async removeNotification(id: number): Promise<any> {
await this.dbReady;

return this.appDB.deleteRecords(this.DESKTOP_NOTIFS_TABLE, { id: id });
}

Expand Down Expand Up @@ -979,7 +991,9 @@ export class LocalNotificationsMock extends LocalNotifications {
* @param triggered Whether the notification has been triggered.
* @return Promise resolved when stored.
*/
protected storeNotification(notification: ILocalNotification, triggered: boolean): Promise<any> {
protected async storeNotification(notification: ILocalNotification, triggered: boolean): Promise<any> {
await this.dbReady;

// Only store some of the properties.
const entry = {
id : notification.id,
Expand Down
11 changes: 9 additions & 2 deletions src/core/login/pages/reconnect/reconnect.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<ion-icon padding name="alert"></ion-icon> {{ 'core.login.reconnectdescription' | translate }}
</p>
</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">
<p>{{username}}</p>
</ion-item>
Expand All @@ -51,7 +51,7 @@
</form>

<!-- 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>
</div>

Expand All @@ -63,5 +63,12 @@
{{provider.name}}
</button>
</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>
</ion-content>
4 changes: 4 additions & 0 deletions src/core/login/pages/reconnect/reconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class CoreLoginReconnectPage {
site: any;
showForgottenPassword = true;
showSiteAvatar = false;
isOAuth = false;

protected infoSiteUrl: string;
protected pageName: string;
Expand Down Expand Up @@ -88,6 +89,9 @@ export class CoreLoginReconnectPage {
this.siteUrl = site.infos.siteurl;
this.siteName = site.getSiteName();

// If login was OAuth we should only reach this page if the OAuth method ID has changed.
this.isOAuth = site.isOAuth();

// Show logo instead of avatar if it's a fixed site.
this.showSiteAvatar = this.site.avatar && !this.loginHelper.getFixedSites();

Expand Down
Loading