added dominika #6
@ -65,3 +65,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { Component, OnInit } from "@angular/core";
|
|||||||
import { FormControl } from "@angular/forms";
|
import { FormControl } from "@angular/forms";
|
||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
import { Observable } from "rxjs/Observable";
|
import { Observable } from "rxjs/Observable";
|
||||||
|
import {UserService} from '../user.service';
|
||||||
import "rxjs/Rx";
|
import "rxjs/Rx";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -14,7 +15,7 @@ export class AdminComponent implements OnInit {
|
|||||||
ip = new FormControl("");
|
ip = new FormControl("");
|
||||||
ipDelete = new FormControl("");
|
ipDelete = new FormControl("");
|
||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient, private user: UserService) {}
|
||||||
|
|
||||||
onAddDevice() {
|
onAddDevice() {
|
||||||
if (this.name.value.length > 0 && this.ip.value.length > 0) {
|
if (this.name.value.length > 0 && this.ip.value.length > 0) {
|
||||||
|
@ -2,13 +2,14 @@ import { NgModule } from "@angular/core";
|
|||||||
import { Routes, RouterModule } from "@angular/router";
|
import { Routes, RouterModule } from "@angular/router";
|
||||||
import { AppComponent } from "./app.component";
|
import { AppComponent } from "./app.component";
|
||||||
import { AdminComponent } from "./admin/admin.component";
|
import { AdminComponent } from "./admin/admin.component";
|
||||||
|
import { LoginComponent } from "./login/login.component";
|
||||||
import { StatusListComponent } from "./status-list/status-list.component";
|
import { StatusListComponent } from "./status-list/status-list.component";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: "", component: StatusListComponent },
|
{ path: "", component: StatusListComponent },
|
||||||
{
|
{
|
||||||
path: "admin",
|
path: "login",
|
||||||
component: AdminComponent
|
component: LoginComponent
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import { HttpClientModule } from "@angular/common/http";
|
|||||||
import { StatusListComponent } from "./status-list/status-list.component";
|
import { StatusListComponent } from "./status-list/status-list.component";
|
||||||
import { HeaderComponent } from "./header/header.component";
|
import { HeaderComponent } from "./header/header.component";
|
||||||
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
|
||||||
|
import {UserService} from './user.service';
|
||||||
import {
|
import {
|
||||||
MatAutocompleteModule,
|
MatAutocompleteModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
@ -46,15 +47,34 @@ import {
|
|||||||
} from "@angular/material";
|
} from "@angular/material";
|
||||||
import { AdminComponent } from "./admin/admin.component";
|
import { AdminComponent } from "./admin/admin.component";
|
||||||
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
||||||
|
import { LoginComponent } from './login/login.component';
|
||||||
|
import {RouterModule, Routes} from '@angular/router';
|
||||||
|
import {AuthgardGuard} from './authgard.guard';
|
||||||
|
|
||||||
|
const appRoutes:Routes = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: LoginComponent
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'admin',
|
||||||
|
component: AdminComponent,
|
||||||
|
canActivate: [AuthgardGuard]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
StatusListComponent,
|
StatusListComponent,
|
||||||
HeaderComponent,
|
HeaderComponent,
|
||||||
AdminComponent
|
AdminComponent,
|
||||||
|
LoginComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
RouterModule.forRoot(appRoutes),
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
@ -73,7 +93,7 @@ import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
|||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
MatInputModule
|
MatInputModule
|
||||||
],
|
],
|
||||||
providers: [StatusService],
|
providers: [StatusService, UserService, AuthgardGuard],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
15
src/app/authgard.guard.spec.ts
Normal file
15
src/app/authgard.guard.spec.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { TestBed, async, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthgardGuard } from './authgard.guard';
|
||||||
|
|
||||||
|
describe('AuthgardGuard', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [AuthgardGuard]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ...', inject([AuthgardGuard], (guard: AuthgardGuard) => {
|
||||||
|
expect(guard).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
16
src/app/authgard.guard.ts
Normal file
16
src/app/authgard.guard.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import {UserService} from './user.service';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthgardGuard implements CanActivate {
|
||||||
|
constructor( private user: UserService) {}
|
||||||
|
canActivate(
|
||||||
|
next: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
|
||||||
|
return this.user.getUserLoggedIn();
|
||||||
|
}
|
||||||
|
}
|
22
src/app/login/login.component.html
Normal file
22
src/app/login/login.component.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
<div style="margin-top:30px"><form (submit)="loginUser($event)">
|
||||||
|
<div class="input">
|
||||||
|
<label> Nazwa użytkownika</label>
|
||||||
|
<input type="text">
|
||||||
|
</div>
|
||||||
|
<div class="input">
|
||||||
|
<label>Hasło</label>
|
||||||
|
<input type="password">
|
||||||
|
</div>
|
||||||
|
<span style="color: red">{{ statusLog == 1
|
||||||
|
? " "
|
||||||
|
: statusLog == 2
|
||||||
|
? "Niepoprawny login lub hasło"
|
||||||
|
: " "}}</span>
|
||||||
|
<div class="input">
|
||||||
|
<input type="submit" value="Login">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
37
src/app/login/login.component.less
Normal file
37
src/app/login/login.component.less
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
:host {
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.input{
|
||||||
|
position:relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.input label {
|
||||||
|
position: absolute;
|
||||||
|
top:0;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
left:10px;
|
||||||
|
background:white;
|
||||||
|
padding: 5px 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.input input{
|
||||||
|
padding:10px 10px;
|
||||||
|
font-size:20px;
|
||||||
|
outline: 0px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
div{
|
||||||
|
margin-bottom:15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=submit]{
|
||||||
|
background-color: #0099ff;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
25
src/app/login/login.component.spec.ts
Normal file
25
src/app/login/login.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LoginComponent } from './login.component';
|
||||||
|
|
||||||
|
describe('LoginComponent', () => {
|
||||||
|
let component: LoginComponent;
|
||||||
|
let fixture: ComponentFixture<LoginComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ LoginComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(LoginComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
34
src/app/login/login.component.ts
Normal file
34
src/app/login/login.component.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import {UserService} from '../user.service';
|
||||||
|
@Component({
|
||||||
|
selector: 'app-login',
|
||||||
|
templateUrl: './login.component.html',
|
||||||
|
styleUrls: ['./login.component.less']
|
||||||
|
})
|
||||||
|
export class LoginComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(private router: Router, private user:UserService) { }
|
||||||
|
statusLog = 0;
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
loginUser(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var username = e.target.elements[0].value;
|
||||||
|
var password = e.target.elements[1].value;
|
||||||
|
|
||||||
|
if(username == 'admin' && password == 'admin'){
|
||||||
|
this.user.setUserLoggedIn();
|
||||||
|
this.router.navigate(['admin']);
|
||||||
|
this.statusLog=1;
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.statusLog=2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -110,18 +110,7 @@ table {
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.room-button:hover {
|
|
||||||
-webkit-box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
}
|
|
||||||
.room-button:active {
|
|
||||||
-webkit-box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
}
|
|
||||||
.room-button:focus {
|
|
||||||
-webkit-box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
box-shadow: inset 0 0 0 2px #24a1fc;
|
|
||||||
}
|
|
||||||
@media only screen and (max-width: 1000px) {
|
@media only screen and (max-width: 1000px) {
|
||||||
.machine-image {
|
.machine-image {
|
||||||
margin-left: 50px;
|
margin-left: 50px;
|
||||||
|
12
src/app/user.service.spec.ts
Normal file
12
src/app/user.service.spec.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { UserService } from './user.service';
|
||||||
|
|
||||||
|
describe('UserService', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const service: UserService = TestBed.get(UserService);
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
21
src/app/user.service.ts
Normal file
21
src/app/user.service.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class UserService {
|
||||||
|
private isUserLoggedIn;
|
||||||
|
private username;
|
||||||
|
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.isUserLoggedIn = false;
|
||||||
|
}
|
||||||
|
setUserLoggedIn(){
|
||||||
|
this.isUserLoggedIn = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserLoggedIn(){
|
||||||
|
return this.isUserLoggedIn;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user