diff --git a/src/apis/auth.php b/src/apis/auth.php new file mode 100755 index 0000000..581c326 --- /dev/null +++ b/src/apis/auth.php @@ -0,0 +1,29 @@ +status = 404; + +if(isset($_POST['act']) && $_POST['act'] == 'auth') { + if($_POST['usr'] == 'admin' && $_POST['pwd'] == 'JohnHolmes') { + $content->status = 200; + $content->authToken = md5(date("Y-m-d")); + } else { + $content->status = 403; + } +} else if(isset($_POST['act']) && $_POST['act'] == 'check') { + if($_POST['token'] == md5(date("Y-m-d"))) { + $content->status = 200; + $content->authToken = md5(date("Y-m-d")); + } else { + $content->status = 403; + } +} + +header('Access-Control-Allow-Origin: *'); +header('Content-Type: application/json'); +echo json_encode($content); + +?> diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html new file mode 100644 index 0000000..717bddf --- /dev/null +++ b/src/app/admin/admin.component.html @@ -0,0 +1,28 @@ +
+
+
+ +
+
+ +
+ +
+
diff --git a/src/app/admin/admin.component.scss b/src/app/admin/admin.component.scss new file mode 100644 index 0000000..08ad394 --- /dev/null +++ b/src/app/admin/admin.component.scss @@ -0,0 +1,58 @@ +@import "../../assets/scss/variables"; + +.component-admin { + + .login-form-container { + text-align: center; + padding: 40px; + color: $white; + + .input { + width: 100%; + } + + .button { + background: $black; + } + } + + .menu { + background: $dark-gray; + + .section-title { + display: block; + width: 100%; + padding: 50px 10px 10px; + font-size: $font-22; + font-weight: bolder; + text-transform: uppercase; + color: $white; + text-align: center; + border-bottom: 1px dotted $white-alpha; + } + + .action { + display: block; + appearance: none; + border: none; + width: 100%; + padding: 10px; + font-size: $font-14; + text-transform: uppercase; + color: $white; + background: $dark-gray; + cursor: pointer; + border-bottom: 1px dotted $white-alpha; + } + } +} + +@media (min-width: map-get($grid-breakpoints, 'md')) { + .component-admin { + .menu { + height: 100vh; + background: $dark-gray; + } + } + +} diff --git a/src/app/admin/admin.component.spec.ts b/src/app/admin/admin.component.spec.ts new file mode 100644 index 0000000..72e742f --- /dev/null +++ b/src/app/admin/admin.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AdminComponent } from './admin.component'; + +describe('AdminComponent', () => { + let component: AdminComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AdminComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AdminComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts new file mode 100644 index 0000000..18082e0 --- /dev/null +++ b/src/app/admin/admin.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit } from '@angular/core' +import { AuthService } from '../services/auth.service' + +@Component({ + selector: 'app-admin', + templateUrl: './admin.component.html', + styleUrls: ['./admin.component.scss'] +}) +export class AdminComponent implements OnInit { + + public authCheck: boolean = false + + constructor(private authService: AuthService) { } + + ngOnInit(): void { + + const body = { + token: window.sessionStorage.getItem('authToken') + } + + this.authService.authCheck(body).toPromise().then((response) => { + this.authCheck = response.status == 200 + },(error) => { + console.error('Auth ERROR', error) + }).catch((e) => { + console.error('Auth CATCH', e) + }) + } + + + login(): void { + + const body = { + usr: 'admin', + pwd: 'JohnHolmes' + } + this.authService.login(body).toPromise().then((response) => { + this.authCheck = response.status == 200 + if(this.authCheck) { + window.sessionStorage.setItem('authToken', response.authToken) + } + },(error) => { + console.error('Auth ERROR', error) + }).catch((e) => { + console.error('Auth CATCH', e) + }) + + } +} diff --git a/src/app/app-layout/app-layout.component.html b/src/app/app-layout/app-layout.component.html index 10a7dc1..89a86da 100644 --- a/src/app/app-layout/app-layout.component.html +++ b/src/app/app-layout/app-layout.component.html @@ -1,4 +1,5 @@ - + - + diff --git a/src/app/app-layout/app-layout.component.ts b/src/app/app-layout/app-layout.component.ts index 0b874c6..956d7d3 100644 --- a/src/app/app-layout/app-layout.component.ts +++ b/src/app/app-layout/app-layout.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core' +import { Router } from '@angular/router' import type { Container } from 'tsparticles' @Component({ @@ -8,6 +9,7 @@ import type { Container } from 'tsparticles' }) export class AppLayoutComponent implements OnInit { + public page: string = '/' public particlesEnabled: boolean = false public id: string = 'tsparticles' @@ -90,9 +92,10 @@ export class AppLayoutComponent implements OnInit { detectRetina: true } - constructor() { } + constructor(private router: Router) { } ngOnInit(): void { + this.page = this.router.url } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 83b3dbc..453d579 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import { AppLayoutComponent } from './app-layout/app-layout.component' import { AboutComponent } from './about/about.component' import { PortfolioComponent } from './portfolio/portfolio.component' import { DetailComponent } from './detail/detail.component' +import { AdminComponent } from './admin/admin.component' const routes: Routes = [ { @@ -27,8 +28,8 @@ const routes: Routes = [ ] } ] - } - + }, + { path: 'admin', component: AdminComponent } ] } ] diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ec33f1b..4962f37 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,6 +11,7 @@ import { AppLayoutComponent } from './app-layout/app-layout.component'; import { AboutComponent } from './about/about.component'; import { PortfolioComponent } from './portfolio/portfolio.component'; import { DetailComponent } from './detail/detail.component'; +import { AdminComponent } from './admin/admin.component'; @NgModule({ declarations: [ @@ -19,7 +20,8 @@ import { DetailComponent } from './detail/detail.component'; AppLayoutComponent, AboutComponent, PortfolioComponent, - DetailComponent + DetailComponent, + AdminComponent ], imports: [ BrowserModule, diff --git a/src/app/services/apis.service.ts b/src/app/services/apis.service.ts index ce4e16d..3e02ae0 100644 --- a/src/app/services/apis.service.ts +++ b/src/app/services/apis.service.ts @@ -30,4 +30,5 @@ export class ApisService extends BaseService { ) } + } diff --git a/src/app/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts new file mode 100644 index 0000000..f1251ca --- /dev/null +++ b/src/app/services/auth.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/services/auth.service.spec.ts_ b/src/app/services/auth.service.spec.ts_ new file mode 100644 index 0000000..f1251ca --- /dev/null +++ b/src/app/services/auth.service.spec.ts_ @@ -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(); + }); +}); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts new file mode 100644 index 0000000..3ee8d3c --- /dev/null +++ b/src/app/services/auth.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@angular/core' +import { HttpClient, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http' +import { Observable, Subject, throwError } from 'rxjs' +import { catchError } from 'rxjs/operators' +import { BaseService } from './base-service' +import { environment } from '../../environments/environment' + +@Injectable({ + providedIn: 'root' +}) +export class AuthService extends BaseService { + + private restApi = `${environment.API_URL}` + + constructor(private http: HttpClient) { + super() + } + + login(body): Observable { + let urlApi = `${this.restApi}auth.php?act=login` + return this.http.post(urlApi, JSON.stringify(body)).pipe( + catchError(this.handleError) + ) + } + + authCheck(body): Observable { + let urlApi = `${this.restApi}auth.php?act=check` + return this.http.post(urlApi, JSON.stringify(body)).pipe( + catchError(this.handleError) + ) + } + +} diff --git a/src/app/services/auth.service.ts_ b/src/app/services/auth.service.ts_ new file mode 100644 index 0000000..dd4e29d --- /dev/null +++ b/src/app/services/auth.service.ts_ @@ -0,0 +1,27 @@ +import { Injectable } from '@angular/core' +import { HttpClient, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http' +import { Observable, Subject, throwError } from 'rxjs' +import { catchError } from 'rxjs/operators' +import { BaseService } from './base-service' +import { environment } from '../../environments/environment' + +@Injectable({ + providedIn: 'root' +}) +export class AuthService extends BaseService { + + private restApi = `${environment.API_URL}` + + constructor(private http: HttpClient) { + super() + } + + login(body): Observable { + let urlApi = `${this.restApi}auth.php` + return this.http.post(urlApi, body).pipe( + catchError(this.handleError) + ) + } + + +}