14 changed files with 295 additions and 6 deletions
@ -0,0 +1,29 @@ |
|||
<?php |
|||
@include 'conn.conn'; |
|||
$GLOBALS['conn']; |
|||
$conn=@mysqli_connect($DATAhst,$DATAusr,$DATApwd,$DATAdtb)or die("CONNECTION ERROR"); |
|||
|
|||
$content = null; |
|||
$content->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); |
|||
|
|||
?> |
@ -0,0 +1,28 @@ |
|||
<div class="component-admin"> |
|||
<div class="row no-gutters" *ngIf="!authCheck"> |
|||
<div class="col-12 col-md-6 mx-auto"> |
|||
<div class="login-form-container"> |
|||
<div class="m-2"> |
|||
<span class="font-12">Username</span> |
|||
<input type="text" class="input"> |
|||
</div> |
|||
<div class="m-2"> |
|||
<span class="font-12">Password</span> |
|||
<input type="password" class="input"> |
|||
</div> |
|||
<div class="m-2"> |
|||
<button type="button" class="button">Sign-in</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="row no-gutters" *ngIf="authCheck"> |
|||
<div class="col-12 col-md-3 col-lg-2 menu" > |
|||
<span class="section-title">Works</span> |
|||
<button class="action">Add</button> |
|||
<button class="action">Add</button> |
|||
<button class="action">Add</button> |
|||
</div> |
|||
</div> |
|||
</div> |
@ -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; |
|||
} |
|||
} |
|||
|
|||
} |
@ -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<AdminComponent>; |
|||
|
|||
beforeEach(async(() => { |
|||
TestBed.configureTestingModule({ |
|||
declarations: [ AdminComponent ] |
|||
}) |
|||
.compileComponents(); |
|||
})); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(AdminComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
@ -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) |
|||
}) |
|||
|
|||
} |
|||
} |
@ -1,4 +1,5 @@ |
|||
<app-header></app-header> |
|||
<app-header *ngIf="page != '/admin'"></app-header> |
|||
<router-outlet></router-outlet> |
|||
|
|||
<Particles class="particles" [id]="id" [options]="particlesOptions" (particlesLoaded)="particlesLoaded($event)" *ngIf="particlesEnabled"></Particles> |
|||
<Particles class="particles" *ngIf="particlesEnabled && page != '/admin'" |
|||
[id]="id" [options]="particlesOptions" (particlesLoaded)="particlesLoaded($event)"></Particles> |
|||
|
@ -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,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 { 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<any> { |
|||
let urlApi = `${this.restApi}auth.php?act=login` |
|||
return this.http.post<any>(urlApi, JSON.stringify(body)).pipe( |
|||
catchError(this.handleError) |
|||
) |
|||
} |
|||
|
|||
authCheck(body): Observable<any> { |
|||
let urlApi = `${this.restApi}auth.php?act=check` |
|||
return this.http.post<any>(urlApi, JSON.stringify(body)).pipe( |
|||
catchError(this.handleError) |
|||
) |
|||
} |
|||
|
|||
} |
@ -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<any> { |
|||
let urlApi = `${this.restApi}auth.php` |
|||
return this.http.post<any>(urlApi, body).pipe( |
|||
catchError(this.handleError) |
|||
) |
|||
} |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue