2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import {Injectable, Inject} from '@angular/core';
22 import {ICookie} from "../../models/app-config";
23 import {SdcConfigToken, ISdcConfig} from "../config/sdc-config.config";
26 export class Cookie2Service {
28 private cookie:ICookie;
29 private cookiePrefix:string;
31 constructor(@Inject(SdcConfigToken) sdcConfig:ISdcConfig) {
32 this.cookie = sdcConfig.cookie;
34 this.cookiePrefix = '';
35 let junctionName:string = this.getCookieByName(this.cookie.junctionName);
36 if ((junctionName !== null) && (junctionName !== '')) {
37 this.cookiePrefix = this.cookie.prefix + junctionName + '!';
39 console.log("junctionName:" + junctionName);
42 private getCookieByName = (cookieName:string):string => {
44 let cookies:Array<string> = document.cookie.split(';');
45 let cookieVal:string = '';
46 cookies.forEach((cookie:string) => {
47 while (cookie.charAt(0) === ' ') {
48 cookie = cookie.substring(1);
50 if (cookie.indexOf(cookieName) === 0) {
51 cookieVal = cookie.substring(cookieName.length, cookie.length);
58 public getUserIdSuffix = ():string => {
59 return this.cookie.userIdSuffix;
62 public getUserId = ():string => {
63 let userIdCookieName:string = this.cookiePrefix + this.cookie.userIdSuffix;
64 let userId:string = this.getCookieByName(userIdCookieName);
68 public getFirstName = ():string => {
69 let firstNameCookieName:string = this.cookiePrefix + this.cookie.userFirstName;
70 let firstName:string = this.getCookieByName(firstNameCookieName);
74 public getLastName = ():string => {
75 let lastNameCookieName:string = this.cookiePrefix + this.cookie.userLastName;
76 let lastName:string = this.getCookieByName(lastNameCookieName);
80 public getEmail = ():string => {
81 let emailCookieName:string = this.cookiePrefix + this.cookie.userEmail;
82 let email:string = this.getCookieByName(emailCookieName);