Add comments
This commit is contained in:
parent
9aa45d28d8
commit
be59f274ec
@ -50,6 +50,8 @@ const ELEMENT_DATA: PeriodicElement[] = [
|
|||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
constructor(private dataService: DataService) {}
|
constructor(private dataService: DataService) {}
|
||||||
|
|
||||||
|
//TODO avoid using ngOnInit() like this
|
||||||
|
//TODO fix server problems
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
const data = await this.dataService.getStockData();
|
const data = await this.dataService.getStockData();
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,14 @@ import { TokenStorageService } from 'src/app/Services/token.service';
|
|||||||
styleUrls: ['./header.component.scss'],
|
styleUrls: ['./header.component.scss'],
|
||||||
})
|
})
|
||||||
export class HeaderComponent implements OnInit {
|
export class HeaderComponent implements OnInit {
|
||||||
|
/**
|
||||||
|
* @param {TokenStorageService} privatetokenStorage
|
||||||
|
*/
|
||||||
constructor(private tokenStorage: TokenStorageService) {}
|
constructor(private tokenStorage: TokenStorageService) {}
|
||||||
|
|
||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
|
|
||||||
|
//logout() clears session storage; All user data is eradicated from it and page is reloaded
|
||||||
logout() {
|
logout() {
|
||||||
this.tokenStorage.signOut();
|
this.tokenStorage.signOut();
|
||||||
location.reload();
|
location.reload();
|
||||||
|
@ -18,17 +18,26 @@ export class LoginComponent implements OnInit {
|
|||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
accountName = '';
|
accountName = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AuthService} privateauthService
|
||||||
|
* @param {TokenStorageService} privatetokenStorage
|
||||||
|
* @param {Router} privaterouter
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private tokenStorage: TokenStorageService,
|
private tokenStorage: TokenStorageService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
//ngOnInit() checks if a
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.tokenStorage.signOut();
|
this.tokenStorage.signOut();
|
||||||
if (this.tokenStorage.getToken()) {
|
if (this.tokenStorage.getToken()) {
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//onSubmit() saves valuable information in session storage
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
const { username, password } = this.form;
|
const { username, password } = this.form;
|
||||||
this.authService.login(username, password).subscribe(
|
this.authService.login(username, password).subscribe(
|
||||||
@ -47,6 +56,8 @@ export class LoginComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//reloadPage() reloads the page
|
||||||
reloadPage(): void {
|
reloadPage(): void {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ export class RegisterComponent implements OnInit {
|
|||||||
isSuccessful = false;
|
isSuccessful = false;
|
||||||
isSignUpFailed = false;
|
isSignUpFailed = false;
|
||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AuthService} privateauthService
|
||||||
|
* @param {Router} privaterouter
|
||||||
|
*/
|
||||||
constructor(private authService: AuthService, private router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
|
@ -13,8 +13,8 @@ export class AppComponent {
|
|||||||
* Application title.
|
* Application title.
|
||||||
*/
|
*/
|
||||||
title = 'Aktienbot';
|
title = 'Aktienbot';
|
||||||
showHeader = false;
|
|
||||||
|
|
||||||
|
showHeader = false;
|
||||||
isLoggedIn = false;
|
isLoggedIn = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,6 +26,7 @@ export class AppComponent {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private tokenStorage: TokenStorageService
|
private tokenStorage: TokenStorageService
|
||||||
) {
|
) {
|
||||||
|
//check if it is login or registration page, header should not show there
|
||||||
this.router.events
|
this.router.events
|
||||||
.pipe(filter((event) => event instanceof NavigationEnd))
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||||
.subscribe((event) => {
|
.subscribe((event) => {
|
||||||
@ -33,11 +34,15 @@ export class AppComponent {
|
|||||||
(event as NavigationEnd).url === '/login' ||
|
(event as NavigationEnd).url === '/login' ||
|
||||||
(event as NavigationEnd).url === '/register'
|
(event as NavigationEnd).url === '/register'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//check if token already exists from past login
|
||||||
if (this.tokenStorage.getToken()) {
|
if (this.tokenStorage.getToken()) {
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
} else {
|
} else {
|
||||||
this.isLoggedIn = false;
|
this.isLoggedIn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//prevent user from accessing dashboard if not logged in
|
||||||
if (
|
if (
|
||||||
this.isLoggedIn === false &&
|
this.isLoggedIn === false &&
|
||||||
(event as NavigationEnd).url != '/register'
|
(event as NavigationEnd).url != '/register'
|
||||||
|
Loading…
Reference in New Issue
Block a user