Fix issue with users signing up and not subscribing to push notifications.
This commit is contained in:
Родитель
daef8d24bf
Коммит
e4b0012433
|
@ -3,7 +3,7 @@ import { NavigationEnd, NavigationStart } from '@angular/router';
|
|||
import { RouterExtensions } from 'nativescript-angular/router';
|
||||
import { Page } from 'ui/page';
|
||||
import { utilities } from './shared';
|
||||
import { FilesService } from './services';
|
||||
import { FilesService, UsersService, PushNotificationsService } from './services';
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
|
@ -16,6 +16,8 @@ export class AppComponent implements OnInit {
|
|||
constructor(
|
||||
private _page: Page,
|
||||
private _filesService: FilesService,
|
||||
private _usersService: UsersService,
|
||||
private _push: PushNotificationsService,
|
||||
private _routerExtensions: RouterExtensions
|
||||
) {}
|
||||
|
||||
|
@ -30,5 +32,10 @@ export class AppComponent implements OnInit {
|
|||
});
|
||||
this._filesService.emptyAppTempFolder();
|
||||
// .catch(err => console.log('err while emptying: ' + JSON.stringify(err)));
|
||||
this._usersService.currentUser().then(user => {
|
||||
if (user) {
|
||||
this._push.subscribe().catch(err => err); // ignore errors
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export class PushNotificationsService {
|
|||
// this._alertsService.showSuccess('got push' + JSON.stringify(args));
|
||||
}
|
||||
|
||||
subscribe(userId: string) {
|
||||
subscribe() {
|
||||
let pushRegSettings = {
|
||||
iOS: { badge: true, sound: true, alert: true },
|
||||
android: { senderID: constants.androidProjNumber },
|
||||
|
|
|
@ -46,11 +46,7 @@ export class LoginComponent implements OnInit {
|
|||
}
|
||||
|
||||
login() {
|
||||
this._usersService.login(this.user.Username, this.user.Password)
|
||||
.then((loginResult) => {
|
||||
this._push.subscribe(loginResult.result.principal_id).catch(err => err);
|
||||
this._goToEvents();
|
||||
})
|
||||
this._logInUser(this.user.Username, this.user.Password)
|
||||
.catch((e) => {
|
||||
this._alertsService.showError(e && e.message);
|
||||
});
|
||||
|
@ -65,17 +61,11 @@ export class LoginComponent implements OnInit {
|
|||
if (errMsg) {
|
||||
return this._alertsService.showError(errMsg);
|
||||
}
|
||||
let registeredUserId: string;
|
||||
|
||||
this._usersService.register(this.user.Username, this.user.Password, this.user.DisplayName)
|
||||
.then((res) => {
|
||||
this._alertsService.showSuccess('Welcome to TeamUP!');
|
||||
registeredUserId = res.result.Id;
|
||||
return this._usersService.login(this.user.Username, this.user.Password);
|
||||
})
|
||||
.then(() => {
|
||||
this._push.subscribe(registeredUserId).catch(err => err);
|
||||
this._goToEvents();
|
||||
return this._logInUser(this.user.Username, this.user.Password);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err) {
|
||||
|
@ -106,4 +96,12 @@ export class LoginComponent implements OnInit {
|
|||
let transition = utilities.getPageTransition();
|
||||
this._routerExtensions.navigate(['events'], { clearHistory: true, transition });
|
||||
}
|
||||
|
||||
private _logInUser(username: string, password: string) {
|
||||
return this._usersService.login(this.user.Username, this.user.Password)
|
||||
.then(() => {
|
||||
this._push.subscribe().catch(e => e); // ignore errors
|
||||
this._goToEvents();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче