Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "teamchat",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"body-parser": "^1.18.2",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"cors": "^2.8.4",
"express": "^4.16.2",
"file-system": "^2.2.2",
"ngx-bootstrap": "^2.0.0-beta.8",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.5.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}
10 changes: 10 additions & 0 deletions server/data/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"username": "admin",
"password": "admin"
},
{
"username": "roei",
"password": "roei"
}
]
9 changes: 9 additions & 0 deletions server/routes/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();

/* GET api listing. */
router.get('/', (req, res) => {
res.send('api works');
});

module.exports = router;
67 changes: 67 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
var file = require('file-system');
var fs = require('fs');
var cors = require('cors');

// Get our API routes
const api = require('./routes/api');

const app = express();

app.use(cors());
// Parsers for POST data
app.use(bodyParser.json());

app.use(bodyParser.urlencoded({extended: false}));

// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
// Set our api routes
app.use('/api', api);

// Catch all other routes and return the index file
app.get('/validate/:username', (req, res) => {
if (doesUserExist(req.params.username))
res.send("user connected");
else
res.send("user doesnt exist!");
});

app.post('/', (req, res) => {

if (doesUserExist(req.body.username)) {
let tempUser = jsonUsers.find(user => user.username === req.body.username);
if (tempUser.password === req.body.password)
// res.send(tempUser);
res.redirect('/dashboard');
else
send('username or password incorrect, please try again');
}
else
res.send('user doesnt exist!');
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);

/**
* Create HTTP server.
*/
const server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));

var jsonUsers = JSON.parse(fs.readFileSync('C:\\Users\\Jbt\\WebstormProjects\\teamChatTheRealOne\\teamchat\\server\\data\\users.json'), 'utf-8');

function doesUserExist(username) {
return jsonUsers.filter(user => user.username === username).length === 1;
}

5 changes: 5 additions & 0 deletions src/app/app.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
}
5 changes: 5 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="wrapper">
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
</div>
27 changes: 27 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
}));
});
9 changes: 9 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {}
56 changes: 56 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClient, HttpClientModule, HttpHandler } from '@angular/common/http';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { LoginFormComponent } from './login-form/login-form.component';
import { FooterComponent } from './footer/footer.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { RouterModule, Routes } from '@angular/router';
import { UserService } from './user.service';
import { AuthguardGuard } from './authguard.guard';
import { AlertModule } from 'ngx-bootstrap';
import { SignupFormComponent } from './signup-form/signup-form.component';
import { StandartRoomComponent } from './standart-room/standart-room.component';
import { SingServiceService } from './sing-service.service';

const appRoutes:Routes = [
{
path: '',
component: LoginFormComponent
},
{
path: 'dashboard',
canActivate: [AuthguardGuard],
component: DashboardComponent

},
{
path: 'signup',
component: SignupFormComponent

}
];

@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
AlertModule.forRoot(),
FormsModule,
HttpClientModule
],
declarations: [
AppComponent,
HeaderComponent,
LoginFormComponent,
FooterComponent,
DashboardComponent,
SignupFormComponent,
StandartRoomComponent
],
providers: [UserService, AuthguardGuard,SingServiceService,HttpClient],
bootstrap: [ AppComponent ]
})
export class AppModule { }
15 changes: 15 additions & 0 deletions src/app/authguard.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TestBed, async, inject } from '@angular/core/testing';

import { AuthguardGuard } from './authguard.guard';

describe('AuthguardGuard', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AuthguardGuard]
});
});

it('should ...', inject([AuthguardGuard], (guard: AuthguardGuard) => {
expect(guard).toBeTruthy();
}));
});
15 changes: 15 additions & 0 deletions src/app/authguard.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import {UserService} from './user.service';
import {Router} from '@angular/router';

@Injectable()
export class AuthguardGuard implements CanActivate {

constructor(private user: UserService) {}

canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> | Promise<boolean> {
return this.user.getUserLoggedIn();
}
}
15 changes: 15 additions & 0 deletions src/app/dashboard/dashboard.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardRoom {
background-color: black;
height: 200px;
color: white;
font-size: 24px;
line-height: 200px;
}

#goldRoom {
background-color: pink;
height: 200px;
color: white;
font-size: 24px;
line-height: 200px;
}
15 changes: 15 additions & 0 deletions src/app/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>
Logged successfully.
<a routerLink="/">Go back</a>
</p>

<div class="container">
<div class="row">
<a href="#"><div id="standardRoom" class="col-md-offset-2 col-md-3 text-center">
Standard Room
</div></a>
<a href="#"><div id="goldRoom" class="col-md-offset-2 col-md-3 text-center">
Gold Room
</div></a>
</div>
</div>
25 changes: 25 additions & 0 deletions src/app/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardComponent } from './dashboard.component';

describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DashboardComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';
import { UserService } from '../user.service';
import { USERS } from '../users';

@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css'],
encapsulation: ViewEncapsulation.None
})
export class DashboardComponent implements OnInit {

constructor(private user: UserService) { }
hasPermission = null;
ngOnInit() {
}

}
Empty file.
1 change: 1 addition & 0 deletions src/app/footer/footer.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Footer will be here</p>
25 changes: 25 additions & 0 deletions src/app/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FooterComponent } from './footer.component';

describe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FooterComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading