Skip to content

Commit 06ceefa

Browse files
authored
Merge pull request #2249 from dpalou/MOBILE-2853
Mobile 2853
2 parents 84f5592 + 59620ff commit 06ceefa

File tree

14 files changed

+1010
-632
lines changed

14 files changed

+1010
-632
lines changed

src/classes/site.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ interface RequestQueueItem {
170170
/**
171171
* Class that represents a site (combination of site + user).
172172
* It will have all the site data and provide utility functions regarding a site.
173-
* To add tables to the site's database, please use CoreSitesProvider.createTablesFromSchema. This will make sure that
173+
* To add tables to the site's database, please use CoreSitesProvider.registerSiteSchema. This will make sure that
174174
* the tables are created in all the sites, not just the current one.
175175
*/
176176
export class CoreSite {
@@ -233,6 +233,7 @@ export class CoreSite {
233233
protected requestQueueTimeout = null;
234234
protected tokenPluginFileWorks: boolean;
235235
protected tokenPluginFileWorksPromise: Promise<boolean>;
236+
protected oauthId: number;
236237

237238
/**
238239
* Create a site.
@@ -404,6 +405,15 @@ export class CoreSite {
404405
return !!this.loggedOut;
405406
}
406407

408+
/**
409+
* Get OAuth ID.
410+
*
411+
* @return OAuth ID.
412+
*/
413+
getOAuthId(): number {
414+
return this.oauthId;
415+
}
416+
407417
/**
408418
* Set site info.
409419
*
@@ -444,6 +454,24 @@ export class CoreSite {
444454
this.loggedOut = !!loggedOut;
445455
}
446456

457+
/**
458+
* Set OAuth ID.
459+
*
460+
* @param oauth OAuth ID.
461+
*/
462+
setOAuthId(oauthId: number): void {
463+
this.oauthId = oauthId;
464+
}
465+
466+
/**
467+
* Check if the user authenticated in the site using an OAuth method.
468+
*
469+
* @return {boolean} Whether the user authenticated in the site using an OAuth method.
470+
*/
471+
isOAuth(): boolean {
472+
return this.oauthId != null && typeof this.oauthId != 'undefined';
473+
}
474+
447475
/**
448476
* Can the user access their private files?
449477
*

src/core/emulator/providers/local-notifications.ts

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

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

4444
// Variables for database.
4545
protected DESKTOP_NOTIFS_TABLE = 'desktop_local_notifications';
46-
protected tableSchema: SQLiteDBTableSchema = {
47-
name: this.DESKTOP_NOTIFS_TABLE,
48-
columns: [
46+
protected tableSchema: CoreAppSchema = {
47+
name: 'LocalNotificationsMock',
48+
version: 1,
49+
tables: [
4950
{
50-
name: 'id',
51-
type: 'INTEGER',
52-
primaryKey: true
53-
},
54-
{
55-
name: 'title',
56-
type: 'TEXT'
57-
},
58-
{
59-
name: 'text',
60-
type: 'TEXT'
61-
},
62-
{
63-
name: 'at',
64-
type: 'INTEGER'
65-
},
66-
{
67-
name: 'data',
68-
type: 'TEXT'
51+
name: this.DESKTOP_NOTIFS_TABLE,
52+
columns: [
53+
{
54+
name: 'id',
55+
type: 'INTEGER',
56+
primaryKey: true
57+
},
58+
{
59+
name: 'title',
60+
type: 'TEXT'
61+
},
62+
{
63+
name: 'text',
64+
type: 'TEXT'
65+
},
66+
{
67+
name: 'at',
68+
type: 'INTEGER'
69+
},
70+
{
71+
name: 'data',
72+
type: 'TEXT'
73+
},
74+
{
75+
name: 'triggered',
76+
type: 'INTEGER'
77+
}
78+
],
6979
},
70-
{
71-
name: 'triggered',
72-
type: 'INTEGER'
73-
}
74-
]
80+
],
7581
};
7682

7783
protected appDB: SQLiteDB;
7884
protected scheduled: { [i: number]: any } = {};
7985
protected triggered: { [i: number]: any } = {};
8086
protected observers: {[event: string]: Subject<any>};
87+
protected dbReady: Promise<any>; // Promise resolved when the app DB is initialized.
8188
protected defaults = {
8289
actions : [],
8390
attachments : [],
@@ -117,7 +124,9 @@ export class LocalNotificationsMock extends LocalNotifications {
117124
super();
118125

119126
this.appDB = appProvider.getDB();
120-
this.appDB.createTableFromSchema(this.tableSchema);
127+
this.dbReady = appProvider.createTablesFromSchema(this.tableSchema).catch(() => {
128+
// Ignore errors.
129+
});
121130

122131
// Initialize observers.
123132
this.observers = {
@@ -550,20 +559,21 @@ export class LocalNotificationsMock extends LocalNotifications {
550559
*
551560
* @return Promise resolved with the notifications.
552561
*/
553-
protected getAllNotifications(): Promise<any> {
554-
return this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE).then((notifications) => {
555-
notifications.forEach((notification) => {
556-
notification.trigger = {
557-
at: new Date(notification.at)
558-
};
559-
notification.data = this.textUtils.parseJSON(notification.data);
560-
notification.triggered = !!notification.triggered;
562+
protected async getAllNotifications(): Promise<any> {
563+
await this.dbReady;
561564

562-
this.mergeWithDefaults(notification);
563-
});
565+
const notifications = await this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE);
566+
notifications.forEach((notification) => {
567+
notification.trigger = {
568+
at: new Date(notification.at),
569+
};
570+
notification.data = this.textUtils.parseJSON(notification.data);
571+
notification.triggered = !!notification.triggered;
564572

565-
return notifications;
573+
this.mergeWithDefaults(notification);
566574
});
575+
576+
return notifications;
567577
}
568578

569579
/**
@@ -889,7 +899,9 @@ export class LocalNotificationsMock extends LocalNotifications {
889899
* @param id ID of the notification.
890900
* @return Promise resolved when done.
891901
*/
892-
protected removeNotification(id: number): Promise<any> {
902+
protected async removeNotification(id: number): Promise<any> {
903+
await this.dbReady;
904+
893905
return this.appDB.deleteRecords(this.DESKTOP_NOTIFS_TABLE, { id: id });
894906
}
895907

@@ -979,7 +991,9 @@ export class LocalNotificationsMock extends LocalNotifications {
979991
* @param triggered Whether the notification has been triggered.
980992
* @return Promise resolved when stored.
981993
*/
982-
protected storeNotification(notification: ILocalNotification, triggered: boolean): Promise<any> {
994+
protected async storeNotification(notification: ILocalNotification, triggered: boolean): Promise<any> {
995+
await this.dbReady;
996+
983997
// Only store some of the properties.
984998
const entry = {
985999
id : notification.id,

src/core/login/pages/reconnect/reconnect.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<ion-icon padding name="alert"></ion-icon> {{ 'core.login.reconnectdescription' | translate }}
3030
</p>
3131
</div>
32-
<form ion-list [formGroup]="credForm" (ngSubmit)="login($event)" class="core-login-form">
32+
<form ion-list *ngIf="!isOAuth" [formGroup]="credForm" (ngSubmit)="login($event)" class="core-login-form">
3333
<ion-item text-wrap class="core-username">
3434
<p>{{username}}</p>
3535
</ion-item>
@@ -51,7 +51,7 @@
5151
</form>
5252

5353
<!-- Forgotten password button. -->
54-
<div *ngIf="showForgottenPassword" padding-top class="core-login-forgotten-password">
54+
<div *ngIf="showForgottenPassword && !isOAuth" padding-top class="core-login-forgotten-password">
5555
<button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button>
5656
</div>
5757

@@ -63,5 +63,12 @@
6363
{{provider.name}}
6464
</button>
6565
</ion-list>
66+
67+
<!-- If OAuth, display cancel button since the form isn't displayed. -->
68+
<ion-list *ngIf="isOAuth">
69+
<ion-item>
70+
<a ion-button block color="light" (click)="cancel($event)">{{ 'core.login.cancel' | translate }}</a>
71+
</ion-item>
72+
</ion-list>
6673
</div>
6774
</ion-content>

src/core/login/pages/reconnect/reconnect.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class CoreLoginReconnectPage {
3838
site: any;
3939
showForgottenPassword = true;
4040
showSiteAvatar = false;
41+
isOAuth = false;
4142

4243
protected infoSiteUrl: string;
4344
protected pageName: string;
@@ -88,6 +89,9 @@ export class CoreLoginReconnectPage {
8889
this.siteUrl = site.infos.siteurl;
8990
this.siteName = site.getSiteName();
9091

92+
// If login was OAuth we should only reach this page if the OAuth method ID has changed.
93+
this.isOAuth = site.isOAuth();
94+
9195
// Show logo instead of avatar if it's a fixed site.
9296
this.showSiteAvatar = this.site.avatar && !this.loginHelper.getFixedSites();
9397

0 commit comments

Comments
 (0)