From 5ac403b430daa14b391d88adf9588443e35982af Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 7 Sep 2018 23:34:17 -0400 Subject: [PATCH] clean up --- .../register-new-account.component.ts | 2 +- src/app/services/app.service.ts | 37 ++---------------- src/app/services/auth.service.ts | 38 ------------------- 3 files changed, 5 insertions(+), 72 deletions(-) diff --git a/src/app/pages/register-new-account/register-new-account.component.ts b/src/app/pages/register-new-account/register-new-account.component.ts index 5b2a0461..4951468b 100644 --- a/src/app/pages/register-new-account/register-new-account.component.ts +++ b/src/app/pages/register-new-account/register-new-account.component.ts @@ -46,7 +46,7 @@ export class RegisterNewAccountComponent implements OnInit { localStorage.removeItem('tempAuth'); //TODO review all this - this.accountsService.addNewAccount(appDataWrapper.instance, appDataWrapper.username, tokenData); + // this.accountsService.addNewAccount(appDataWrapper.instance, appDataWrapper.username, tokenData); }); diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts index ff09da31..dfde8bfc 100644 --- a/src/app/services/app.service.ts +++ b/src/app/services/app.service.ts @@ -1,34 +1,17 @@ import { Injectable } from '@angular/core'; -import { Http, Response, RequestOptions } from '@angular/http'; -import { map } from "rxjs/operators"; - import { ApiRoutes } from './models/api.settings'; import { AppData } from './models/mastodon.interfaces'; -import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; @Injectable() export class AppService { private apiRoutes = new ApiRoutes(); - constructor( - private readonly httpService: Http, - private readonly router: Router) { + constructor(private readonly httpClient: HttpClient) { } createNewApplication(instance: string, redirectUrl: string): Promise { - const url = 'https://' + instance + this.apiRoutes.createApp; - - // const redirect_uri = this.router.url; - // var redirect_uri = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: ''); - - // if(redirect_uri === 'file://'){ - // redirect_uri = 'http://localhost'; - // } - - // console.warn(`redirect_uri ${redirect_uri}`); - // return null; - - const options = new RequestOptions(); + const url = 'https://' + instance + this.apiRoutes.createApp; const formData = new FormData(); formData.append('client_name', 'Sengi'); @@ -36,18 +19,6 @@ export class AppService { formData.append('scopes', 'read write follow'); formData.append('website', 'https://github.com/NicolasConstant/sengi'); - return this.httpService.post(url, formData, options) - .pipe( - map((res: Response) => { - const result = res.json(); - console.warn(result); - return result as AppData; - })) - .toPromise(); - - // // .then((res: Response) => { - // // const result = res.json(); - // // return result as TokenData; - // // }); + return this.httpClient.post(url, formData).toPromise(); } } \ No newline at end of file diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 3ed58822..4c265a7e 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,51 +1,13 @@ import { Injectable } from "@angular/core"; -import { Http, Response, RequestOptions } from "@angular/http"; -import { ApiRoutes } from "./models/api.settings"; import { TokenData } from "./models/mastodon.interfaces"; import { HttpClient } from "@angular/common/http"; @Injectable() export class AuthService { - private apiRoutes = new ApiRoutes(); - constructor( private readonly httpClient: HttpClient) { } - // getToken(instance: string, email: string, password: string): Promise { - - // //TODO retrieve those via API - // const clientId = localStorage.getItem("client_id"); - // const clientSecret = localStorage.getItem("client_secret"); - - // //Retrieve Token - // const url = this.getHostUrl(instance) + this.apiRoutes.getToken; - - // const options = new RequestOptions(); - // const formData = new FormData(); - - // formData.append("client_id", clientId); - // formData.append("client_secret", clientSecret); - // formData.append("grant_type", "password"); - // formData.append("username", email); - // formData.append("password", password); - // formData.append("scope", "read write follow"); - - // return this.httpService.post(url, formData, options).toPromise() - // .then((res: Response) => { - // const result = res.json(); - // return result as TokenData; - // }); - // } - - // private getHostUrl(url: string): string { - // url = url.replace("http://", ""); - // if (!url.startsWith("https://")) { - // url = "https://" + url; - // } - // return url; - // } - getToken(instance: string, client_id: string, client_secret: string, code: string, redirect_uri: string): Promise { const url = `https://${instance}/oauth/token?client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent(redirect_uri)}`;