Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: TTA-180 creating logout
  • Loading branch information
reihtw committed Oct 11, 2022
commit 0d6d4abdbacf4498cbad113353b2b018fd5b7a25
Binary file modified .dev.env
Binary file not shown.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
API_URL: ${API_URL}
CLIENT_ID: ${CLIENT_ID}
CLIENT_URL: ${CLIENT_URL}
AUTH_URL: ${AUTH_URL}
SCOPES: ${SCOPES}
STACK_EXCHANGE_ID: ${STACK_EXCHANGE_ID}
STACK_EXCHANGE_ACCESS_TOKEN: ${STACK_EXCHANGE_ACCESS_TOKEN}
Expand Down
16 changes: 0 additions & 16 deletions proxy.conf.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/modules/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ <h3>Please log in</h3>
<button (click)="login() " class="btn btn-primary">login</button>
</div>
<div *ngIf="!isProduction">
<button class="btn btn-primary"><a href="{{loginAuth()}}"></a></button>
<button class="btn btn-primary"><a href="{{loginAuth()}}">Login</a></button>
</div>
</div>
69 changes: 10 additions & 59 deletions src/app/modules/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AzureAdB2CService } from './services/azure.ad.b2c.service';
import { Router } from '@angular/router';
import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-toggle-cookies/feature-toggle-cookies.service';

import { environment, CLIENT_URL, AUTH_URL } from 'src/environments/environment';
import { environment, CLIENT_URL } from 'src/environments/environment';
import { EnvironmentType } from 'src/environments/enum';
import { LoginService } from './services/login.service';
import { UserService } from '../user/services/user.service';
Expand All @@ -22,7 +22,7 @@ declare global {
export class LoginComponent implements OnInit {
isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY;
cliendId = CLIENT_URL;
authUrl = AUTH_URL;
authUrl = environment.authUrl;
auth2: any;


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


googleAuthSDK() {
const sdkLoaded = 'googleSDKLoaded';
const gapi = 'gapi';

(window as any)[sdkLoaded] = () => {
(window as any)[gapi].load('auth2', () => {
this.auth2 = ( window as any)[gapi].auth2.init({
client_id: this.cliendId,
plugin_name: 'login',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
});
});
};

(async (d, s, id) => {
const keyGoogle = 'src';
const gjs = d.getElementsByTagName(s)[1];
let js = gjs;
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js[keyGoogle] = 'https://accounts.google.com/gsi/client';
gjs.parentNode.insertBefore(js, gjs);
})(document, 'script', 'async defer');
}

ngOnInit() {

this.googleAuthSDK();
if (this.isProduction && this.azureAdB2CService.isLogin()) {
this.router.navigate(['']);
} else {
this.loginService.isLogin().subscribe(isLogin => {
if (isLogin) {
this.router.navigate(['']);
}
if (!this.isProduction) {
this.loginService.getUser(null).subscribe((resp) => {
this.loginService.setCookies();
const tokenObject = JSON.stringify(resp);
const tokenJson = JSON.parse(tokenObject);
this.loginService.setLocalStorage('user', tokenJson.token);
this.ngZone.run(() => this.router.navigate(['']));
});
}
window.handleCredentialResponse = (response) => {
const {credential = ''} = response;
this.featureToggleCookiesService.setCookies();
this.loginService.setLocalStorage('idToken', credential);
this.loginService.getUser(credential).subscribe((resp) => {
this.loginService.setCookies();
const tokenObject = JSON.stringify(resp);
const tokenJson = JSON.parse(tokenObject);
this.loginService.setLocalStorage('user', tokenJson.token);
this.ngZone.run(() => this.router.navigate(['']));
});
};
this.loginService.getUser('test').subscribe((resp) => {
this.loginService.setCookies();
const tokenObject = JSON.stringify(resp);
console.log(tokenObject)
const tokenJson = JSON.parse(tokenObject);
this.loginService.setLocalStorage('user', tokenJson.token);
this.ngZone.run(() => this.router.navigate(['']));
});
}

login(): void {
Expand All @@ -116,7 +67,7 @@ export class LoginComponent implements OnInit {
}

loginAuth(): string {
return this.authUrl;
return `${this.authUrl}/authn/login/timeTracker`;
}

}
12 changes: 7 additions & 5 deletions src/app/modules/login/services/login.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Injectable, NgZone } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { EnvironmentType, UserEnum } from 'src/environments/enum';
import { environment } from 'src/environments/environment';
import { JwtHelperService } from '@auth0/angular-jwt';
import { map } from 'rxjs/operators';
import { of } from 'rxjs';
import { Observable, of } from 'rxjs';
import { Router } from '@angular/router';

@Injectable({
providedIn: 'root'
Expand All @@ -15,6 +16,8 @@ export class LoginService {
helper: JwtHelperService;
isLegacyProd: boolean = environment.production === EnvironmentType.TT_PROD_LEGACY;
localStorageKey = this.isLegacyProd ? 'user2' : 'user';
router: Router;
ngZone: NgZone;

constructor(
private http?: HttpClient,
Expand All @@ -25,8 +28,8 @@ export class LoginService {
}

logout() {
this.cookieService.deleteAll();
localStorage.clear();
this.http.post(`${this.baseUrl}/logout`, null, { withCredentials: true }).subscribe();
}

isLogin() {
Expand Down Expand Up @@ -120,5 +123,4 @@ export class LoginService {
})
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ <h3 class="font-poppins text-base ml-4 pl-3 -mt-6 text-left" >{{ item.text }}</h
<div id="page-content-wrapper">
<div class="container-fluid px-0 full-height">
<div class="content_app h-100">
<div class="m-1 p-5 rounded-md bg-whiteTW dark:bg-grayTW-dark">
<div class="m-1 p-5 rounded-md bg-whiteTW dark:bg-grayTW-dark">
<router-outlet></router-outlet>
</div>
</div>
</div>
</div>
</div>
</div>
8 changes: 6 additions & 2 deletions src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export class EntryService {

loadEntries(date): Observable<any> {
const timezoneOffset = new Date().getTimezoneOffset();
return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`, { withCredentials: true });
return this.http.get(
`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`,
{ withCredentials: true }
);
}

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

stopEntryRunning(idEntry: string): Observable<any> {
return (this.urlInProductionLegacy ?
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null, { withCredentials: true }) : this.http.put(`${this.baseUrl}/stop`, null, { withCredentials: true }) );
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null, { withCredentials: true }) :
this.http.put(`${this.baseUrl}/stop`, null, { withCredentials: true }) );
}

restartEntry(idEntry: string): Observable<Entry> {
Expand Down
5 changes: 3 additions & 2 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { EnvironmentType } from './enum';
/* tslint:disable:no-string-literal */
export const environment = {
production: EnvironmentType.TT_DEV,
timeTrackerApiUrl: process.env["API_URL"],
timeTrackerApiUrl: process.env['API_URL'],
stackexchangeApiUrl: 'https://api.stackexchange.com',
authUrl: 'https://uat-backend.auth.ioet.com',
};

export const AUTHORITY = process.env['AUTHORITY'];
export const CLIENT_ID = process.env['CLIENT_ID'];
export const CLIENT_URL = process.env['CLIENT_URL'];
export let AUTH_URL = process.env['AUTH_URL'];
export const AUTH_URL = process.env['AUTH_URL'];
export const SCOPES = process.env['SCOPES'].split(',');
export const STACK_EXCHANGE_ID = process.env['STACK_EXCHANGE_ID'];
export const STACK_EXCHANGE_ACCESS_TOKEN = process.env['STACK_EXCHANGE_ACCESS_TOKEN'];
Expand Down
4 changes: 4 additions & 0 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

(window as any).process = {
env: { DEBUG: undefined },
};