Matrix integration
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { ChatService } from './services/chat.service';
|
||||
|
||||
@Component({
|
||||
// tslint:disable-next-line:component-selector
|
||||
@@ -11,11 +12,17 @@ export class AppComponent implements OnInit {
|
||||
showOverlay = true;
|
||||
|
||||
constructor(
|
||||
private authService: AuthService
|
||||
private authService: AuthService,
|
||||
private chatService: ChatService
|
||||
) { }
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.authService.isLogged;
|
||||
console.log('AppComponent.ngInit()');
|
||||
const isLogged = await this.authService.isLogged;
|
||||
this.showOverlay = false;
|
||||
if (isLogged) {
|
||||
console.log('GO TO SSO LOGIN');
|
||||
this.chatService.goToSsoLogin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export class EditTravelComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.subscribe(params => {
|
||||
const travelId = this.route.snapshot.paramMap.get('id') as unknown as TravelId;
|
||||
const travelId = params.get('id') as unknown as TravelId;
|
||||
|
||||
this.apiService.getTravel(travelId)
|
||||
.subscribe(res => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { Travel } from '../../entities/travel';
|
||||
import { ApiService } from '../../services/api.service';
|
||||
|
||||
@@ -29,11 +30,16 @@ export class HomeComponent implements OnInit {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
private apiService: ApiService
|
||||
private apiService: ApiService,
|
||||
private chatService: ChatService
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
const loginToken = this.route.snapshot.queryParams['loginToken'];
|
||||
if (loginToken) {
|
||||
console.log('loginToken=' + this.route.snapshot.queryParams['loginToken']);
|
||||
this.chatService.login(loginToken);
|
||||
}
|
||||
}
|
||||
|
||||
newTravel(): void {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError, retry } from 'rxjs/operators';
|
||||
import { ApiResponse } from '../entities/api-response';
|
||||
import { Travel, TravelId } from '../entities/travel';
|
||||
import { PUBLIC_API_URL, TRAVEL_API_URL, USER_API_URL } from '../app.config';
|
||||
import { ApiResponse } from '../entities/api-response';
|
||||
import { ListDto } from '../entities/list-dto';
|
||||
import { Travel, TravelId } from '../entities/travel';
|
||||
import { User } from '../entities/user';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
export type ApiCall<T> = (params?: { [param: string]: any }) => (Observable<ApiResponse<ListDto<T>>>);
|
||||
|
||||
@@ -16,7 +15,6 @@ export type ApiCall<T> = (params?: { [param: string]: any }) => (Observable<ApiR
|
||||
})
|
||||
export class ApiService {
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private http: HttpClient
|
||||
) { }
|
||||
|
||||
@@ -80,27 +78,6 @@ export class ApiService {
|
||||
);
|
||||
}
|
||||
|
||||
// private callProtectedApi<T>(
|
||||
// url: string,
|
||||
// params?: { [param: string]: any },
|
||||
// body?: any
|
||||
// ): Observable<ApiResponse<T>> {
|
||||
// const observable = new Observable<ApiResponse<T>>(observer => {
|
||||
// this.authService.configurePromise.then(logged => {
|
||||
// if (logged) {
|
||||
// this.callApi<T>(url, params, body).subscribe(res => {
|
||||
// observer.next(res);
|
||||
// });
|
||||
// }
|
||||
// else {
|
||||
// console.error('callProtectedApi: NOT LOGGED');
|
||||
// observer.error('NOT LOGGED');
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// return observable;
|
||||
// }
|
||||
|
||||
private handleError(error: HttpErrorResponse): Observable<never> {
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
// A client-side or network error occurred. Handle it accordingly.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { OAuthService } from 'angular-oauth2-oidc';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { authConfig } from '../auth.config';
|
||||
import { Travel } from '../entities/travel';
|
||||
import { User } from '../entities/user';
|
||||
|
||||
@Injectable({
|
||||
@@ -38,9 +38,19 @@ export class AuthService {
|
||||
this.oauthService.configure(authConfig);
|
||||
this.oauthService.setupAutomaticSilentRefresh();
|
||||
|
||||
|
||||
// Automatically load user profile
|
||||
this.oauthService.events
|
||||
.pipe(filter((e) => e.type === 'token_received'))
|
||||
.subscribe((_) => {
|
||||
console.log('auth.service token_received state=', this.oauthService.state);
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => {
|
||||
if (this.oauthService.getIdentityClaims() != null) {
|
||||
console.log('IDENTITY CLAIMS');
|
||||
console.log(this.oauthService.getIdentityClaims());
|
||||
if (this.oauthService.hasValidIdToken() && this.oauthService.hasValidAccessToken()) {
|
||||
console.log('NO NEED FOR TOKEN REFRESH');
|
||||
resolve(true);
|
||||
@@ -62,18 +72,5 @@ export class AuthService {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Automatically load user profile
|
||||
// this.oauthService.events
|
||||
// .pipe(filter((e) => e.type === 'token_received'))
|
||||
// .subscribe((_) => {
|
||||
// console.log('state', this.oauthService.state);
|
||||
// this.oauthService.loadUserProfile();
|
||||
|
||||
// this.apiService.getUser().subscribe(user => {
|
||||
// console.log('USER');
|
||||
// console.log(user);
|
||||
// });
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
31
src/app/services/chat.service.ts
Normal file
31
src/app/services/chat.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
// import sdk from 'matrix-js-sdk';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatService {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private http: HttpClient
|
||||
) { }
|
||||
|
||||
goToSsoLogin(): void {
|
||||
// window.location.href = 'https://matrix.fosil.eu/_matrix/client/r0/login/sso/redirect?redirectUrl=http://localhost:4200/';
|
||||
}
|
||||
|
||||
login(loginToken: string): Promise<void | object> {
|
||||
return this.http.post(
|
||||
'https://matrix.fosil.eu/_matrix/client/r0/login',
|
||||
{
|
||||
initial_device_display_name: 'Okupa mi coche',
|
||||
token: loginToken,
|
||||
type: 'm.login.token'
|
||||
}
|
||||
).toPromise().then(res => {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<label for="places">Plazas</label>
|
||||
<input type="number" id="places" required [(ngModel)]="travel.places" name="places">
|
||||
<div hidden="places.valid || places.pristine" class="alert alert-danger">
|
||||
El destino es obligatorio
|
||||
El número de plazas disponibles es obligatorio
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user