| @@ -20,6 +20,7 @@ import { HttpClientModule } from '@angular/common/http'; | |||||
| import { NewsService } from './services/news.service'; | import { NewsService } from './services/news.service'; | ||||
| import { MatchService } from './services/match.service'; | import { MatchService } from './services/match.service'; | ||||
| import { ToastService } from './services/toast.service'; | import { ToastService } from './services/toast.service'; | ||||
| import { UserService } from './services/user.service'; | |||||
| @NgModule({ | @NgModule({ | ||||
| declarations: [AppComponent], | declarations: [AppComponent], | ||||
| @@ -37,6 +38,7 @@ import { ToastService } from './services/toast.service'; | |||||
| AppVersion, | AppVersion, | ||||
| NewsService, | NewsService, | ||||
| MatchService, | MatchService, | ||||
| UserService, | |||||
| ToastService, | ToastService, | ||||
| HTTP, | HTTP, | ||||
| { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, | ||||
| @@ -4,6 +4,8 @@ | |||||
| <button (click)="login()"> Login with <ion-icon name="logo-facebook"></ion-icon> </button> | <button (click)="login()"> Login with <ion-icon name="logo-facebook"></ion-icon> </button> | ||||
| </section> | </section> | ||||
| </section> | </section> | ||||
| <input type="text" *ngIf="token" [(ngModel)]="token.token"> | |||||
| <section class="social-login" [ngClass]="{'active' : showLogout && user }"> | <section class="social-login" [ngClass]="{'active' : showLogout && user }"> | ||||
| @@ -1,4 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { UserService } from '../../services/user.service'; | |||||
| // For capacitor Facebook | // For capacitor Facebook | ||||
| import { Platform } from '@ionic/angular'; | import { Platform } from '@ionic/angular'; | ||||
| @@ -26,7 +27,8 @@ export class FacebookLoginComponent implements OnInit { | |||||
| constructor( | constructor( | ||||
| private platform: Platform, | private platform: Platform, | ||||
| private http: HttpClient | |||||
| private http: HttpClient, | |||||
| private userService: UserService | |||||
| ) { | ) { | ||||
| } | } | ||||
| @@ -81,7 +83,11 @@ export class FacebookLoginComponent implements OnInit { | |||||
| this.token = result.accessToken; | this.token = result.accessToken; | ||||
| this.loadUserData(); | this.loadUserData(); | ||||
| localStorage.setItem('FBToken', this.token); | |||||
| localStorage.setItem('FBToken', JSON.stringify(this.token)); | |||||
| this.userService.getUserProfile().then((data) => alert(JSON.stringify(data)), err => alert(JSON.stringify(err))); | |||||
| } else { | } else { | ||||
| // Not logged in. | // Not logged in. | ||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import { ToastService } from '../services/toast.service'; | |||||
| import { DomSanitizer } from '@angular/platform-browser'; | import { DomSanitizer } from '@angular/platform-browser'; | ||||
| import { SocialSharing } from '@ionic-native/social-sharing/ngx'; | import { SocialSharing } from '@ionic-native/social-sharing/ngx'; | ||||
| import { Platform } from '@ionic/angular'; | import { Platform } from '@ionic/angular'; | ||||
| import { UserService } from '../services/user.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-home', | selector: 'app-home', | ||||
| @@ -43,6 +44,7 @@ export class HomePage implements OnInit { | |||||
| private dom: DomSanitizer, | private dom: DomSanitizer, | ||||
| private socialSharing: SocialSharing, | private socialSharing: SocialSharing, | ||||
| private platform: Platform, | private platform: Platform, | ||||
| private userService: UserService | |||||
| ) { } | ) { } | ||||
| transformYourHtml(htmlTextWithStyle) { | transformYourHtml(htmlTextWithStyle) { | ||||
| @@ -0,0 +1,16 @@ | |||||
| import { TestBed } from '@angular/core/testing'; | |||||
| import { UserService } from './user.service'; | |||||
| describe('UserService', () => { | |||||
| let service: UserService; | |||||
| beforeEach(() => { | |||||
| TestBed.configureTestingModule({}); | |||||
| service = TestBed.inject(UserService); | |||||
| }); | |||||
| it('should be created', () => { | |||||
| expect(service).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,41 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |||||
| @Injectable({ | |||||
| providedIn: 'root' | |||||
| }) | |||||
| export class UserService { | |||||
| BASE_URL: string = 'https://fan-engagement.techmahindra.com'; | |||||
| // /like-article/:id | |||||
| // /bookmark-article/:id | |||||
| constructor( | |||||
| private http: HttpClient | |||||
| ) { } | |||||
| likePost(postId: string) { | |||||
| const httpOptions = { | |||||
| headers: new HttpHeaders({ | |||||
| 'Access-Control-Allow-Origin': '*', | |||||
| 'Content-Type': 'application/json', | |||||
| 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token | |||||
| }) | |||||
| }; | |||||
| return this.http.get(this.BASE_URL + '/like-article/' + postId, httpOptions).toPromise(); | |||||
| } | |||||
| getUserProfile() { | |||||
| const httpOptions = { | |||||
| headers: new HttpHeaders({ | |||||
| 'Access-Control-Allow-Origin': '*', | |||||
| 'Content-Type': 'application/json', | |||||
| 'Authorization': 'Bearer ' + JSON.parse(localStorage.getItem('FBToken')).token | |||||
| }) | |||||
| }; | |||||
| return this.http.get(this.BASE_URL + '/user-details/', httpOptions).toPromise(); | |||||
| } | |||||
| } | |||||