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