added logout
This commit is contained in:
parent
f0ff72a1b1
commit
1274615ee2
9 changed files with 47 additions and 12 deletions
|
|
@ -41,17 +41,10 @@ export class AppComponent {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
console.log(this.isLoggedIn);
|
||||
|
||||
if (this.isLoggedIn === undefined) {
|
||||
this.router.navigate(['/login']);
|
||||
} else {
|
||||
this.getUserIdInLocalStorage();
|
||||
this.router.navigate(['/summary']);
|
||||
}
|
||||
}
|
||||
|
||||
getUserIdInLocalStorage() {
|
||||
localStorage.setItem('currentUser', JSON.stringify('5EX7gnwPPGEDbN186Rdw'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@
|
|||
[class]="'btn-guest-login'"
|
||||
[type]="'button'"
|
||||
[value]="'Guest Log in'"
|
||||
(click)="guestLogin()"
|
||||
></app-form-btn>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common';
|
|||
import { Component } from '@angular/core';
|
||||
import { FormsModule, NgForm } from '@angular/forms';
|
||||
import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component';
|
||||
import { FirebaseService } from '../../services/firebase.service';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
|
|
@ -16,8 +18,22 @@ export class LoginComponent {
|
|||
password: '',
|
||||
};
|
||||
|
||||
constructor(
|
||||
private firebaseService: FirebaseService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
onSubmit(ngForm: NgForm) {
|
||||
if (ngForm.submitted && ngForm.form.valid) {
|
||||
}
|
||||
}
|
||||
|
||||
guestLogin() {
|
||||
this.getUserIdInLocalStorage();
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
getUserIdInLocalStorage() {
|
||||
localStorage.setItem('currentUser', JSON.stringify('5EX7gnwPPGEDbN186Rdw'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ export class FirebaseService implements OnDestroy {
|
|||
allTasks: Task[] = [];
|
||||
filteredTasks: Task[] = [];
|
||||
allUsers: User[] = [];
|
||||
isUserLogin: boolean = false;
|
||||
|
||||
unsubTask;
|
||||
unsubUser;
|
||||
|
|
|
|||
|
|
@ -36,4 +36,15 @@ export class SharedService {
|
|||
cleanup() {
|
||||
this.removeResizeListener();
|
||||
}
|
||||
|
||||
// LOGOUT
|
||||
|
||||
logout() {
|
||||
this.deleteUserIdInLocalStorage();
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
deleteUserIdInLocalStorage() {
|
||||
localStorage.removeItem('currentUser');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
>
|
||||
<span>{{ "navbar.legalNotice" | translate }}</span>
|
||||
</div>
|
||||
<div class="link" onclick="logout()">
|
||||
<div class="link" (click)="logout()">
|
||||
<span>{{ "navbar.logout" | translate }}</span>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { HeaderComponent } from '../header/header.component';
|
|||
import { LanguageService } from '../../../services/language.service';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SharedService } from '../../../services/shared.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-navbar',
|
||||
|
|
@ -18,9 +19,17 @@ export class NavbarComponent {
|
|||
|
||||
currentRoute: string = '';
|
||||
|
||||
constructor(public langService: LanguageService, private router: Router) {}
|
||||
constructor(
|
||||
public langService: LanguageService,
|
||||
private router: Router,
|
||||
private sharedService: SharedService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.currentRoute = this.router.url;
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.sharedService.logout();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,6 @@
|
|||
{{ "sidebar.privacyPolicy" | translate }}
|
||||
</div>
|
||||
<div routerLink="imprint">{{ "sidebar.legalNotice" | translate }}</div>
|
||||
<div onclick="logout()">{{ "sidebar.logout" | translate }}</div>
|
||||
<div (click)="logout()">{{ "sidebar.logout" | translate }}</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
|
|||
import { NavigationEnd, Router, RouterModule } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { LanguageService } from '../../../services/language.service';
|
||||
import { SharedService } from '../../../services/shared.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
|
|
@ -16,13 +17,18 @@ export class SidebarComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
private router: Router,
|
||||
public languageService: LanguageService
|
||||
public languageService: LanguageService,
|
||||
private sharedService: SharedService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getCurrentPath();
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.sharedService.logout();
|
||||
}
|
||||
|
||||
getCurrentPath() {
|
||||
this.router.events.subscribe((event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue