diff --git a/src/Ombi/ClientApp/app/app.module.ts b/src/Ombi/ClientApp/app/app.module.ts index 1e5fe82e9..ab79b8fe9 100644 --- a/src/Ombi/ClientApp/app/app.module.ts +++ b/src/Ombi/ClientApp/app/app.module.ts @@ -8,6 +8,8 @@ import {BrowserModule} from "@angular/platform-browser"; import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; import {RouterModule, Routes} from "@angular/router"; +import { JwtModule } from "@auth0/angular-jwt"; + // Third Party //import { DragulaModule, DragulaService } from 'ng2-dragula/ng2-dragula'; import { NgbModule } from "@ng-bootstrap/ng-bootstrap"; @@ -27,7 +29,6 @@ import { TokenResetPasswordComponent } from "./login/tokenresetpassword.componen // Services import { AuthGuard } from "./auth/auth.guard"; -import { AuthModule } from "./auth/auth.module"; import { AuthService } from "./auth/auth.service"; import { IdentityService } from "./services"; import { ImageService } from "./services"; @@ -78,7 +79,6 @@ export function HttpLoaderFactory(http: HttpClient, platformLocation: PlatformLo SettingsModule, DataTableModule, SharedModule, - AuthModule, WizardModule, SearchModule, DialogModule, @@ -93,7 +93,18 @@ export function HttpLoaderFactory(http: HttpClient, platformLocation: PlatformLo CaptchaModule, TooltipModule, ConfirmDialogModule, - CommonModule, + CommonModule, + JwtModule.forRoot({ + config: { + tokenGetter: () => { + const token = localStorage.getItem("id_token"); + if (!token) { + return ""; + } + return token; + }, + }, + }), TranslateModule.forRoot({ loader: { provide: TranslateLoader, diff --git a/src/Ombi/ClientApp/app/auth/auth.guard.ts b/src/Ombi/ClientApp/app/auth/auth.guard.ts index 166d94a99..d06d8c590 100644 --- a/src/Ombi/ClientApp/app/auth/auth.guard.ts +++ b/src/Ombi/ClientApp/app/auth/auth.guard.ts @@ -13,6 +13,7 @@ export class AuthGuard implements CanActivate { if (this.auth.loggedIn()) { return true; } else { + localStorage.removeItem("token"); this.router.navigate(["login"]); return false; } diff --git a/src/Ombi/ClientApp/app/auth/auth.module.ts b/src/Ombi/ClientApp/app/auth/auth.module.ts deleted file mode 100644 index 49f22a98f..000000000 --- a/src/Ombi/ClientApp/app/auth/auth.module.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { NgModule } from "@angular/core"; -import { Http, RequestOptions } from "@angular/http"; -import { RouterModule, Routes } from "@angular/router"; -import { AuthConfig, AuthHttp } from "angular2-jwt"; -import { CookieService } from "ng2-cookies"; -import { CookieComponent } from "./cookie.component"; - -export function authHttpServiceFactory(http: Http, options: RequestOptions) { - return new AuthHttp(new AuthConfig({ - tokenName: "id_token", - tokenGetter: (() => localStorage.getItem("id_token")!), - globalHeaders: [{ "Content-Type": "application/json" }], - }), http, options); -} -const routes: Routes = [ - { path: "auth/cookie", component: CookieComponent }, -]; - -@NgModule({ - imports : [ - RouterModule.forChild(routes), - ], - declarations:[ - CookieComponent, - ], - providers: [ - { - provide: AuthHttp, - useFactory: authHttpServiceFactory, - deps: [Http, RequestOptions], - }, - CookieService, - ], -}) -export class AuthModule { } diff --git a/src/Ombi/ClientApp/app/auth/auth.service.ts b/src/Ombi/ClientApp/app/auth/auth.service.ts index a2770e221..976c9dcb9 100644 --- a/src/Ombi/ClientApp/app/auth/auth.service.ts +++ b/src/Ombi/ClientApp/app/auth/auth.service.ts @@ -1,7 +1,7 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { Headers, Http } from "@angular/http"; -import { JwtHelper, tokenNotExpired } from "angular2-jwt"; +import { JwtHelperService } from "@auth0/angular-jwt"; import { Observable } from "rxjs/Rx"; import { ServiceHelpers } from "../services"; @@ -9,22 +9,24 @@ import { ILocalUser, IUserLogin } from "./IUserLogin"; @Injectable() export class AuthService extends ServiceHelpers { - public jwtHelper: JwtHelper = new JwtHelper(); - constructor(http: Http, public platformLocation: PlatformLocation) { + constructor(http: HttpClient, public platformLocation: PlatformLocation, private jwtHelperService: JwtHelperService) { super(http, "/api/v1/token", platformLocation); } public login(login: IUserLogin): Observable { - this.headers = new Headers(); - this.headers.append("Content-Type", "application/json"); - - return this.http.post(`${this.url}/`, JSON.stringify(login), { headers: this.headers }) - .map(this.extractData); + return this.http.post(`${this.url}/`, JSON.stringify(login), {headers: this.headers}); } - public loggedIn() { - return tokenNotExpired("id_token"); + public loggedIn() { + const token: string = this.jwtHelperService.tokenGetter(); + + if (!token) { + return false; + } + + const tokenExpired: boolean = this.jwtHelperService.isTokenExpired(token); + return !tokenExpired; } public claims(): ILocalUser { @@ -33,7 +35,7 @@ export class AuthService extends ServiceHelpers { if (!token) { throw new Error("Invalid token"); } - const json = this.jwtHelper.decodeToken(token); + const json = this.jwtHelperService.decodeToken(token); const roles = json.role; const name = json.sub; diff --git a/src/Ombi/ClientApp/app/services/applications/couchpotato.service.ts b/src/Ombi/ClientApp/app/services/applications/couchpotato.service.ts index a4e43ad85..667cd1b98 100644 --- a/src/Ombi/ClientApp/app/services/applications/couchpotato.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/couchpotato.service.ts @@ -1,23 +1,23 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; import { Observable } from "rxjs/Rx"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; import { ICouchPotatoApiKey, ICouchPotatoProfiles, ICouchPotatoSettings } from "../../interfaces"; @Injectable() -export class CouchPotatoService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class CouchPotatoService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/CouchPotato/", platformLocation); } public getProfiles(settings: ICouchPotatoSettings): Observable { - return this.http.post(`${this.url}profile`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}profile`, JSON.stringify(settings), {headers: this.headers}); } public getApiKey(settings: ICouchPotatoSettings): Observable { - return this.http.post(`${this.url}apikey`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}apikey`, JSON.stringify(settings), {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/applications/emby.service.ts b/src/Ombi/ClientApp/app/services/applications/emby.service.ts index c8c6f6aea..a8897043c 100644 --- a/src/Ombi/ClientApp/app/services/applications/emby.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/emby.service.ts @@ -1,24 +1,23 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; -import { AuthHttp } from "angular2-jwt"; import { Observable } from "rxjs/Rx"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; import { IEmbySettings, IUsersModel } from "../../interfaces"; @Injectable() -export class EmbyService extends ServiceAuthHelpers { - constructor(http: AuthHttp, private regularHttp: Http, public platformLocation: PlatformLocation) { +export class EmbyService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Emby/", platformLocation); } public logIn(settings: IEmbySettings): Observable { - return this.regularHttp.post(`${this.url}`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}`, JSON.stringify(settings), {headers: this.headers}); } public getUsers(): Observable { - return this.http.get(`${this.url}users`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}users`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/applications/plex.service.ts b/src/Ombi/ClientApp/app/services/applications/plex.service.ts index dae06171b..c04a990e1 100644 --- a/src/Ombi/ClientApp/app/services/applications/plex.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/plex.service.ts @@ -1,33 +1,32 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; -import { AuthHttp } from "angular2-jwt"; import { Observable } from "rxjs/Rx"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; import { IPlexAuthentication, IPlexLibResponse, IPlexServer, IPlexServerViewModel, IUsersModel } from "../../interfaces"; @Injectable() -export class PlexService extends ServiceAuthHelpers { - constructor(http: AuthHttp, private regularHttp: Http, public platformLocation: PlatformLocation) { +export class PlexService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Plex/", platformLocation); } public logIn(login: string, password: string): Observable { - return this.regularHttp.post(`${this.url}`, JSON.stringify({ login, password }), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}`, JSON.stringify({ login, password }), {headers: this.headers}); } public getServers(login: string, password: string): Observable { - return this.http.post(`${this.url}servers`, JSON.stringify({ login, password }), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}servers`, JSON.stringify({ login, password }), {headers: this.headers}); } public getLibraries(plexSettings: IPlexServer): Observable { - return this.http.post(`${this.url}Libraries`, JSON.stringify(plexSettings), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}Libraries`, JSON.stringify(plexSettings), {headers: this.headers}); } public getFriends(): Observable { - return this.http.get(`${this.url}Friends`, { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}Friends`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/applications/radarr.service.ts b/src/Ombi/ClientApp/app/services/applications/radarr.service.ts index 0d76f4e9d..2403b3c8e 100644 --- a/src/Ombi/ClientApp/app/services/applications/radarr.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/radarr.service.ts @@ -1,29 +1,29 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; import { Observable } from "rxjs/Rx"; import { IRadarrProfile, IRadarrRootFolder } from "../../interfaces"; import { IRadarrSettings } from "../../interfaces"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; @Injectable() -export class RadarrService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class RadarrService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Radarr", platformLocation); } public getRootFolders(settings: IRadarrSettings): Observable { - return this.http.post(`${this.url}/RootFolders/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}/RootFolders/`, JSON.stringify(settings), {headers: this.headers}); } public getQualityProfiles(settings: IRadarrSettings): Observable { - return this.http.post(`${this.url}/Profiles/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}/Profiles/`, JSON.stringify(settings), {headers: this.headers}); } public getRootFoldersFromSettings(): Observable { - return this.http.get(`${this.url}/RootFolders/`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}/RootFolders/`, {headers: this.headers}); } public getQualityProfilesFromSettings(): Observable { - return this.http.get(`${this.url}/Profiles/`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}/Profiles/`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/applications/sonarr.service.ts b/src/Ombi/ClientApp/app/services/applications/sonarr.service.ts index 6ccf53318..20b67fd9e 100644 --- a/src/Ombi/ClientApp/app/services/applications/sonarr.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/sonarr.service.ts @@ -1,22 +1,23 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; import { ISonarrSettings } from "../../interfaces"; import { ISonarrProfile, ISonarrRootFolder } from "../../interfaces"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; @Injectable() -export class SonarrService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class SonarrService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Sonarr", platformLocation); } public getRootFolders(settings: ISonarrSettings): Observable { - return this.http.post(`${this.url}/RootFolders/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}/RootFolders/`, JSON.stringify(settings), {headers: this.headers}); } public getQualityProfiles(settings: ISonarrSettings): Observable { - return this.http.post(`${this.url}/Profiles/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}/Profiles/`, JSON.stringify(settings), {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/applications/tester.service.ts b/src/Ombi/ClientApp/app/services/applications/tester.service.ts index 7d3c87ad5..9122eb0b9 100644 --- a/src/Ombi/ClientApp/app/services/applications/tester.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/tester.service.ts @@ -1,9 +1,10 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; -import { ServiceAuthHelpers } from "../service.helpers"; +import { ServiceHelpers } from "../service.helpers"; import { ICouchPotatoSettings, @@ -22,59 +23,59 @@ import { } from "../../interfaces"; @Injectable() -export class TesterService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class TesterService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/tester/", platformLocation); } public discordTest(settings: IDiscordNotifcationSettings): Observable { - return this.http.post(`${this.url}discord`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}discord`, JSON.stringify(settings), {headers: this.headers}); } public pushbulletTest(settings: IPushbulletNotificationSettings): Observable { - return this.http.post(`${this.url}pushbullet`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}pushbullet`, JSON.stringify(settings), {headers: this.headers}); } public pushoverTest(settings: IPushoverNotificationSettings): Observable { - return this.http.post(`${this.url}pushover`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}pushover`, JSON.stringify(settings), {headers: this.headers}); } public mattermostTest(settings: IMattermostNotifcationSettings): Observable { - return this.http.post(`${this.url}mattermost`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}mattermost`, JSON.stringify(settings), {headers: this.headers}); } public slackTest(settings: ISlackNotificationSettings): Observable { - return this.http.post(`${this.url}slack`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}slack`, JSON.stringify(settings), {headers: this.headers}); } public emailTest(settings: IEmailNotificationSettings): Observable { - return this.http.post(`${this.url}email`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}email`, JSON.stringify(settings), {headers: this.headers}); } public plexTest(settings: IPlexServer): Observable { - return this.http.post(`${this.url}plex`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}plex`, JSON.stringify(settings), {headers: this.headers}); } public embyTest(settings: IEmbyServer): Observable { - return this.http.post(`${this.url}emby`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}emby`, JSON.stringify(settings), {headers: this.headers}); } public radarrTest(settings: IRadarrSettings): Observable { - return this.http.post(`${this.url}radarr`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}radarr`, JSON.stringify(settings), {headers: this.headers}); } public sonarrTest(settings: ISonarrSettings): Observable { - return this.http.post(`${this.url}sonarr`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}sonarr`, JSON.stringify(settings), {headers: this.headers}); } public couchPotatoTest(settings: ICouchPotatoSettings): Observable { - return this.http.post(`${this.url}couchpotato`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}couchpotato`, JSON.stringify(settings), {headers: this.headers}); } public telegramTest(settings: ITelegramNotifcationSettings): Observable { - return this.http.post(`${this.url}telegram`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}telegram`, JSON.stringify(settings), {headers: this.headers}); } public sickrageTest(settings: ISickRageSettings): Observable { - return this.http.post(`${this.url}sickrage`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}sickrage`, JSON.stringify(settings), {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/identity.service.ts b/src/Ombi/ClientApp/app/services/identity.service.ts index 56f2eae01..6a58fb46f 100644 --- a/src/Ombi/ClientApp/app/services/identity.service.ts +++ b/src/Ombi/ClientApp/app/services/identity.service.ts @@ -1,66 +1,66 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; import { ICheckbox, ICreateWizardUser, IIdentityResult, IResetPasswordToken, IUpdateLocalUser, IUser } from "../interfaces"; -import { ServiceAuthHelpers } from "./service.helpers"; +import { ServiceHelpers } from "./service.helpers"; @Injectable() -export class IdentityService extends ServiceAuthHelpers { - constructor(http: AuthHttp, private regularHttp: Http, public platformLocation: PlatformLocation) { +export class IdentityService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Identity/", platformLocation); } public createWizardUser(user: ICreateWizardUser): Observable { - return this.regularHttp.post(`${this.url}Wizard/`, JSON.stringify(user), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}Wizard/`, JSON.stringify(user), {headers: this.headers}); } public getUser(): Observable { - return this.http.get(this.url).map(this.extractData).catch(this.handleError); + return this.http.get(this.url, {headers: this.headers}); } public getUserById(id: string): Observable { - return this.http.get(`${this.url}User/${id}`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}User/${id}`, {headers: this.headers}); } public getUsers(): Observable { - return this.http.get(`${this.url}Users`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}Users`, {headers: this.headers}); } public getAllAvailableClaims(): Observable { - return this.http.get(`${this.url}Claims`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}Claims`, {headers: this.headers}); } public createUser(user: IUser): Observable { - return this.http.post(this.url, JSON.stringify(user), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(this.url, JSON.stringify(user), {headers: this.headers}); } public updateUser(user: IUser): Observable { - return this.http.put(this.url, JSON.stringify(user), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.put(this.url, JSON.stringify(user), {headers: this.headers}); } public updateLocalUser(user: IUpdateLocalUser): Observable { - return this.http.put(this.url + "local", JSON.stringify(user), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.put(this.url + "local", JSON.stringify(user), {headers: this.headers}); } public deleteUser(user: IUser): Observable { - return this.http.delete(`${this.url}${user.id}`, { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.delete(`${this.url}${user.id}`, {headers: this.headers}); } public hasUserRequested(userId: string): Observable { - return this.http.get(`${this.url}userhasrequest/${userId}`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}userhasrequest/${userId}`, {headers: this.headers}); } public submitResetPassword(email: string): Observable { - return this.regularHttp.post(this.url + "reset", JSON.stringify({email}), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(this.url + "reset", JSON.stringify({email}), {headers: this.headers}); } public resetPassword(token: IResetPasswordToken): Observable { - return this.regularHttp.post(this.url + "resetpassword", JSON.stringify(token), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(this.url + "resetpassword", JSON.stringify(token), {headers: this.headers}); } public sendWelcomeEmail(user: IUser): Observable { - return this.http.post(`${this.url}welcomeEmail`, JSON.stringify(user), { headers: this.headers }).map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}welcomeEmail`, JSON.stringify(user), {headers: this.headers}); } public hasRole(role: string): boolean { diff --git a/src/Ombi/ClientApp/app/services/image.service.ts b/src/Ombi/ClientApp/app/services/image.service.ts index 8175cf9e0..022f382ca 100644 --- a/src/Ombi/ClientApp/app/services/image.service.ts +++ b/src/Ombi/ClientApp/app/services/image.service.ts @@ -1,22 +1,23 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; import { Observable } from "rxjs/Rx"; +import { HttpClient } from "@angular/common/http"; + import { IImages } from "../interfaces"; import { ServiceHelpers } from "./service.helpers"; @Injectable() export class ImageService extends ServiceHelpers { - constructor(public http: Http, public platformLocation: PlatformLocation) { + constructor(public http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Images/", platformLocation); } public getRandomBackground(): Observable { - return this.http.get(`${this.url}background/`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}background/`, {headers: this.headers}); } public getTvBanner(tvdbid: number): Observable { - return this.http.get(`${this.url}tv/${tvdbid}`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}tv/${tvdbid}`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/job.service.ts b/src/Ombi/ClientApp/app/services/job.service.ts index 1be356f39..94d73ec7e 100644 --- a/src/Ombi/ClientApp/app/services/job.service.ts +++ b/src/Ombi/ClientApp/app/services/job.service.ts @@ -1,40 +1,41 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; -import { ServiceAuthHelpers } from "./service.helpers"; +import { ServiceHelpers } from "./service.helpers"; @Injectable() -export class JobService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class JobService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Job/", platformLocation); } public forceUpdate(): Observable { - return this.http.post(`${this.url}update/`, { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}update/`, {headers: this.headers}); } public checkForNewUpdate(): Observable { - return this.http.get(`${this.url}update/`).map(this.extractData); + return this.http.get(`${this.url}update/`, {headers: this.headers}); } public getCachedUpdate(): Observable { - return this.http.get(`${this.url}updateCached/`).map(this.extractData); + return this.http.get(`${this.url}updateCached/`, {headers: this.headers}); } public runPlexImporter(): Observable { - return this.http.post(`${this.url}plexUserImporter/`, { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}plexUserImporter/`, {headers: this.headers}); } public runEmbyImporter(): Observable { - return this.http.post(`${this.url}embyUserImporter/`, { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}embyUserImporter/`, {headers: this.headers}); } public runPlexCacher(): Observable { - return this.http.post(`${this.url}plexcontentcacher/`, { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}plexcontentcacher/`, {headers: this.headers}); } public runEmbyCacher(): Observable { - return this.http.post(`${this.url}embycontentcacher/`, { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}embycontentcacher/`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/landingpage.service.ts b/src/Ombi/ClientApp/app/services/landingpage.service.ts index c6bbfbce6..6cac16037 100644 --- a/src/Ombi/ClientApp/app/services/landingpage.service.ts +++ b/src/Ombi/ClientApp/app/services/landingpage.service.ts @@ -1,18 +1,19 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; import { Observable } from "rxjs/Rx"; +import { HttpClient } from "@angular/common/http"; + import { IMediaServerStatus } from "../interfaces"; import { ServiceHelpers } from "./service.helpers"; @Injectable() export class LandingPageService extends ServiceHelpers { - constructor(public http: Http, public platformLocation: PlatformLocation) { + constructor(public http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/LandingPage/", platformLocation); } public getServerStatus(): Observable { - return this.http.get(`${this.url}`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index 83b722674..ba3f0a860 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -1,125 +1,110 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; import { TreeNode } from "primeng/primeng"; import { IRequestEngineResult } from "../interfaces"; -import { IChildRequests, IMovieRequests, IMovieUpdateModel, IRequestCountModel, IRequestGrid, ITvRequests, ITvUpdateModel } from "../interfaces"; +import { IChildRequests, IMovieRequests, IMovieUpdateModel, ITvRequests, ITvUpdateModel } from "../interfaces"; import { ISearchMovieResult } from "../interfaces"; import { ISearchTvResult } from "../interfaces"; -import { ServiceAuthHelpers } from "./service.helpers"; +import { ServiceHelpers } from "./service.helpers"; @Injectable() -export class RequestService extends ServiceAuthHelpers { - constructor(http: AuthHttp, private basicHttp: Http, public platformLocation: PlatformLocation) { +export class RequestService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/Request/", platformLocation); } public requestMovie(movie: ISearchMovieResult): Observable { - return this.http.post(`${this.url}Movie/`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}Movie/`, JSON.stringify(movie), {headers: this.headers}); } public requestTv(tv: ISearchTvResult): Observable { - return this.http.post(`${this.url}TV/`, JSON.stringify(tv), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}TV/`, JSON.stringify(tv), {headers: this.headers}); } public approveMovie(movie: IMovieUpdateModel): Observable { - return this.http.post(`${this.url}Movie/Approve`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}Movie/Approve`, JSON.stringify(movie), {headers: this.headers}); } public denyMovie(movie: IMovieUpdateModel): Observable { - return this.http.put(`${this.url}Movie/Deny`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.put(`${this.url}Movie/Deny`, JSON.stringify(movie), {headers: this.headers}); } public markMovieAvailable(movie: IMovieUpdateModel): Observable { - return this.http.post(`${this.url}Movie/available`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}Movie/available`, JSON.stringify(movie), {headers: this.headers}); } public markMovieUnavailable(movie: IMovieUpdateModel): Observable { - return this.http.post(`${this.url}Movie/unavailable`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}Movie/unavailable`, JSON.stringify(movie), {headers: this.headers}); } public getMovieRequests(count: number, position: number): Observable { - return this.http.get(`${this.url}movie/${count}/${position}`).map(this.extractData); + return this.http.get(`${this.url}movie/${count}/${position}`, {headers: this.headers}); } public searchMovieRequests(search: string): Observable { - return this.http.get(`${this.url}movie/search/${search}`).map(this.extractData); + return this.http.get(`${this.url}movie/search/${search}`, {headers: this.headers}); } public removeMovieRequest(request: IMovieRequests) { - this.http.delete(`${this.url}movie/${request.id}`).map(this.extractData).subscribe(); + this.http.delete(`${this.url}movie/${request.id}`, {headers: this.headers}).subscribe(); } public updateMovieRequest(request: IMovieRequests): Observable { - return this.http.put(`${this.url}movie/`, JSON.stringify(request), { headers: this.headers }).map(this.extractData); + return this.http.put(`${this.url}movie/`, JSON.stringify(request), {headers: this.headers}); } public getTvRequests(count: number, position: number): Observable { - return this.http.get(`${this.url}tv/${count}/${position}`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}tv/${count}/${position}`, {headers: this.headers}); } public getTvRequestsTree(count: number, position: number): Observable { - return this.http.get(`${this.url}tv/${count}/${position}/tree`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}tv/${count}/${position}/tree`, {headers: this.headers}); } public getChildRequests(requestId: number): Observable { - return this.http.get(`${this.url}tv/${requestId}/child`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}tv/${requestId}/child`, {headers: this.headers}); } public searchTvRequests(search: string): Observable { - return this.http.get(`${this.url}tv/search/${search}`).map(this.extractData); + return this.http.get(`${this.url}tv/search/${search}`, {headers: this.headers}); } public searchTvRequestsTree(search: string): Observable { - return this.http.get(`${this.url}tv/search/${search}/tree`).map(this.extractData); + return this.http.get(`${this.url}tv/search/${search}/tree`, {headers: this.headers}); } public removeTvRequest(request: ITvRequests) { - this.http.delete(`${this.url}tv/${request.id}`).map(this.extractData).subscribe(); + this.http.delete(`${this.url}tv/${request.id}`, {headers: this.headers}).subscribe(); } public markTvAvailable(movie: ITvUpdateModel): Observable { - return this.http.post(`${this.url}tv/available`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}tv/available`, JSON.stringify(movie), {headers: this.headers}); } public markTvUnavailable(movie: ITvUpdateModel): Observable { - return this.http.post(`${this.url}tv/unavailable`, JSON.stringify(movie), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}tv/unavailable`, JSON.stringify(movie), {headers: this.headers}); } public updateTvRequest(request: ITvRequests): Observable { - return this.http.put(`${this.url}tv/`, JSON.stringify(request), { headers: this.headers }).map(this.extractData); + return this.http.put(`${this.url}tv/`, JSON.stringify(request), {headers: this.headers}); } public updateChild(child: IChildRequests): Observable { - return this.http.put(`${this.url}tv/child`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + return this.http.put(`${this.url}tv/child`, JSON.stringify(child), {headers: this.headers}); } public denyChild(child: ITvUpdateModel): Observable { - return this.http.put(`${this.url}tv/deny`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + return this.http.put(`${this.url}tv/deny`, JSON.stringify(child), {headers: this.headers}); } public approveChild(child: ITvUpdateModel): Observable { - return this.http.post(`${this.url}tv/approve`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + return this.http.post(`${this.url}tv/approve`, JSON.stringify(child), {headers: this.headers}); } public deleteChild(child: IChildRequests): Observable { - return this.http.delete(`${this.url}tv/child/${child.id}`, { headers: this.headers }).map(this.extractData); - } - - public getRequestsCount(): Observable { - return this.basicHttp.get(`${this.url}count`).map(this.extractData); - } - - public getMovieGrid(): Observable> { - return this.http.get(`${this.url}movie/grid`).map(this.extractData); - } - - public getTvGrid(): Observable> { - return this.http.get(`${this.url}tv/grid`).map(this.extractData); + return this.http.delete(`${this.url}tv/child/${child.id}`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/search.service.ts b/src/Ombi/ClientApp/app/services/search.service.ts index db9a65f58..859f01240 100644 --- a/src/Ombi/ClientApp/app/services/search.service.ts +++ b/src/Ombi/ClientApp/app/services/search.service.ts @@ -1,67 +1,68 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { AuthHttp } from "angular2-jwt"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; import { TreeNode } from "primeng/primeng"; import { ISearchMovieResult } from "../interfaces"; import { ISearchTvResult } from "../interfaces"; -import { ServiceAuthHelpers } from "./service.helpers"; +import { ServiceHelpers } from "./service.helpers"; @Injectable() -export class SearchService extends ServiceAuthHelpers { - constructor(http: AuthHttp, public platformLocation: PlatformLocation) { +export class SearchService extends ServiceHelpers { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/search", platformLocation); } // Movies public searchMovie(searchTerm: string): Observable { - return this.http.get(`${this.url}/Movie/` + searchTerm).map(this.extractData); + return this.http.get(`${this.url}/Movie/` + searchTerm); } public popularMovies(): Observable { - return this.http.get(`${this.url}/Movie/Popular`).map(this.extractData); + return this.http.get(`${this.url}/Movie/Popular`); } public upcomingMovies(): Observable { - return this.http.get(`${this.url}/Movie/upcoming`).map(this.extractData); + return this.http.get(`${this.url}/Movie/upcoming`); } public nowPlayingMovies(): Observable { - return this.http.get(`${this.url}/Movie/nowplaying`).map(this.extractData); + return this.http.get(`${this.url}/Movie/nowplaying`); } public topRatedMovies(): Observable { - return this.http.get(`${this.url}/Movie/toprated`).map(this.extractData); + return this.http.get(`${this.url}/Movie/toprated`); } public getMovieInformation(theMovieDbId: number): Observable { - return this.http.get(`${this.url}/Movie/info/${theMovieDbId}`).map(this.extractData); + return this.http.get(`${this.url}/Movie/info/${theMovieDbId}`); } // TV public searchTv(searchTerm: string): Observable { - return this.http.get(`${this.url}/Tv/` + searchTerm).map(this.extractData); + return this.http.get(`${this.url}/Tv/${searchTerm}`, {headers: this.headers}); } public searchTvTreeNode(searchTerm: string): Observable { - return this.http.get(`${this.url}/Tv/${searchTerm}/tree`).map(this.extractData); + return this.http.get(`${this.url}/Tv/${searchTerm}/tree`, {headers: this.headers}); } public getShowInformationTreeNode(theTvDbId: number): Observable { - return this.http.get(`${this.url}/Tv/info/${theTvDbId}/Tree`).map(this.extractData); + return this.http.get(`${this.url}/Tv/info/${theTvDbId}/Tree`, {headers: this.headers}); } public getShowInformation(theTvDbId: number): Observable { - return this.http.get(`${this.url}/Tv/info/${theTvDbId}`).map(this.extractData); + return this.http.get(`${this.url}/Tv/info/${theTvDbId}`, {headers: this.headers}); } public popularTv(): Observable { - return this.http.get(`${this.url}/Tv/popular`).map(this.extractData); + return this.http.get(`${this.url}/Tv/popular`, {headers: this.headers}); } public mostWatchedTv(): Observable { - return this.http.get(`${this.url}/Tv/mostwatched`).map(this.extractData); + return this.http.get(`${this.url}/Tv/mostwatched`, {headers: this.headers}); } public anticipatedTv(): Observable { - return this.http.get(`${this.url}/Tv/anticipated`).map(this.extractData); + return this.http.get(`${this.url}/Tv/anticipated`, {headers: this.headers}); } public trendingTv(): Observable { - return this.http.get(`${this.url}/Tv/trending`).map(this.extractData); + return this.http.get(`${this.url}/Tv/trending`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/service.helpers.ts b/src/Ombi/ClientApp/app/services/service.helpers.ts index 78f58e638..dc8c33414 100644 --- a/src/Ombi/ClientApp/app/services/service.helpers.ts +++ b/src/Ombi/ClientApp/app/services/service.helpers.ts @@ -1,82 +1,15 @@ import { PlatformLocation } from "@angular/common"; -import { Headers, Http, Response } from "@angular/http"; +import { HttpClient, HttpHeaders } from "@angular/common/http"; import "rxjs/add/observable/throw"; -import { AuthHttp } from "angular2-jwt"; - export class ServiceHelpers { - protected headers: Headers; - - constructor(protected http: Http, protected url: string, protected platformLocation: PlatformLocation) { + protected headers = new HttpHeaders(); + constructor(protected http: HttpClient, protected url: string, protected platformLocation: PlatformLocation) { const base = platformLocation.getBaseHrefFromDOM(); + this.headers = new HttpHeaders().set("Content-Type","application/json"); if (base.length > 1) { this.url = base + this.url; } - this.headers = new Headers(); - this.headers.append("Content-Type", "application/json; charset=utf-8"); - } - - protected extractData(res: Response) { - const body = res.json(); - //console.log('extractData', body || {}); - return body; - } - - protected handleError(error: Response | any) { - let errMsg: string; - if (error instanceof Response) { - const body = error.json() || ""; - const err = body.error || JSON.stringify(body); - errMsg = `${error.status} - ${error.statusText || ""} ${err}`; - } else { - errMsg = error.message ? error.message : error.toString(); - } - console.error(errMsg); - return errMsg; - } -} - -export class ServiceAuthHelpers { - - protected headers: Headers; - - constructor(protected http: AuthHttp, protected url: string, protected platformLocation: PlatformLocation) { - const base = platformLocation.getBaseHrefFromDOM(); - if (base.length > 1) { - this.url = base + this.url; - } - this.headers = new Headers(); - this.headers.append("Content-Type", "application/json; charset=utf-8"); - } - - protected extractData(res: Response) { - if(res.text()) { - const body = res.json(); - return body; - } else { - return ""; - } - } - - protected extractContentData(res: Response) { - if(res.text()) { - return res.text(); - } else { - return ""; - } - } - - protected handleError(error: Response | any) { - let errMsg: string; - if (error instanceof Response) { - const body = error.json() || ""; - const err = body.error || JSON.stringify(body); - errMsg = `${error.status} - ${error.statusText || ""} ${err}`; - } else { - errMsg = error.Message ? error.message : error.toString(); - } - console.error(errMsg); - return errMsg; } } diff --git a/src/Ombi/ClientApp/app/services/settings.service.ts b/src/Ombi/ClientApp/app/services/settings.service.ts index babb4c444..2868281f2 100644 --- a/src/Ombi/ClientApp/app/services/settings.service.ts +++ b/src/Ombi/ClientApp/app/services/settings.service.ts @@ -1,7 +1,6 @@ import { PlatformLocation } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; -import { AuthHttp } from "angular2-jwt"; import { Observable } from "rxjs/Rx"; import { @@ -30,236 +29,208 @@ import { IUserManagementSettings, } from "../interfaces"; -import { ServiceAuthHelpers } from "./service.helpers"; +import { ServiceHelpers } from "./service.helpers"; @Injectable() -export class SettingsService extends ServiceAuthHelpers { - constructor(public httpAuth: AuthHttp, private nonAuthHttp: Http, - public platformLocation: PlatformLocation) { - super(httpAuth, "/api/v1/Settings", platformLocation); +export class SettingsService extends ServiceHelpers { + constructor(public http: HttpClient, public platformLocation: PlatformLocation) { + super(http, "/api/v1/Settings", platformLocation); } public about(): Observable { - return this.httpAuth.get(`${this.url}/About/`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/About/`, {headers: this.headers}); } public getOmbi(): Observable { - return this.httpAuth.get(`${this.url}/Ombi/`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/Ombi/`, {headers: this.headers}); } public saveOmbi(settings: IOmbiSettings): Observable { - return this.httpAuth.post(`${this.url}/Ombi/`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Ombi/`, JSON.stringify(settings), {headers: this.headers}); } public resetOmbiApi(): Observable { - return this.httpAuth.post(`${this.url}/Ombi/resetApi`, { headers: this.headers }).map(this.extractData) - .catch(this.handleError); + return this.http.post(`${this.url}/Ombi/resetApi`, {headers: this.headers}); } public getEmby(): Observable { - return this.httpAuth.get(`${this.url}/Emby/`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/Emby/`); } public saveEmby(settings: IEmbySettings): Observable { - return this.httpAuth.post(`${this.url}/Emby/`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Emby/`, JSON.stringify(settings), {headers: this.headers}); } public getPlex(): Observable { - return this.httpAuth.get(`${this.url}/Plex/`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/Plex/`, {headers: this.headers}); } public savePlex(settings: IPlexSettings): Observable { - return this.httpAuth.post(`${this.url}/Plex/`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Plex/`, JSON.stringify(settings), {headers: this.headers}); } public getSonarr(): Observable { - return this.httpAuth.get(`${this.url}/Sonarr`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}/Sonarr`, {headers: this.headers}); } public saveSonarr(settings: ISonarrSettings): Observable { - return this.httpAuth.post(`${this.url}/Sonarr`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Sonarr`, JSON.stringify(settings), {headers: this.headers}); } public getRadarr(): Observable { - return this.httpAuth.get(`${this.url}/Radarr`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}/Radarr`, {headers: this.headers}); } public saveRadarr(settings: IRadarrSettings): Observable { - return this.httpAuth.post(`${this.url}/Radarr`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Radarr`, JSON.stringify(settings), {headers: this.headers}); } public getAuthentication(): Observable { - return this.httpAuth.get(`${this.url}/Authentication`).map(this.extractData) - .catch(this.handleError); + return this.http.get(`${this.url}/Authentication`, {headers: this.headers}); } public saveAuthentication(settings: IAuthenticationSettings): Observable { - return this.httpAuth.post(`${this.url}/Authentication`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/Authentication`, JSON.stringify(settings), {headers: this.headers}); } // Using http since we need it not to be authenticated to get the landing page settings public getLandingPage(): Observable { - return this.nonAuthHttp.get(`${this.url}/LandingPage`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/LandingPage`, {headers: this.headers}); } public saveLandingPage(settings: ILandingPageSettings): Observable { - return this.httpAuth.post(`${this.url}/LandingPage`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/LandingPage`, JSON.stringify(settings), {headers: this.headers}); } // Using http since we need it not to be authenticated to get the customization settings public getCustomization(): Observable { - return this.nonAuthHttp.get(`${this.url}/customization`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/customization`, {headers: this.headers}); } public saveCustomization(settings: ICustomizationSettings): Observable { - return this.httpAuth.post(`${this.url}/customization`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/customization`, JSON.stringify(settings), {headers: this.headers}); } public getThemes(): Observable { - return this.httpAuth.get(`${this.url}/themes`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/themes`, {headers: this.headers}); } public getThemeContent(themeUrl: string): Observable { - return this.httpAuth.get(`${this.url}/themecontent?url=${themeUrl}`).map(this.extractContentData).catch(this.handleError); + return this.http.get(`${this.url}/themecontent?url=${themeUrl}`, {headers: this.headers}); } public getEmailNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/email`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/email`, {headers: this.headers}); } public getEmailSettingsEnabled(): Observable { - return this.nonAuthHttp.get(`${this.url}/notifications/email/enabled`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/email/enabled`, {headers: this.headers}); } public saveEmailNotificationSettings(settings: IEmailNotificationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/email`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/notifications/email`, JSON.stringify(settings), {headers: this.headers}); } public getDiscordNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/discord`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/discord`, {headers: this.headers}); } public getMattermostNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/mattermost`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/mattermost`, {headers: this.headers}); } public saveDiscordNotificationSettings(settings: IDiscordNotifcationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/discord`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/notifications/discord`, JSON.stringify(settings), {headers: this.headers}); } public saveMattermostNotificationSettings(settings: IMattermostNotifcationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/mattermost`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http.post(`${this.url}/notifications/mattermost`, JSON.stringify(settings), {headers: this.headers}); } public getPushbulletNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/pushbullet`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/pushbullet`, {headers: this.headers}); } public getPushoverNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/pushover`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/pushover`, {headers: this.headers}); } public savePushbulletNotificationSettings(settings: IPushbulletNotificationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/pushbullet`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/notifications/pushbullet`, JSON.stringify(settings), {headers: this.headers}); } public savePushoverNotificationSettings(settings: IPushoverNotificationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/pushover`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/notifications/pushover`, JSON.stringify(settings), {headers: this.headers}); } public getSlackNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/slack`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/slack`, {headers: this.headers}); } public saveSlackNotificationSettings(settings: ISlackNotificationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/slack`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/notifications/slack`, JSON.stringify(settings), {headers: this.headers}); } public getUpdateSettings(): Observable { - return this.httpAuth.get(`${this.url}/update`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/update`, {headers: this.headers}); } public saveUpdateSettings(settings: IUpdateSettings): Observable { - return this.httpAuth - .post(`${this.url}/update`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/update`, JSON.stringify(settings), {headers: this.headers}); } public getUserManagementSettings(): Observable { - return this.httpAuth.get(`${this.url}/UserManagement`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/UserManagement`, {headers: this.headers}); } public saveUserManagementSettings(settings: IUserManagementSettings): Observable { - return this.httpAuth - .post(`${this.url}/UserManagement`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/UserManagement`, JSON.stringify(settings), {headers: this.headers}); } public getCouchPotatoSettings(): Observable { - return this.httpAuth.get(`${this.url}/CouchPotato`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/CouchPotato`, {headers: this.headers}); } public saveCouchPotatoSettings(settings: ICouchPotatoSettings): Observable { - return this.httpAuth - .post(`${this.url}/CouchPotato`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/CouchPotato`, JSON.stringify(settings), {headers: this.headers}); } public getDogNzbSettings(): Observable { - return this.httpAuth.get(`${this.url}/DogNzb`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/DogNzb`, {headers: this.headers}); } public saveDogNzbSettings(settings: IDogNzbSettings): Observable { - return this.httpAuth - .post(`${this.url}/DogNzb`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/DogNzb`, JSON.stringify(settings), {headers: this.headers}); } public getTelegramNotificationSettings(): Observable { - return this.httpAuth.get(`${this.url}/notifications/telegram`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/notifications/telegram`, {headers: this.headers}); } public saveTelegramNotificationSettings(settings: ITelegramNotifcationSettings): Observable { - return this.httpAuth - .post(`${this.url}/notifications/telegram`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/notifications/telegram`, JSON.stringify(settings), {headers: this.headers}); } public getJobSettings(): Observable { - return this.httpAuth.get(`${this.url}/jobs`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/jobs`, {headers: this.headers}); } public saveJobSettings(settings: IJobSettings): Observable { - return this.httpAuth - .post(`${this.url}/jobs`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/jobs`, JSON.stringify(settings), {headers: this.headers}); } public getSickRageSettings(): Observable { - return this.httpAuth.get(`${this.url}/sickrage`).map(this.extractData).catch(this.handleError); + return this.http.get(`${this.url}/sickrage`, {headers: this.headers}); } public saveSickRageSettings(settings: ISickRageSettings): Observable { - return this.httpAuth - .post(`${this.url}/sickrage`, JSON.stringify(settings), { headers: this.headers }) - .map(this.extractData).catch(this.handleError); + return this.http + .post(`${this.url}/sickrage`, JSON.stringify(settings), {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/services/status.service.ts b/src/Ombi/ClientApp/app/services/status.service.ts index 499e0e954..9e84dac4b 100644 --- a/src/Ombi/ClientApp/app/services/status.service.ts +++ b/src/Ombi/ClientApp/app/services/status.service.ts @@ -1,16 +1,17 @@ import { PlatformLocation } from "@angular/common"; import { Injectable } from "@angular/core"; -import { Http } from "@angular/http"; + +import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs/Rx"; import { ServiceHelpers } from "./service.helpers"; @Injectable() export class StatusService extends ServiceHelpers { - constructor(http: Http, public platformLocation: PlatformLocation) { + constructor(http: HttpClient, public platformLocation: PlatformLocation) { super(http, "/api/v1/status/", platformLocation); } public getWizardStatus(): Observable { - return this.http.get(`${this.url}Wizard/`, { headers: this.headers }).map(this.extractData); + return this.http.get(`${this.url}Wizard/`, {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/settings/settings.module.ts b/src/Ombi/ClientApp/app/settings/settings.module.ts index f7062ade7..651d0e033 100644 --- a/src/Ombi/ClientApp/app/settings/settings.module.ts +++ b/src/Ombi/ClientApp/app/settings/settings.module.ts @@ -6,7 +6,6 @@ import { NgbAccordionModule, NgbModule } from "@ng-bootstrap/ng-bootstrap"; import { ClipboardModule } from "ngx-clipboard/dist"; import { AuthGuard } from "../auth/auth.guard"; -import { AuthModule } from "../auth/auth.module"; import { AuthService } from "../auth/auth.service"; import { CouchPotatoService, JobService, RadarrService, SonarrService, TesterService, ValidationService } from "../services"; @@ -72,7 +71,6 @@ const routes: Routes = [ MenuModule, InputSwitchModule, InputTextModule, - AuthModule, NgbModule, TooltipModule, NgbAccordionModule, diff --git a/src/Ombi/package-lock.json b/src/Ombi/package-lock.json index efbf2d2ec..725ac5729 100644 --- a/src/Ombi/package-lock.json +++ b/src/Ombi/package-lock.json @@ -102,6 +102,11 @@ "tslib": "1.8.0" } }, + "@auth0/angular-jwt": { + "version": "1.0.0-beta.9", + "resolved": "https://registry.npmjs.org/@auth0/angular-jwt/-/angular-jwt-1.0.0-beta.9.tgz", + "integrity": "sha1-ZQIsNJ7ck97DMS+TO5VccZ6GKmI=" + }, "@ng-bootstrap/ng-bootstrap": { "version": "1.0.0-beta.5", "resolved": "https://registry.npmjs.org/@ng-bootstrap/ng-bootstrap/-/ng-bootstrap-1.0.0-beta.5.tgz", @@ -266,11 +271,6 @@ "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" }, - "angular2-jwt": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/angular2-jwt/-/angular2-jwt-0.2.3.tgz", - "integrity": "sha1-VO/do87tuoX2o3sWXyKsIrit8CE=" - }, "angular2-moment": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/angular2-moment/-/angular2-moment-1.7.0.tgz", diff --git a/src/Ombi/package.json b/src/Ombi/package.json index 6abb2256b..c1a4807c1 100644 --- a/src/Ombi/package.json +++ b/src/Ombi/package.json @@ -21,6 +21,7 @@ "@angular/platform-browser-dynamic": "^5.0.3", "@angular/platform-server": "5.0.0", "@angular/router": "^5.0.3", + "@auth0/angular-jwt": "^1.0.0-beta.9", "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", "@ngx-translate/core": "^8.0.0", "@ngx-translate/http-loader": "^2.0.0", @@ -29,7 +30,6 @@ "@types/intro.js": "^2.4.3", "@types/node": "^8.0.53", "@types/webpack": "^3.8.1", - "angular2-jwt": "^0.2.3", "angular2-moment": "^1.7.0", "angular2-template-loader": "^0.6.2", "aspnet-webpack": "^2.0.1", diff --git a/src/Ombi/webpack.config.vendor.ts b/src/Ombi/webpack.config.vendor.ts index 4dec9177d..36947d6ae 100644 --- a/src/Ombi/webpack.config.vendor.ts +++ b/src/Ombi/webpack.config.vendor.ts @@ -62,7 +62,7 @@ module.exports = (env: any) => { "event-source-polyfill", "bootstrap/dist/js/bootstrap", "ngx-clipboard", - "angular2-jwt", + "@auth0/angular-jwt", "ng2-cookies", "@ngx-translate/core", "@ngx-translate/http-loader",