cookie init
This commit is contained in:
34
src/app/service/cookie.service.ts
Normal file
34
src/app/service/cookie.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {CookieService} from 'ngx-cookie-service';
|
||||
import {Router} from "@angular/router";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class cookieService {
|
||||
|
||||
constructor(
|
||||
private coockieService: CookieService,
|
||||
private router: Router,
|
||||
) {
|
||||
}
|
||||
|
||||
setUsername(username: string): void {
|
||||
this.coockieService.set('username', username);
|
||||
}
|
||||
|
||||
getUsername(): string {
|
||||
let username = this.coockieService.get('username');
|
||||
if (username == null) {
|
||||
this.router.navigate(['/login']);
|
||||
return '';
|
||||
} else {
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
||||
deleteUsername(): void {
|
||||
this.coockieService.delete('username');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user