made everything use the new storage service

pull/3895/head
Jamie Rees 5 years ago
parent a8dd23d29f
commit 90b38e09ec

@ -68,7 +68,7 @@ export class AppComponent implements OnInit {
}
public ngOnInit() {
const theme = localStorage.getItem("theme");
const theme = this.storage.get("theme");
this.onSetTheme(theme);
this.settingsService.getCustomization().subscribe(x => {

@ -3,17 +3,19 @@ import { Injectable } from "@angular/core";
import { Router } from "@angular/router";
import { CanActivate } from "@angular/router";
import { AuthService } from "./auth.service";
import { StorageService } from "../shared/storage/storage-service";
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private auth: AuthService, private router: Router) { }
constructor(private auth: AuthService, private router: Router,
private store: StorageService) { }
public canActivate() {
if (this.auth.loggedIn()) {
return true;
} else {
localStorage.removeItem("token");
this.store.remove("token");
this.router.navigate(["login"]);
return false;
}

@ -6,11 +6,13 @@ import { Observable } from "rxjs";
import { ServiceHelpers } from "../services";
import { ILocalUser, IUserLogin } from "./IUserLogin";
import { StorageService } from "../shared/storage/storage-service";
@Injectable()
export class AuthService extends ServiceHelpers {
constructor(http: HttpClient, @Inject(APP_BASE_HREF) href: string, private jwtHelperService: JwtHelperService) {
constructor(http: HttpClient, @Inject(APP_BASE_HREF) href: string, private jwtHelperService: JwtHelperService,
private store: StorageService) {
super(http, "/api/v1/token", href);
}
@ -39,7 +41,7 @@ export class AuthService extends ServiceHelpers {
public claims(): ILocalUser {
if (this.loggedIn()) {
const token = localStorage.getItem("id_token");
const token = this.store.get("id_token");
if (!token) {
throw new Error("Invalid token");
}
@ -68,6 +70,6 @@ export class AuthService extends ServiceHelpers {
}
public logout() {
localStorage.removeItem("id_token");
this.store.remove("id_token");
}
}

@ -1,19 +1,21 @@
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { CookieService } from "ng2-cookies";
import { StorageService } from "../shared/storage/storage-service";
@Component({
templateUrl: "cookie.component.html",
})
export class CookieComponent implements OnInit {
constructor(private readonly cookieService: CookieService,
private readonly router: Router) { }
private readonly router: Router,
private store: StorageService) { }
public ngOnInit() {
const cookie = this.cookieService.getAll();
if (cookie.Auth) {
const jwtVal = cookie.Auth;
localStorage.setItem("id_token", jwtVal);
this.store.save("id_token", jwtVal);
this.router.navigate(["search"]);
} else {
this.router.navigate(["login"]);

@ -14,6 +14,7 @@ import { DomSanitizer } from "@angular/platform-browser";
import { ImageService } from "../services";
import { fadeInOutAnimation } from "../animations/fadeinout";
import { StorageService } from "../shared/storage/storage-service";
@Component({
templateUrl: "./login.component.html",
@ -49,7 +50,8 @@ export class LoginComponent implements OnDestroy, OnInit {
constructor(private authService: AuthService, private router: Router, private notify: NotificationService, private status: StatusService,
private fb: FormBuilder, private settingsService: SettingsService, private images: ImageService, private sanitizer: DomSanitizer,
private route: ActivatedRoute, @Inject(APP_BASE_HREF) href:string, private translate: TranslateService, private plexTv: PlexTvService) {
private route: ActivatedRoute, @Inject(APP_BASE_HREF) href:string, private translate: TranslateService, private plexTv: PlexTvService,
private store: StorageService) {
this.href = href;
this.route.params
.subscribe((params: any) => {
@ -115,7 +117,7 @@ export class LoginComponent implements OnDestroy, OnInit {
}
this.authService.login(user)
.subscribe(x => {
localStorage.setItem("id_token", x.access_token);
this.store.save("id_token", x.access_token);
if (this.authService.loggedIn()) {
this.ngOnDestroy();
@ -153,7 +155,7 @@ export class LoginComponent implements OnDestroy, OnInit {
public getPinResult(pinId: number) {
this.authService.oAuth(pinId).subscribe(x => {
if(x.access_token) {
localStorage.setItem("id_token", x.access_token);
this.store.save("id_token", x.access_token);
if (this.authService.loggedIn()) {
this.ngOnDestroy();

@ -3,6 +3,7 @@ import { ActivatedRoute, Router } from "@angular/router";
import { AuthService } from "../auth/auth.service";
import { NotificationService } from "../services";
import { StorageService } from "../shared/storage/storage-service";
@Component({
templateUrl: "./loginoauth.component.html",
@ -12,7 +13,8 @@ export class LoginOAuthComponent implements OnInit {
public error: string;
constructor(private authService: AuthService, private router: Router,
private route: ActivatedRoute, private notify: NotificationService) {
private route: ActivatedRoute, private notify: NotificationService,
private store: StorageService) {
this.route.params
.subscribe((params: any) => {
this.pin = params.pin;
@ -26,7 +28,7 @@ export class LoginOAuthComponent implements OnInit {
public auth() {
this.authService.oAuth(this.pin).subscribe(x => {
if (x.access_token) {
localStorage.setItem("id_token", x.access_token);
this.store.save("id_token", x.access_token);
if (this.authService.loggedIn()) {
this.router.navigate(["search"]);

@ -3,6 +3,7 @@ import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { INavBar } from '../interfaces/ICommon';
import { StorageService } from '../shared/storage/storage-service';
@Component({
selector: 'app-my-nav',
@ -24,13 +25,14 @@ export class MyNavComponent implements OnInit {
@Output() public themeChange = new EventEmitter<string>();
public theme: string;
constructor(private breakpointObserver: BreakpointObserver) {
constructor(private breakpointObserver: BreakpointObserver,
private store: StorageService) {
}
public ngOnInit(): void {
this.theme = localStorage.getItem("theme");
this.theme = this.store.get("theme");
if(!this.theme) {
localStorage.setItem("theme","light");
this.store.save("theme","light");
}
}
@ -49,14 +51,13 @@ export class MyNavComponent implements OnInit {
public switchTheme() {
if (this.theme) {
localStorage.removeItem("theme");
let newTheme = "";
if (this.theme === "dark") {
newTheme = "light";
} else {
newTheme = "dark";
}
localStorage.setItem("theme", newTheme)
this.store.save("theme", newTheme)
this.theme = newTheme;
this.themeChange.emit(newTheme);
}

@ -78,15 +78,4 @@ export class IdentityService extends ServiceHelpers {
public getNotificationPreferencesForUser(userId: string): Observable<INotificationPreferences[]> {
return this.http.get<INotificationPreferences[]>(`${this.url}notificationpreferences/${userId}`, {headers: this.headers});
}
public hasRole(role: string): boolean {
const roles = localStorage.getItem("roles") as any as string[] | null;
if (roles) {
if (roles.indexOf(role) > -1) {
return true;
}
return false;
}
return false;
}
}

@ -5,6 +5,7 @@ import { PlatformLocation } from "@angular/common";
import { AuthService } from "../../auth/auth.service";
import { PlexOAuthService, PlexService, PlexTvService, SettingsService } from "../../services";
import { IdentityService, NotificationService } from "../../services";
import { StorageService } from "../../shared/storage/storage-service";
@Component({
templateUrl: "./plex.component.html",
@ -23,7 +24,7 @@ export class PlexComponent implements OnInit, OnDestroy {
private identityService: IdentityService, private plexTv: PlexTvService,
private settingsService: SettingsService,
private location: PlatformLocation, private authService: AuthService,
private plexOauth: PlexOAuthService) { }
private plexOauth: PlexOAuthService, private store: StorageService) { }
public ngOnInit(): void {
const base = this.location.getBaseHrefFromDOM();
@ -95,7 +96,7 @@ export class PlexComponent implements OnInit, OnDestroy {
}).subscribe(u => {
if (u.result) {
this.authService.oAuth(pinId).subscribe(c => {
localStorage.setItem("id_token", c.access_token);
this.store.save("id_token", c.access_token);
this.router.navigate(["login"]);
});
} else {

Loading…
Cancel
Save