From fdd3a211f84ee5a3b1de6b4f8b0e45241ef769c5 Mon Sep 17 00:00:00 2001 From: Aviv454 Date: Mon, 13 Nov 2017 16:40:28 +0200 Subject: [PATCH 1/6] not working yet --- client-side-chat/server/data/users.json | 18 +++++ client-side-chat/server/routes/api.js | 9 +++ client-side-chat/server/server.js | 58 +++++++++++++ client-side-chat/src/app/app.component.css | 0 client-side-chat/src/app/app.component.html | 7 ++ .../src/app/app.component.spec.ts | 27 +++++++ client-side-chat/src/app/app.component.ts | 10 +++ client-side-chat/src/app/app.module.ts | 23 ++++++ .../sign-in-component.component.css | 0 .../sign-in-component.component.html | 25 ++++++ .../sign-in-component.component.spec.ts | 25 ++++++ .../sign-in-component.component.ts | 26 ++++++ .../src/app/sign-in-service.service.spec.ts | 15 ++++ .../src/app/sign-in-service.service.ts | 40 +++++++++ client-side-chat/src/app/user.ts | 4 + client-side-chat/src/assets/.gitkeep | 0 .../src/environments/environment.prod.ts | 3 + .../src/environments/environment.ts | 8 ++ client-side-chat/src/favicon.ico | Bin 0 -> 5430 bytes client-side-chat/src/index.html | 14 ++++ client-side-chat/src/main.ts | 12 +++ client-side-chat/src/polyfills.ts | 76 ++++++++++++++++++ client-side-chat/src/styles.css | 2 + client-side-chat/src/test.ts | 32 ++++++++ client-side-chat/src/tsconfig.app.json | 13 +++ client-side-chat/src/tsconfig.spec.json | 20 +++++ client-side-chat/src/typings.d.ts | 5 ++ package.json | 23 ++++++ 28 files changed, 495 insertions(+) create mode 100644 client-side-chat/server/data/users.json create mode 100644 client-side-chat/server/routes/api.js create mode 100644 client-side-chat/server/server.js create mode 100644 client-side-chat/src/app/app.component.css create mode 100644 client-side-chat/src/app/app.component.html create mode 100644 client-side-chat/src/app/app.component.spec.ts create mode 100644 client-side-chat/src/app/app.component.ts create mode 100644 client-side-chat/src/app/app.module.ts create mode 100644 client-side-chat/src/app/sign-in-component/sign-in-component.component.css create mode 100644 client-side-chat/src/app/sign-in-component/sign-in-component.component.html create mode 100644 client-side-chat/src/app/sign-in-component/sign-in-component.component.spec.ts create mode 100644 client-side-chat/src/app/sign-in-component/sign-in-component.component.ts create mode 100644 client-side-chat/src/app/sign-in-service.service.spec.ts create mode 100644 client-side-chat/src/app/sign-in-service.service.ts create mode 100644 client-side-chat/src/app/user.ts create mode 100644 client-side-chat/src/assets/.gitkeep create mode 100644 client-side-chat/src/environments/environment.prod.ts create mode 100644 client-side-chat/src/environments/environment.ts create mode 100644 client-side-chat/src/favicon.ico create mode 100644 client-side-chat/src/index.html create mode 100644 client-side-chat/src/main.ts create mode 100644 client-side-chat/src/polyfills.ts create mode 100644 client-side-chat/src/styles.css create mode 100644 client-side-chat/src/test.ts create mode 100644 client-side-chat/src/tsconfig.app.json create mode 100644 client-side-chat/src/tsconfig.spec.json create mode 100644 client-side-chat/src/typings.d.ts create mode 100644 package.json diff --git a/client-side-chat/server/data/users.json b/client-side-chat/server/data/users.json new file mode 100644 index 0000000..7270099 --- /dev/null +++ b/client-side-chat/server/data/users.json @@ -0,0 +1,18 @@ +[ + { + "username": "Mr. Nice", + "password": 1237 + }, + { + "username": "Narco", + "password": 12374 + }, + { + "username": "aviv", + "password": 1234 + }, + { + "username": "tealterMashoo", + "password": 5555 + } +] diff --git a/client-side-chat/server/routes/api.js b/client-side-chat/server/routes/api.js new file mode 100644 index 0000000..6bd0243 --- /dev/null +++ b/client-side-chat/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/client-side-chat/server/server.js b/client-side-chat/server/server.js new file mode 100644 index 0000000..6df7389 --- /dev/null +++ b/client-side-chat/server/server.js @@ -0,0 +1,58 @@ +// Get dependencies + +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!"); +}); + +/** + * 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\\angular-team-chat-aviv\\client-side-chat\\server\\data\\users.json'), 'utf-8'); + +function doesUserExist() { + return jsonUsers.filter(user => user.username === req.params.username).length === 1; +} + + + diff --git a/client-side-chat/src/app/app.component.css b/client-side-chat/src/app/app.component.css new file mode 100644 index 0000000..e69de29 diff --git a/client-side-chat/src/app/app.component.html b/client-side-chat/src/app/app.component.html new file mode 100644 index 0000000..38d608d --- /dev/null +++ b/client-side-chat/src/app/app.component.html @@ -0,0 +1,7 @@ + +
+

+ Welcome to {{title}}! +

+ +
diff --git a/client-side-chat/src/app/app.component.spec.ts b/client-side-chat/src/app/app.component.spec.ts new file mode 100644 index 0000000..bcbdf36 --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/app/app.component.ts b/client-side-chat/src/app/app.component.ts new file mode 100644 index 0000000..7b0f672 --- /dev/null +++ b/client-side-chat/src/app/app.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) +export class AppComponent { + title = 'app'; +} diff --git a/client-side-chat/src/app/app.module.ts b/client-side-chat/src/app/app.module.ts new file mode 100644 index 0000000..3376cf5 --- /dev/null +++ b/client-side-chat/src/app/app.module.ts @@ -0,0 +1,23 @@ +import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule } from '@angular/forms'; +import { NgModule } from '@angular/core'; +import { HttpClientModule } from '@angular/common/http'; + +import { AppComponent } from './app.component'; +import { SignInComponentComponent } from './sign-in-component/sign-in-component.component'; + + +@NgModule({ + imports: [ + BrowserModule, + FormsModule, + HttpClientModule + ], + declarations: [ + AppComponent, + SignInComponentComponent + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.css b/client-side-chat/src/app/sign-in-component/sign-in-component.component.css new file mode 100644 index 0000000..e69de29 diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.html b/client-side-chat/src/app/sign-in-component/sign-in-component.component.html new file mode 100644 index 0000000..83b76dd --- /dev/null +++ b/client-side-chat/src/app/sign-in-component/sign-in-component.component.html @@ -0,0 +1,25 @@ +
+
+
+
+
+ Sign In +
+
+
+ + +
+
+ +
+
+ +
+
+
+
+
+ diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.spec.ts b/client-side-chat/src/app/sign-in-component/sign-in-component.component.spec.ts new file mode 100644 index 0000000..6058c4e --- /dev/null +++ b/client-side-chat/src/app/sign-in-component/sign-in-component.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SignInComponentComponent } from './sign-in-component.component'; + +describe('SignInComponentComponent', () => { + let component: SignInComponentComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SignInComponentComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SignInComponentComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts b/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts new file mode 100644 index 0000000..c0864ae --- /dev/null +++ b/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { User } from '../user'; +import { SignInService } from '../sign-in-service.service'; + +@Component({ + selector: 'app-sign-in-component', + templateUrl: './sign-in-component.component.html', + styleUrls: ['./sign-in-component.component.css'], + providers: [SignInService], + encapsulation: ViewEncapsulation.None +}) +export class SignInComponentComponent implements OnInit { + + user: User = {username:"", password:null}; + + constructor(private signInService: SignInService) { + } + + ngOnInit() { + } + + submit(){ + this.signInService.getUsers(this.user.username).subscribe((res) => console.log(res)); + } + +} diff --git a/client-side-chat/src/app/sign-in-service.service.spec.ts b/client-side-chat/src/app/sign-in-service.service.spec.ts new file mode 100644 index 0000000..e97718c --- /dev/null +++ b/client-side-chat/src/app/sign-in-service.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { SignInService } from './sign-in-service.service'; + +describe('SignInService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [SignInService] + }); + }); + + it('should be created', inject([SignInService], (service: SignInService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/client-side-chat/src/app/sign-in-service.service.ts b/client-side-chat/src/app/sign-in-service.service.ts new file mode 100644 index 0000000..a31da5f --- /dev/null +++ b/client-side-chat/src/app/sign-in-service.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core'; +import { User } from './user'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; + +import { of } from 'rxjs/observable/of'; +import { catchError, map, tap } from 'rxjs/operators'; + +@Injectable() +export class SignInService { + + constructor(private http: HttpClient) { } + + getUsers (userName: string): Observable { + return this.http.get("localhost:3000/validate/" + userName) + .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.error(error); // 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/client-side-chat/src/app/user.ts b/client-side-chat/src/app/user.ts new file mode 100644 index 0000000..ae5b950 --- /dev/null +++ b/client-side-chat/src/app/user.ts @@ -0,0 +1,4 @@ +export class User{ + username : string; + password : number; +} diff --git a/client-side-chat/src/assets/.gitkeep b/client-side-chat/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/client-side-chat/src/environments/environment.prod.ts b/client-side-chat/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/client-side-chat/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/client-side-chat/src/environments/environment.ts b/client-side-chat/src/environments/environment.ts new file mode 100644 index 0000000..b7f639a --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/favicon.ico b/client-side-chat/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..8081c7ceaf2be08bf59010158c586170d9d2d517 GIT binary patch literal 5430 zcmc(je{54#6vvCoAI3i*G5%$U7!sA3wtMZ$fH6V9C`=eXGJb@R1%(I_{vnZtpD{6n z5Pl{DmxzBDbrB>}`90e12m8T*36WoeDLA&SD_hw{H^wM!cl_RWcVA!I+x87ee975; z@4kD^=bYPn&pmG@(+JZ`rqQEKxW<}RzhW}I!|ulN=fmjVi@x{p$cC`)5$a!)X&U+blKNvN5tg=uLvuLnuqRM;Yc*swiexsoh#XPNu{9F#c`G zQLe{yWA(Y6(;>y|-efAy11k<09(@Oo1B2@0`PtZSkqK&${ zgEY}`W@t{%?9u5rF?}Y7OL{338l*JY#P!%MVQY@oqnItpZ}?s z!r?*kwuR{A@jg2Chlf0^{q*>8n5Ir~YWf*wmsh7B5&EpHfd5@xVaj&gqsdui^spyL zB|kUoblGoO7G(MuKTfa9?pGH0@QP^b#!lM1yHWLh*2iq#`C1TdrnO-d#?Oh@XV2HK zKA{`eo{--^K&MW66Lgsktfvn#cCAc*(}qsfhrvOjMGLE?`dHVipu1J3Kgr%g?cNa8 z)pkmC8DGH~fG+dlrp(5^-QBeEvkOvv#q7MBVLtm2oD^$lJZx--_=K&Ttd=-krx(Bb zcEoKJda@S!%%@`P-##$>*u%T*mh+QjV@)Qa=Mk1?#zLk+M4tIt%}wagT{5J%!tXAE;r{@=bb%nNVxvI+C+$t?!VJ@0d@HIyMJTI{vEw0Ul ze(ha!e&qANbTL1ZneNl45t=#Ot??C0MHjjgY8%*mGisN|S6%g3;Hlx#fMNcL<87MW zZ>6moo1YD?P!fJ#Jb(4)_cc50X5n0KoDYfdPoL^iV`k&o{LPyaoqMqk92wVM#_O0l z09$(A-D+gVIlq4TA&{1T@BsUH`Bm=r#l$Z51J-U&F32+hfUP-iLo=jg7Xmy+WLq6_tWv&`wDlz#`&)Jp~iQf zZP)tu>}pIIJKuw+$&t}GQuqMd%Z>0?t%&BM&Wo^4P^Y z)c6h^f2R>X8*}q|bblAF?@;%?2>$y+cMQbN{X$)^R>vtNq_5AB|0N5U*d^T?X9{xQnJYeU{ zoZL#obI;~Pp95f1`%X3D$Mh*4^?O?IT~7HqlWguezmg?Ybq|7>qQ(@pPHbE9V?f|( z+0xo!#m@Np9PljsyxBY-UA*{U*la#8Wz2sO|48_-5t8%_!n?S$zlGe+NA%?vmxjS- zHE5O3ZarU=X}$7>;Okp(UWXJxI%G_J-@IH;%5#Rt$(WUX?6*Ux!IRd$dLP6+SmPn= z8zjm4jGjN772R{FGkXwcNv8GBcZI#@Y2m{RNF_w8(Z%^A*!bS*!}s6sh*NnURytky humW;*g7R+&|Ledvc- + + + + ClientSideChat + + + + + + + + + diff --git a/client-side-chat/src/main.ts b/client-side-chat/src/main.ts new file mode 100644 index 0000000..91ec6da --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/polyfills.ts b/client-side-chat/src/polyfills.ts new file mode 100644 index 0000000..20d4075 --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/styles.css b/client-side-chat/src/styles.css new file mode 100644 index 0000000..ad5ea64 --- /dev/null +++ b/client-side-chat/src/styles.css @@ -0,0 +1,2 @@ +/* You can add global styles to this file, and also import other style files */ +@import "~bootstrap/dist/css/bootstrap.min.css"; diff --git a/client-side-chat/src/test.ts b/client-side-chat/src/test.ts new file mode 100644 index 0000000..cd612ee --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/tsconfig.app.json b/client-side-chat/src/tsconfig.app.json new file mode 100644 index 0000000..39ba8db --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/tsconfig.spec.json b/client-side-chat/src/tsconfig.spec.json new file mode 100644 index 0000000..63d89ff --- /dev/null +++ b/client-side-chat/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/client-side-chat/src/typings.d.ts b/client-side-chat/src/typings.d.ts new file mode 100644 index 0000000..ef5c7bd --- /dev/null +++ b/client-side-chat/src/typings.d.ts @@ -0,0 +1,5 @@ +/* SystemJS module definition */ +declare var module: NodeModule; +interface NodeModule { + id: string; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9d26a07 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "angular-team-chat-aviv", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/WebCourse3/team-chat-angular-aviv2.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/WebCourse3/team-chat-angular-aviv2/issues" + }, + "homepage": "https://github.com/WebCourse3/team-chat-angular-aviv2#readme", + "dependencies": { + "bootstrap": "^3.3.7", + "express": "^4.16.2" + } +} From 2e6a010ee68763e9b47182c41f93de6f7fdc4735 Mon Sep 17 00:00:00 2001 From: Aviv454 Date: Mon, 13 Nov 2017 16:46:05 +0200 Subject: [PATCH 2/6] not working yet --- client-side-chat/server/server.js | 8 ++++---- client-side-chat/src/app/sign-in-service.service.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client-side-chat/server/server.js b/client-side-chat/server/server.js index 6df7389..e90bc88 100644 --- a/client-side-chat/server/server.js +++ b/client-side-chat/server/server.js @@ -6,7 +6,7 @@ const http = require('http'); const bodyParser = require('body-parser'); var file = require('file-system'); var fs = require('fs'); -var cors = require('cors') +var cors = require('cors'); // Get our API routes const api = require('./routes/api'); @@ -50,9 +50,9 @@ server.listen(port, () => console.log(`API running on localhost:${port}`)); var jsonUsers = JSON.parse(fs.readFileSync('C:\\Users\\Jbt\\WebstormProjects\\angular-team-chat-aviv\\client-side-chat\\server\\data\\users.json'), 'utf-8'); -function doesUserExist() { - return jsonUsers.filter(user => user.username === req.params.username).length === 1; +function doesUserExist(username) { + return jsonUsers.filter(user => user.username === username).length === 1; } - +//sfsadfgsd diff --git a/client-side-chat/src/app/sign-in-service.service.ts b/client-side-chat/src/app/sign-in-service.service.ts index a31da5f..1442b0a 100644 --- a/client-side-chat/src/app/sign-in-service.service.ts +++ b/client-side-chat/src/app/sign-in-service.service.ts @@ -12,7 +12,7 @@ export class SignInService { constructor(private http: HttpClient) { } getUsers (userName: string): Observable { - return this.http.get("localhost:3000/validate/" + userName) + return this.http.get("http://localhost:3000/validate/" + userName) .pipe( tap(users => this.log(`fetched users`)), catchError(this.handleError('getUsers', [])) From 020967b055348020b0d73303cef946a304a80c17 Mon Sep 17 00:00:00 2001 From: Aviv454 Date: Tue, 14 Nov 2017 13:06:06 +0200 Subject: [PATCH 3/6] not working yet --- client-side-chat/server/data/users.json | 2 +- client-side-chat/server/server.js | 19 +++++++++++--- client-side-chat/src/app/app.module.ts | 26 +++++++++++++++++-- .../sign-in-component.component.html | 3 ++- .../sign-in-component.component.ts | 2 +- .../src/app/sign-in-service.service.ts | 16 +++++++++--- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/client-side-chat/server/data/users.json b/client-side-chat/server/data/users.json index 7270099..f4bd434 100644 --- a/client-side-chat/server/data/users.json +++ b/client-side-chat/server/data/users.json @@ -4,7 +4,7 @@ "password": 1237 }, { - "username": "Narco", + "username": "leon", "password": 12374 }, { diff --git a/client-side-chat/server/server.js b/client-side-chat/server/server.js index e90bc88..c2f749e 100644 --- a/client-side-chat/server/server.js +++ b/client-side-chat/server/server.js @@ -16,7 +16,6 @@ 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 @@ -27,9 +26,22 @@ 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"); + res.send(jsonUsers.find(user => user.username === req.params.username)); + else + res.send('user doesnt exist!'); +}); + +app.post('/validate', (req, res) => { + + if (doesUserExist(req.body.username)) { + let tempUser = jsonUsers.find(user => user.username === req.body.username); + if (tempUser.password.toString() === req.body.password) + res.send(tempUser); + else + send('username or password incorrect, please try again'); + } else - res.send("user doesnt exist!"); + res.send('user doesnt exist!'); }); /** @@ -54,5 +66,4 @@ function doesUserExist(username) { return jsonUsers.filter(user => user.username === username).length === 1; } - //sfsadfgsd diff --git a/client-side-chat/src/app/app.module.ts b/client-side-chat/src/app/app.module.ts index 3376cf5..8f41654 100644 --- a/client-side-chat/src/app/app.module.ts +++ b/client-side-chat/src/app/app.module.ts @@ -2,17 +2,39 @@ import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { NgModule } from '@angular/core'; import { HttpClientModule } from '@angular/common/http'; - +import { RouterModule, Routes } from '@angular/router'; import { AppComponent } from './app.component'; import { SignInComponentComponent } from './sign-in-component/sign-in-component.component'; +// const appRoutes: Routes = [ +// { path: 'crisis-center', component: CrisisListComponent }, +// { path: 'hero/:id', component: HeroDetailComponent }, +// { +// path: 'heroes', +// component: HeroListComponent, +// data: { title: 'Heroes List' } +// }, +// { path: '', +// redirectTo: '/heroes', +// pathMatch: 'full' +// }, +// { path: '**', component: PageNotFoundComponent } +// ]; + + @NgModule({ imports: [ BrowserModule, FormsModule, - HttpClientModule + HttpClientModule, + RouterModule, + // RouterModule.forRoot( + // // appRoutes, + // { enableTracing: true } // <-- debugging purposes only + // ) ], + declarations: [ AppComponent, SignInComponentComponent diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.html b/client-side-chat/src/app/sign-in-component/sign-in-component.component.html index 83b76dd..ddb9760 100644 --- a/client-side-chat/src/app/sign-in-component/sign-in-component.component.html +++ b/client-side-chat/src/app/sign-in-component/sign-in-component.component.html @@ -1,3 +1,4 @@ +
@@ -13,7 +14,7 @@
-
diff --git a/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts b/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts index c0864ae..3b30491 100644 --- a/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts +++ b/client-side-chat/src/app/sign-in-component/sign-in-component.component.ts @@ -20,7 +20,7 @@ export class SignInComponentComponent implements OnInit { } submit(){ - this.signInService.getUsers(this.user.username).subscribe((res) => console.log(res)); + this.signInService.loginUser(this.user.username,this.user.password).subscribe((res) => console.log(res)); } } diff --git a/client-side-chat/src/app/sign-in-service.service.ts b/client-side-chat/src/app/sign-in-service.service.ts index 1442b0a..8134ba4 100644 --- a/client-side-chat/src/app/sign-in-service.service.ts +++ b/client-side-chat/src/app/sign-in-service.service.ts @@ -11,8 +11,18 @@ export class SignInService { constructor(private http: HttpClient) { } - getUsers (userName: string): Observable { - return this.http.get("http://localhost:3000/validate/" + userName) + // 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:number) { + 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', [])) @@ -23,7 +33,7 @@ export class SignInService { return (error: any): Observable => { // TODO: send the error to remote logging infrastructure - console.error(error); // log to console instead + console.log(error.toString()); // log to console instead // TODO: better job of transforming error for user consumption this.log(`${operation} failed: ${error.message}`); From 9ece27dbea14301621a5d0105c4f8a48df65919c Mon Sep 17 00:00:00 2001 From: Aviv454 Date: Tue, 14 Nov 2017 13:23:25 +0200 Subject: [PATCH 4/6] not working yet --- .idea/misc.xml | 6 + .idea/workspace.xml | 626 +++++++++++++++++++++++- client-side-chat/server/data/users.json | 2 +- client-side-chat/server/server.js | 2 +- 4 files changed, 608 insertions(+), 28 deletions(-) create mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7beed61..6de7ded 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,15 @@ + + + - + + + + + + @@ -12,19 +20,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sty + + + + + + + true + + false + true + true + true DEFINITION_ORDER - -