Skip to content

Commit 0d6d4ab

Browse files
committed
feat: TTA-180 creating logout
1 parent 12c9efd commit 0d6d4ab

File tree

10 files changed

+34
-87
lines changed

10 files changed

+34
-87
lines changed

.dev.env

-24 Bytes
Binary file not shown.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
API_URL: ${API_URL}
1515
CLIENT_ID: ${CLIENT_ID}
1616
CLIENT_URL: ${CLIENT_URL}
17+
AUTH_URL: ${AUTH_URL}
1718
SCOPES: ${SCOPES}
1819
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
1920
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}

proxy.conf.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/app/modules/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ <h3>Please log in</h3>
1111
<button (click)="login() " class="btn btn-primary">login</button>
1212
</div>
1313
<div *ngIf="!isProduction">
14-
<button class="btn btn-primary"><a href="{{loginAuth()}}"></a></button>
14+
<button class="btn btn-primary"><a href="{{loginAuth()}}">Login</a></button>
1515
</div>
1616
</div>

src/app/modules/login/login.component.ts

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AzureAdB2CService } from './services/azure.ad.b2c.service';
33
import { Router } from '@angular/router';
44
import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-toggle-cookies/feature-toggle-cookies.service';
55

6-
import { environment, CLIENT_URL, AUTH_URL } from 'src/environments/environment';
6+
import { environment, CLIENT_URL } from 'src/environments/environment';
77
import { EnvironmentType } from 'src/environments/enum';
88
import { LoginService } from './services/login.service';
99
import { UserService } from '../user/services/user.service';
@@ -22,7 +22,7 @@ declare global {
2222
export class LoginComponent implements OnInit {
2323
isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY;
2424
cliendId = CLIENT_URL;
25-
authUrl = AUTH_URL;
25+
authUrl = environment.authUrl;
2626
auth2: any;
2727

2828

@@ -35,65 +35,16 @@ export class LoginComponent implements OnInit {
3535
private ngZone?: NgZone
3636
) {}
3737

38-
39-
googleAuthSDK() {
40-
const sdkLoaded = 'googleSDKLoaded';
41-
const gapi = 'gapi';
42-
43-
(window as any)[sdkLoaded] = () => {
44-
(window as any)[gapi].load('auth2', () => {
45-
this.auth2 = ( window as any)[gapi].auth2.init({
46-
client_id: this.cliendId,
47-
plugin_name: 'login',
48-
cookiepolicy: 'single_host_origin',
49-
scope: 'profile email'
50-
});
51-
});
52-
};
53-
54-
(async (d, s, id) => {
55-
const keyGoogle = 'src';
56-
const gjs = d.getElementsByTagName(s)[1];
57-
let js = gjs;
58-
if (d.getElementById(id)) { return; }
59-
js = d.createElement(s); js.id = id;
60-
js[keyGoogle] = 'https://accounts.google.com/gsi/client';
61-
gjs.parentNode.insertBefore(js, gjs);
62-
})(document, 'script', 'async defer');
63-
}
64-
6538
ngOnInit() {
66-
67-
this.googleAuthSDK();
68-
if (this.isProduction && this.azureAdB2CService.isLogin()) {
69-
this.router.navigate(['']);
70-
} else {
71-
this.loginService.isLogin().subscribe(isLogin => {
72-
if (isLogin) {
73-
this.router.navigate(['']);
74-
}
39+
if (!this.isProduction) {
40+
this.loginService.getUser(null).subscribe((resp) => {
41+
this.loginService.setCookies();
42+
const tokenObject = JSON.stringify(resp);
43+
const tokenJson = JSON.parse(tokenObject);
44+
this.loginService.setLocalStorage('user', tokenJson.token);
45+
this.ngZone.run(() => this.router.navigate(['']));
7546
});
7647
}
77-
window.handleCredentialResponse = (response) => {
78-
const {credential = ''} = response;
79-
this.featureToggleCookiesService.setCookies();
80-
this.loginService.setLocalStorage('idToken', credential);
81-
this.loginService.getUser(credential).subscribe((resp) => {
82-
this.loginService.setCookies();
83-
const tokenObject = JSON.stringify(resp);
84-
const tokenJson = JSON.parse(tokenObject);
85-
this.loginService.setLocalStorage('user', tokenJson.token);
86-
this.ngZone.run(() => this.router.navigate(['']));
87-
});
88-
};
89-
this.loginService.getUser('test').subscribe((resp) => {
90-
this.loginService.setCookies();
91-
const tokenObject = JSON.stringify(resp);
92-
console.log(tokenObject)
93-
const tokenJson = JSON.parse(tokenObject);
94-
this.loginService.setLocalStorage('user', tokenJson.token);
95-
this.ngZone.run(() => this.router.navigate(['']));
96-
});
9748
}
9849

9950
login(): void {
@@ -116,7 +67,7 @@ export class LoginComponent implements OnInit {
11667
}
11768

11869
loginAuth(): string {
119-
return this.authUrl;
70+
return `${this.authUrl}/authn/login/timeTracker`;
12071
}
12172

12273
}

src/app/modules/login/services/login.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { HttpClient, HttpHeaders } from '@angular/common/http';
2-
import { Injectable } from '@angular/core';
1+
import { HttpClient } from '@angular/common/http';
2+
import { Injectable, NgZone } from '@angular/core';
33
import { CookieService } from 'ngx-cookie-service';
44
import { EnvironmentType, UserEnum } from 'src/environments/enum';
55
import { environment } from 'src/environments/environment';
66
import { JwtHelperService } from '@auth0/angular-jwt';
77
import { map } from 'rxjs/operators';
8-
import { of } from 'rxjs';
8+
import { Observable, of } from 'rxjs';
9+
import { Router } from '@angular/router';
910

1011
@Injectable({
1112
providedIn: 'root'
@@ -15,6 +16,8 @@ export class LoginService {
1516
helper: JwtHelperService;
1617
isLegacyProd: boolean = environment.production === EnvironmentType.TT_PROD_LEGACY;
1718
localStorageKey = this.isLegacyProd ? 'user2' : 'user';
19+
router: Router;
20+
ngZone: NgZone;
1821

1922
constructor(
2023
private http?: HttpClient,
@@ -25,8 +28,8 @@ export class LoginService {
2528
}
2629

2730
logout() {
28-
this.cookieService.deleteAll();
2931
localStorage.clear();
32+
this.http.post(`${this.baseUrl}/logout`, null, { withCredentials: true }).subscribe();
3033
}
3134

3235
isLogin() {
@@ -120,5 +123,4 @@ export class LoginService {
120123
})
121124
);
122125
}
123-
124126
}

src/app/modules/shared/components/sidebar/sidebar.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ <h3 class="font-poppins text-base ml-4 pl-3 -mt-6 text-left" >{{ item.text }}</h
4040
<div id="page-content-wrapper">
4141
<div class="container-fluid px-0 full-height">
4242
<div class="content_app h-100">
43-
<div class="m-1 p-5 rounded-md bg-whiteTW dark:bg-grayTW-dark">
43+
<div class="m-1 p-5 rounded-md bg-whiteTW dark:bg-grayTW-dark">
4444
<router-outlet></router-outlet>
4545
</div>
4646
</div>
4747
</div>
4848
</div>
49-
</div>
49+
</div>

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export class EntryService {
2828

2929
loadEntries(date): Observable<any> {
3030
const timezoneOffset = new Date().getTimezoneOffset();
31-
return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`, { withCredentials: true });
31+
return this.http.get(
32+
`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`,
33+
{ withCredentials: true }
34+
);
3235
}
3336

3437
createEntry(entryData): Observable<any> {
@@ -47,7 +50,8 @@ export class EntryService {
4750

4851
stopEntryRunning(idEntry: string): Observable<any> {
4952
return (this.urlInProductionLegacy ?
50-
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null, { withCredentials: true }) : this.http.put(`${this.baseUrl}/stop`, null, { withCredentials: true }) );
53+
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null, { withCredentials: true }) :
54+
this.http.put(`${this.baseUrl}/stop`, null, { withCredentials: true }) );
5155
}
5256

5357
restartEntry(idEntry: string): Observable<Entry> {

src/environments/environment.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { EnvironmentType } from './enum';
66
/* tslint:disable:no-string-literal */
77
export const environment = {
88
production: EnvironmentType.TT_DEV,
9-
timeTrackerApiUrl: process.env["API_URL"],
9+
timeTrackerApiUrl: process.env['API_URL'],
1010
stackexchangeApiUrl: 'https://api.stackexchange.com',
11+
authUrl: 'https://uat-backend.auth.ioet.com',
1112
};
1213

1314
export const AUTHORITY = process.env['AUTHORITY'];
1415
export const CLIENT_ID = process.env['CLIENT_ID'];
1516
export const CLIENT_URL = process.env['CLIENT_URL'];
16-
export let AUTH_URL = process.env['AUTH_URL'];
17+
export const AUTH_URL = process.env['AUTH_URL'];
1718
export const SCOPES = process.env['SCOPES'].split(',');
1819
export const STACK_EXCHANGE_ID = process.env['STACK_EXCHANGE_ID'];
1920
export const STACK_EXCHANGE_ACCESS_TOKEN = process.env['STACK_EXCHANGE_ACCESS_TOKEN'];

src/polyfills.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
6161
/***************************************************************************************************
6262
* APPLICATION IMPORTS
6363
*/
64+
65+
(window as any).process = {
66+
env: { DEBUG: undefined },
67+
};

0 commit comments

Comments
 (0)