mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
made some changes
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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([''])
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user