Extracted frontend from webservice to new directory
Updated directory structure Updated .gitignore
This commit is contained in:
16
frontend/src/app/Services/auth.service.spec.ts
Normal file
16
frontend/src/app/Services/auth.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
30
frontend/src/app/Services/auth.service.ts
Normal file
30
frontend/src/app/Services/auth.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
const AUTH_API = 'https://aktienbot.flokaiser.com/api/';
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthService {
|
||||
constructor(private http: HttpClient) {}
|
||||
login(username: string, password: string): Observable<any> {
|
||||
return this.http.post(AUTH_API + 'login', {
|
||||
username,
|
||||
password,
|
||||
});
|
||||
}
|
||||
register(username: string, password: string): Observable<any> {
|
||||
return this.http.post(
|
||||
AUTH_API + 'signup',
|
||||
{
|
||||
username,
|
||||
password,
|
||||
},
|
||||
httpOptions
|
||||
);
|
||||
}
|
||||
}
|
16
frontend/src/app/Services/data.service.spec.ts
Normal file
16
frontend/src/app/Services/data.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DataService } from './data.service';
|
||||
|
||||
describe('DataService', () => {
|
||||
let service: DataService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DataService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
22
frontend/src/app/Services/data.service.ts
Normal file
22
frontend/src/app/Services/data.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
const API_URL = 'http://localhost:8080/api/test/';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DataService {
|
||||
constructor(private http: HttpClient) {}
|
||||
// getPublicContent(): Observable<any> {
|
||||
// return this.http.get(API_URL + 'all', { responseType: 'text' });
|
||||
// }
|
||||
// getUserBoard(): Observable<any> {
|
||||
// return this.http.get(API_URL + 'user', { responseType: 'text' });
|
||||
// }
|
||||
// getModeratorBoard(): Observable<any> {
|
||||
// return this.http.get(API_URL + 'mod', { responseType: 'text' });
|
||||
// }
|
||||
// getAdminBoard(): Observable<any> {
|
||||
// return this.http.get(API_URL + 'admin', { responseType: 'text' });
|
||||
// }
|
||||
}
|
16
frontend/src/app/Services/token.service.spec.ts
Normal file
16
frontend/src/app/Services/token.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TokenService } from './token.service';
|
||||
|
||||
describe('TokenService', () => {
|
||||
let service: TokenService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(TokenService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
30
frontend/src/app/Services/token.service.ts
Normal file
30
frontend/src/app/Services/token.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
const TOKEN_KEY = 'auth-token';
|
||||
const USER_KEY = 'auth-user';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TokenStorageService {
|
||||
constructor() {}
|
||||
signOut(): void {
|
||||
window.sessionStorage.clear();
|
||||
}
|
||||
public saveToken(token: string): void {
|
||||
window.sessionStorage.removeItem(TOKEN_KEY);
|
||||
window.sessionStorage.setItem(TOKEN_KEY, token);
|
||||
}
|
||||
public getToken(): string | null {
|
||||
return window.sessionStorage.getItem(TOKEN_KEY);
|
||||
}
|
||||
public saveUser(user: any): void {
|
||||
window.sessionStorage.removeItem(USER_KEY);
|
||||
window.sessionStorage.setItem(USER_KEY, JSON.stringify(user));
|
||||
}
|
||||
public getUser(): any {
|
||||
const user = window.sessionStorage.getItem(USER_KEY);
|
||||
if (user) {
|
||||
return JSON.parse(user);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user