made some changes

This commit is contained in:
Kayaya
2020-08-06 14:31:07 +01:00
parent d25ebc0d28
commit 4e143a55a4
12 changed files with 142 additions and 115 deletions
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AuthService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+33
View File
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { StorageService } from './storage.service';
import { HttpService } from './http.service';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthConnstants } from '../config/auth-constants';
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(
private httpService: HttpService,
private storageService: StorageService,
private router: Router
) { }
login(postData: any): Observable<any> {
return this.httpService.post('login', postData);
}
signup(postData: any): Observable<any> {
return this.httpService.post('signup', postData);
}
logout(){
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
this.router.navigate([''])
})
}
}
+9 -13
View File
@@ -1,22 +1,18 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
/* import { environment } from 'src/environments/environment.prod'; */
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class HttpService {
constructor(private http: HttpClient) {}
constructor(private http: HttpClient) { }
post(serviceName: string, data: any) {
const headers = new HttpHeaders();
const options = { headers: headers, withCredintials: false };
const url = environment.apiURL + serviceName;
post(serviceName: string, data: any){
const headers = new HttpHeaders();
const options = { header: headers, withCredintials: false}
const url = environment.apiURL + serviceName;
/* const this.http.post(url, JSON.stringify(data), options); */
}
return this.http.post(url, JSON.stringify(data), options);
}
}
+24 -11
View File
@@ -1,20 +1,33 @@
import { Injectable } from '@angular/core';
import { Plugins } from '@capacitor/core';
const { Storage } = Plugins;
@Injectable({
providedIn: 'root'
})
export class StorageService {
})
export class StorageService {
constructor() {}
constructor() {
/* async store(storageKey: String, value: any){
await Storage.set({
key: storageKey,
value: value
})
// Store the value
async store(storageKey: string, value: any) {
const encryptedValue = btoa(escape(JSON.stringify(value)));
await Storage.set({
key: storageKey,
value: encryptedValue
});
}
} */
// Get the value
async get(storageKey: string) {
const ret = await Storage.get({ key: storageKey });
return JSON.parse(unescape(atob(ret.value)));
}
async removeStorageItem(storageKey: string) {
await Storage.remove({ key: storageKey });
}
// Clear storage
async clear() {
await Storage.clear();
}
}