mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
Save device token on middleware
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
export class Token {
|
||||
UserId: number;
|
||||
TokenId: string;
|
||||
Status: number;
|
||||
Service: number
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import { AlertController } from '@ionic/angular';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { PhotoService } from 'src/app/services/photo.service';
|
||||
import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Token } from '../../models/token.model';
|
||||
|
||||
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core';
|
||||
|
||||
@@ -28,6 +31,8 @@ export class LoginPage implements OnInit {
|
||||
userattempt: User;
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private notificatinsservice: NotificationsService,
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
private storageService: StorageService,
|
||||
@@ -57,21 +62,21 @@ export class LoginPage implements OnInit {
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
loginRocketChat(user:any){
|
||||
|
||||
loginRocketChat(user: any) {
|
||||
|
||||
let postData = {
|
||||
"user": user.username,
|
||||
"password": user.password,
|
||||
}
|
||||
this.authService.loginChat(postData).subscribe((res: any) =>{
|
||||
this.authService.loginChat(postData).subscribe((res: any) => {
|
||||
console.log(res.data);
|
||||
this.storageService.store(AuthConnstants.AUTH, res.data);
|
||||
console.log('Login to Rocket chat OK');
|
||||
},(error:any) =>{
|
||||
}, (error: any) => {
|
||||
console.log('Network error');
|
||||
this.presentAlert('Network error '+error);
|
||||
this.presentAlert('Network error ' + error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
storeUserIdANdToken() {
|
||||
|
||||
@@ -85,14 +90,26 @@ export class LoginPage implements OnInit {
|
||||
console.log('FIREBASE TOKEN', token.value)
|
||||
this.storageService.store(this.username, token.value);
|
||||
this.storageService.get(this.username).then(value => {
|
||||
console.log('STORAGE TOKEN',value )
|
||||
this.storageService.get(AuthConnstants.USER).then(res=>{
|
||||
console.log('USERID',res);
|
||||
|
||||
console.log('STORAGE TOKEN', value)
|
||||
this.storageService.get(AuthConnstants.USER).then(res => {
|
||||
console.log('USERID', res);
|
||||
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
|
||||
const body = { UserId: 261,
|
||||
TokenId: "cSLzVzMzRCKZvGjlSzVM66:APA91bFTDlINnZ8NFvNQ-E9787DrWVnXIYOwuptpTVuV950i_pkqZoiN-mAMC4MNXZAe5IWy0OaLp4h2ALrtuugl-wQ57Wp8H9JApW_YUpilN93PfHAc2BXVFbOtn7ac4kLkWwTQei4d",
|
||||
Status: 1,
|
||||
Service: 2 };
|
||||
|
||||
this.http.post<Token>('https://equilibrium.dyndns.info/GabineteDigital.Services/V4/api/notifications/token', body,{headers}).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
})
|
||||
/*this.http.get<Token>('http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V4/api/notifications/user/'+res).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE',data);
|
||||
})*/
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
);
|
||||
|
||||
@@ -113,7 +130,7 @@ export class LoginPage implements OnInit {
|
||||
if (await this.authService.login(this.userattempt)) {
|
||||
/* this.loginRocketChat(); */
|
||||
this.storeUserIdANdToken()
|
||||
|
||||
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationsService } from './notifications.service';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
let service: NotificationsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NotificationsService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Token } from '../models/token.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotificationsService {
|
||||
|
||||
constructor(private http: HttpClient,) { }
|
||||
|
||||
getTokenByUserIdAndId(user, userID) {
|
||||
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
|
||||
return this.http.get<Token[]>(`${geturl}`);
|
||||
}
|
||||
|
||||
postToken(userId, token) {
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
|
||||
let data = {
|
||||
UserId: userId,
|
||||
TokenId: token,
|
||||
Status: 1,
|
||||
Service: 2
|
||||
}
|
||||
return this.http.post<Token[]>(`${geturl}`,data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user