diff --git a/package.json b/package.json new file mode 100644 index 0000000..c92c4c2 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/server/data/users.json b/server/data/users.json new file mode 100644 index 0000000..d4c7c15 --- /dev/null +++ b/server/data/users.json @@ -0,0 +1,10 @@ +[ + { + "username": "admin", + "password": "admin" + }, + { + "username": "roei", + "password": "roei" + } +] diff --git a/server/routes/api.js b/server/routes/api.js new file mode 100644 index 0000000..6bd0243 --- /dev/null +++ b/server/routes/api.js @@ -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; diff --git a/server/server.js b/server/server.js new file mode 100644 index 0000000..f97254a --- /dev/null +++ b/server/server.js @@ -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; +} + diff --git a/src/app/app.component.css b/src/app/app.component.css new file mode 100644 index 0000000..74b16a8 --- /dev/null +++ b/src/app/app.component.css @@ -0,0 +1,5 @@ +#wrapper { + display: flex; + flex-direction: column; + min-height: 100vh; +} diff --git a/src/app/app.component.html b/src/app/app.component.html new file mode 100644 index 0000000..8548910 --- /dev/null +++ b/src/app/app.component.html @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts new file mode 100644 index 0000000..bcbdf36 --- /dev/null +++ b/src/app/app.component.spec.ts @@ -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!'); + })); +}); diff --git a/src/app/app.component.ts b/src/app/app.component.ts new file mode 100644 index 0000000..bb05f90 --- /dev/null +++ b/src/app/app.component.ts @@ -0,0 +1,9 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) + +export class AppComponent {} diff --git a/src/app/app.module.ts b/src/app/app.module.ts new file mode 100644 index 0000000..e12c1cc --- /dev/null +++ b/src/app/app.module.ts @@ -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 { } diff --git a/src/app/authguard.guard.spec.ts b/src/app/authguard.guard.spec.ts new file mode 100644 index 0000000..1c15a0f --- /dev/null +++ b/src/app/authguard.guard.spec.ts @@ -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(); + })); +}); diff --git a/src/app/authguard.guard.ts b/src/app/authguard.guard.ts new file mode 100644 index 0000000..9cb4f64 --- /dev/null +++ b/src/app/authguard.guard.ts @@ -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 | Promise { + return this.user.getUserLoggedIn(); + } +} diff --git a/src/app/dashboard/dashboard.component.css b/src/app/dashboard/dashboard.component.css new file mode 100644 index 0000000..2a02c4d --- /dev/null +++ b/src/app/dashboard/dashboard.component.css @@ -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; +} diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html new file mode 100644 index 0000000..ec8b969 --- /dev/null +++ b/src/app/dashboard/dashboard.component.html @@ -0,0 +1,15 @@ +

+ Logged successfully. + Go back +

+ + diff --git a/src/app/dashboard/dashboard.component.spec.ts b/src/app/dashboard/dashboard.component.spec.ts new file mode 100644 index 0000000..9c996c3 --- /dev/null +++ b/src/app/dashboard/dashboard.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DashboardComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts new file mode 100644 index 0000000..d20cc95 --- /dev/null +++ b/src/app/dashboard/dashboard.component.ts @@ -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() { + } + +} diff --git a/src/app/footer/footer.component.css b/src/app/footer/footer.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/footer/footer.component.html b/src/app/footer/footer.component.html new file mode 100644 index 0000000..1825eb3 --- /dev/null +++ b/src/app/footer/footer.component.html @@ -0,0 +1 @@ +

Footer will be here

diff --git a/src/app/footer/footer.component.spec.ts b/src/app/footer/footer.component.spec.ts new file mode 100644 index 0000000..2ca6c45 --- /dev/null +++ b/src/app/footer/footer.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FooterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FooterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/footer/footer.component.ts b/src/app/footer/footer.component.ts new file mode 100644 index 0000000..3d8f7e9 --- /dev/null +++ b/src/app/footer/footer.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-footer', + templateUrl: './footer.component.html', + styleUrls: ['./footer.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class FooterComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/header/header.component.css b/src/app/header/header.component.css new file mode 100644 index 0000000..dd31c07 --- /dev/null +++ b/src/app/header/header.component.css @@ -0,0 +1,6 @@ +header { + text-align: center; + padding: 20px 0; + font-size: 30px; + border-bottom: 2px solid #eee; +} diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html new file mode 100644 index 0000000..2100222 --- /dev/null +++ b/src/app/header/header.component.html @@ -0,0 +1 @@ +
Team Chat
diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts new file mode 100644 index 0000000..2d0479d --- /dev/null +++ b/src/app/header/header.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HeaderComponent } from './header.component'; + +describe('HeaderComponent', () => { + let component: HeaderComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HeaderComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HeaderComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts new file mode 100644 index 0000000..5d1e556 --- /dev/null +++ b/src/app/header/header.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-header', + templateUrl: './header.component.html', + styleUrls: ['./header.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class HeaderComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/login-form/login-form.component.css b/src/app/login-form/login-form.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/login-form/login-form.component.html b/src/app/login-form/login-form.component.html new file mode 100644 index 0000000..9c44b72 --- /dev/null +++ b/src/app/login-form/login-form.component.html @@ -0,0 +1,30 @@ +
+
+
+
+

Login

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
diff --git a/src/app/login-form/login-form.component.spec.ts b/src/app/login-form/login-form.component.spec.ts new file mode 100644 index 0000000..c5f08d4 --- /dev/null +++ b/src/app/login-form/login-form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginFormComponent } from './login-form.component'; + +describe('LoginFormComponent', () => { + let component: LoginFormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoginFormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoginFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/login-form/login-form.component.ts b/src/app/login-form/login-form.component.ts new file mode 100644 index 0000000..803d4d0 --- /dev/null +++ b/src/app/login-form/login-form.component.ts @@ -0,0 +1,47 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Router } from '@angular/router'; +import { UserService } from '../user.service'; +import { USERS } from '../users'; +import { Observable} from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/catch'; +import { User } from '../user'; +import {SingServiceService} from '../sing-service.service'; +import { NgModel } from '@angular/forms'; + +@Component({ + selector: 'app-login-form', + templateUrl: './login-form.component.html', + styleUrls: ['./login-form.component.css'], + encapsulation: ViewEncapsulation.None +}) + +export class LoginFormComponent implements OnInit { + + loginUser2: User = {username:"", password:""}; + constructor(private login:SingServiceService) { + } + + ngOnInit() { + } + submit() { + this.login.loginUser(this.loginUser2.username,this.loginUser2.password).subscribe((res) => console.log(res)); + } + // loginUser(e) { + // e.preventDefault(); + // console.log(e); + // var usernameForm = e.target.elements[0].value; + // var passwordForm = e.target.elements[1].value; + + // this.login.loginUser(this.loginUser2.username,this.loginUser2.password); + + // var authenticatedUsername = USERS.find(u => u.username === usernameForm); + // var authenticatedPassword = USERS.find(u => u.password === passwordForm); + + // if (authenticatedUsername != null && authenticatedPassword != null) { + // this.user.setUserLoggedIn(usernameForm); + + // this.router.navigate(['dashboard']); + // } + } + diff --git a/src/app/login-service.service.spec.ts b/src/app/login-service.service.spec.ts new file mode 100644 index 0000000..c451bee --- /dev/null +++ b/src/app/login-service.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { LoginService } from './login-service.service'; + +describe('LoginServiceService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [LoginService] + }); + }); + + it('should be created', inject([LoginService], (service: LoginService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/login-service.service.ts b/src/app/login-service.service.ts new file mode 100644 index 0000000..0c91e2c --- /dev/null +++ b/src/app/login-service.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; +import { User } from './user'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { NgModel } from '@angular/forms'; +import { of } from 'rxjs/observable/of'; +import { catchError, map, tap } from 'rxjs/operators'; + +@Injectable() +export class LoginService { + + constructor(private http: HttpClient) { } + + // loginUser (userName: string): Observable { + // return this.http.get("http://localhost:3000/validate/" + userName) + // .pipe( + // tap(users => this.log(`fetched users`)), + // catchError(this.handleError('getUsers', [])) + // ); + // } + + loginUser (userName: string,password:string) { + let body = {username: userName,password : password}; + return this.http.post("http://localhost:3000/validate/",body) + .pipe( + tap(users => this.log(`fetched users`)), + catchError(this.handleError('getUsers', [])) + ); + } + + private handleError (operation = 'operation', result?: T) { + return (error: any): Observable => { + + // TODO: send the error to remote logging infrastructure + console.log(error.toString()); // log to console instead + // TODO: better job of transforming error for user consumption + this.log(`${operation} failed: ${error.message}`); + + // Let the app keep running by returning an empty result. + return of(result as T); + }; + } + + private log(message: string) { + } + +} diff --git a/src/app/signup-form/signup-form.component.css b/src/app/signup-form/signup-form.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/signup-form/signup-form.component.html b/src/app/signup-form/signup-form.component.html new file mode 100644 index 0000000..1a3e489 --- /dev/null +++ b/src/app/signup-form/signup-form.component.html @@ -0,0 +1,51 @@ +
+
+
+
+

Sign up

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+
diff --git a/src/app/signup-form/signup-form.component.spec.ts b/src/app/signup-form/signup-form.component.spec.ts new file mode 100644 index 0000000..53e36f9 --- /dev/null +++ b/src/app/signup-form/signup-form.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SignupFormComponent } from './signup-form.component'; + +describe('SignupFormComponent', () => { + let component: SignupFormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SignupFormComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SignupFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/signup-form/signup-form.component.ts b/src/app/signup-form/signup-form.component.ts new file mode 100644 index 0000000..d83d122 --- /dev/null +++ b/src/app/signup-form/signup-form.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Router } from '@angular/router'; +import { UserService } from '../user.service'; +import { User } from '../user'; +import { USERS } from '../users'; +import { NgIf } from '@angular/common'; + + +@Component({ + selector: 'app-signup-form', + templateUrl: './signup-form.component.html', + styleUrls: ['./signup-form.component.css'], + encapsulation: ViewEncapsulation.None +}) + +export class SignupFormComponent implements OnInit { + + constructor(private router: Router, private user: UserService) { + } + ngOnInit() { + } + formResults = ""; + isValid = null; + registerUser(e) { + e.preventDefault(); + console.log(e); + var usernameForm = e.target.elements[0].value; + var passwordForm = e.target.elements[1].value; + var repasswordForm = e.target.elements[2].value; + + var authenticatedUsername = USERS.find(u => u.username === usernameForm); + var authenticatedPassword = false; + if (passwordForm === repasswordForm) { + authenticatedPassword = true; + } + + if (authenticatedUsername == null && authenticatedPassword) { + var newUser = {username: usernameForm, password: passwordForm} + USERS.push(newUser); + this.formResults = "User is created. Go to login page."; + this.isValid = true; + this.router.navigate(['dashboard']); + } + else { + this.formResults = "Username already exists or passwords not match"; + this.isValid = false; + } + } +} diff --git a/src/app/sing-service.service.spec.ts b/src/app/sing-service.service.spec.ts new file mode 100644 index 0000000..d6f8709 --- /dev/null +++ b/src/app/sing-service.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { SingServiceService } from './sing-service.service'; + +describe('SingServiceService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [SingServiceService] + }); + }); + + it('should be created', inject([SingServiceService], (service: SingServiceService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/sing-service.service.ts b/src/app/sing-service.service.ts new file mode 100644 index 0000000..edea29d --- /dev/null +++ b/src/app/sing-service.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import { User } from './user'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { NgModel } from '@angular/forms'; +import { of } from 'rxjs/observable/of'; +import { catchError, map, tap } from 'rxjs/operators'; + +@Injectable() +export class SingServiceService { + + constructor(private http: HttpClient) { } + loginUser (userName: string,password:string) { + let body = {username: userName,password : password}; + return this.http.post("http://localhost:3000/validate/",body) + .pipe( + tap(users => this.log(`fetched users`)), + catchError(this.handleError('getUsers', [])) + ); + } + + private handleError (operation = 'operation', result?: T) { + return (error: any): Observable => { + + // TODO: send the error to remote logging infrastructure + console.log(error.toString()); // log to console instead + // TODO: better job of transforming error for user consumption + this.log(`${operation} failed: ${error.message}`); + + // Let the app keep running by returning an empty result. + return of(result as T); + }; + } + + private log(message: string) { + } + + +} diff --git a/src/app/standart-room/standart-room.component.css b/src/app/standart-room/standart-room.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/standart-room/standart-room.component.html b/src/app/standart-room/standart-room.component.html new file mode 100644 index 0000000..5fd7a3b --- /dev/null +++ b/src/app/standart-room/standart-room.component.html @@ -0,0 +1,3 @@ +

+ standart-room works! +

diff --git a/src/app/standart-room/standart-room.component.spec.ts b/src/app/standart-room/standart-room.component.spec.ts new file mode 100644 index 0000000..e1fd229 --- /dev/null +++ b/src/app/standart-room/standart-room.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StandartRoomComponent } from './standart-room.component'; + +describe('StandartRoomComponent', () => { + let component: StandartRoomComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ StandartRoomComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(StandartRoomComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/standart-room/standart-room.component.ts b/src/app/standart-room/standart-room.component.ts new file mode 100644 index 0000000..2e45c36 --- /dev/null +++ b/src/app/standart-room/standart-room.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-standart-room', + templateUrl: './standart-room.component.html', + styleUrls: ['./standart-room.component.css'], + encapsulation: ViewEncapsulation.None +}) +export class StandartRoomComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/user.service.spec.ts b/src/app/user.service.spec.ts new file mode 100644 index 0000000..b26195c --- /dev/null +++ b/src/app/user.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { UserService } from './user.service'; + +describe('UserService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [UserService] + }); + }); + + it('should be created', inject([UserService], (service: UserService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/user.service.ts b/src/app/user.service.ts new file mode 100644 index 0000000..9bd1b8c --- /dev/null +++ b/src/app/user.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { USERS } from './users'; + +@Injectable() +export class UserService { + private isUserLoggedIn; + public username; + + constructor() { + this.isUserLoggedIn = false; + } + + setUserLoggedIn(userName) { + this.isUserLoggedIn = true; + this.username = userName; + } + + + getUserLoggedIn() { + return this.isUserLoggedIn; + } + +} diff --git a/src/app/user.ts b/src/app/user.ts new file mode 100644 index 0000000..b23d28e --- /dev/null +++ b/src/app/user.ts @@ -0,0 +1,5 @@ +export class User { + username: string; + password: string; + +} diff --git a/src/app/users.ts b/src/app/users.ts new file mode 100644 index 0000000..1603afd --- /dev/null +++ b/src/app/users.ts @@ -0,0 +1,6 @@ +import {User} from './user'; + +export const USERS: User[] = [ + {username: 'roei', password: 'roei'}, + {username: 'admin', password: 'admin'} +]; diff --git a/src/assets/.gitkeep b/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/src/environments/environment.ts b/src/environments/environment.ts new file mode 100644 index 0000000..b7f639a --- /dev/null +++ b/src/environments/environment.ts @@ -0,0 +1,8 @@ +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `.angular-cli.json`. + +export const environment = { + production: false +}; diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 0000000..8081c7c Binary files /dev/null and b/src/favicon.ico differ diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..c118574 --- /dev/null +++ b/src/index.html @@ -0,0 +1,14 @@ + + + + + Teamchat + + + + + + + + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..91ec6da --- /dev/null +++ b/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.log(err)); diff --git a/src/polyfills.ts b/src/polyfills.ts new file mode 100644 index 0000000..20d4075 --- /dev/null +++ b/src/polyfills.ts @@ -0,0 +1,76 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), + * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. + * + * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** IE9, IE10 and IE11 requires all of the following polyfills. **/ +// import 'core-js/es6/symbol'; +// import 'core-js/es6/object'; +// import 'core-js/es6/function'; +// import 'core-js/es6/parse-int'; +// import 'core-js/es6/parse-float'; +// import 'core-js/es6/number'; +// import 'core-js/es6/math'; +// import 'core-js/es6/string'; +// import 'core-js/es6/date'; +// import 'core-js/es6/array'; +// import 'core-js/es6/regexp'; +// import 'core-js/es6/map'; +// import 'core-js/es6/weak-map'; +// import 'core-js/es6/set'; + +/** IE10 and IE11 requires the following for NgClass support on SVG elements */ +// import 'classlist.js'; // Run `npm install --save classlist.js`. + +/** IE10 and IE11 requires the following for the Reflect API. */ +// import 'core-js/es6/reflect'; + + +/** Evergreen browsers require these. **/ +// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. +import 'core-js/es7/reflect'; + + +/** + * Required to support Web Animations `@angular/platform-browser/animations`. + * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation + **/ +// import 'web-animations-js'; // Run `npm install --save web-animations-js`. + + + +/*************************************************************************************************** + * Zone JS is required by Angular itself. + */ +import 'zone.js/dist/zone'; // Included with Angular CLI. + + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ + +/** + * Date, currency, decimal and percent pipes. + * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 + */ +// import 'intl'; // Run `npm install --save intl`. +/** + * Need to import at least one locale-data with intl. + */ +// import 'intl/locale-data/jsonp/en'; diff --git a/src/styles.css b/src/styles.css new file mode 100644 index 0000000..90d4ee0 --- /dev/null +++ b/src/styles.css @@ -0,0 +1 @@ +/* You can add global styles to this file, and also import other style files */ diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..cd612ee --- /dev/null +++ b/src/test.ts @@ -0,0 +1,32 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy.js'; +import 'zone.js/dist/sync-test'; +import 'zone.js/dist/jasmine-patch'; +import 'zone.js/dist/async-test'; +import 'zone.js/dist/fake-async-test'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. +declare const __karma__: any; +declare const require: any; + +// Prevent Karma from running prematurely. +__karma__.loaded = function () {}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); +// Finally, start Karma to run the tests. +__karma__.start(); diff --git a/src/tsconfig.app.json b/src/tsconfig.app.json new file mode 100644 index 0000000..39ba8db --- /dev/null +++ b/src/tsconfig.app.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/app", + "baseUrl": "./", + "module": "es2015", + "types": [] + }, + "exclude": [ + "test.ts", + "**/*.spec.ts" + ] +} diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json new file mode 100644 index 0000000..63d89ff --- /dev/null +++ b/src/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "baseUrl": "./", + "module": "commonjs", + "target": "es5", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 0000000..ef5c7bd --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1,5 @@ +/* SystemJS module definition */ +declare var module: NodeModule; +interface NodeModule { + id: string; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a6c016b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "outDir": "./dist/out-tsc", + "sourceMap": true, + "declaration": false, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es5", + "typeRoots": [ + "node_modules/@types" + ], + "lib": [ + "es2017", + "dom" + ] + } +}