@@ -5,7 +5,7 @@ import { Component, EventEmitter, Output, AfterViewInit } from '@angular/core';
55import { AlertService } from '../../services/alert.service' ;
66import { ClaContributorService } from 'src/app/core/services/cla-contributor.service' ;
77import { ProjectModel } from 'src/app/core/models/project' ;
8- import { UserModel } from 'src/app/core/models/user' ;
8+ import { UserModel , UserFromTokenModel } from 'src/app/core/models/user' ;
99import { StorageService } from '../../services/storage.service' ;
1010import { AppSettings } from 'src/app/config/app-settings' ;
1111
@@ -20,6 +20,7 @@ export class ProjectTitleComponent implements AfterViewInit {
2020
2121 project = new ProjectModel ( ) ;
2222 user = new UserModel ( ) ;
23+ userFromToken = new UserFromTokenModel ( ) ;
2324
2425 constructor (
2526 private alertService : AlertService ,
@@ -64,6 +65,21 @@ export class ProjectTitleComponent implements AfterViewInit {
6465 }
6566 }
6667
68+ getUserFromToken ( ) {
69+ this . claContributorService . getUserFromToken ( ) . subscribe (
70+ ( response ) => {
71+ this . userFromToken = response ;
72+ this . storageService . setItem ( AppSettings . USER_ID , this . userFromToken . userID ) ;
73+ // If we need to store all details in USER then add a helper method to
74+ // copy data from UserFromTokenModel to UserModel
75+ // this.storageService.setItem(AppSettings.USER, convertToUserModel(this.userFromToken));
76+ } ,
77+ ( exception ) => {
78+ this . errorEmitter . emit ( true ) ;
79+ this . claContributorService . handleError ( exception ) ;
80+ }
81+ ) ;
82+ }
6783
6884 getUser ( ) {
6985 const userId = JSON . parse ( this . storageService . getItem ( AppSettings . USER_ID ) ) ;
@@ -84,4 +100,4 @@ export class ProjectTitleComponent implements AfterViewInit {
84100 this . alertService . error ( 'There is an invalid user ID in the URL' ) ;
85101 }
86102 }
87- }
103+ }
0 commit comments