From 18600e2874cbc6762c32ec7c6d4c00666cc2616d Mon Sep 17 00:00:00 2001 From: wilfried Date: Fri, 28 May 2021 14:57:38 +0200 Subject: [PATCH] third commit --- .../src/app/general/general.component.html | 6 +- frontend/src/app/general/general.component.ts | 156 ++++++++--------- frontend/src/app/login/login.component.html | 6 +- frontend/src/app/login/login.component.ts | 45 ++--- .../src/app/private/private.component.html | 8 +- frontend/src/app/private/private.component.ts | 158 ++++++++---------- .../src/app/services/auth/auth.service.ts | 83 +++------ frontend/src/environments/environment.ts | 3 +- 8 files changed, 184 insertions(+), 281 deletions(-) diff --git a/frontend/src/app/general/general.component.html b/frontend/src/app/general/general.component.html index b469ee8..96d610a 100644 --- a/frontend/src/app/general/general.component.html +++ b/frontend/src/app/general/general.component.html @@ -5,14 +5,12 @@
-

{{user?.name}}

+

diff --git a/frontend/src/app/general/general.component.ts b/frontend/src/app/general/general.component.ts index 282037c..e6b5700 100644 --- a/frontend/src/app/general/general.component.ts +++ b/frontend/src/app/general/general.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; import {ChatService} from "../services/chat/chat.service"; import {AuthService} from "../services/auth/auth.service"; +import {MessageService} from "../services/message/message.service"; +import {MatTableDataSource} from "@angular/material/table"; @Component({ selector: 'app-general', @@ -8,8 +10,7 @@ import {AuthService} from "../services/auth/auth.service"; styleUrls: ['./general.component.scss'] }) export class GeneralComponent implements OnInit { - public currentUser; - + dataSource = new MatTableDataSource(); // @ts-ignore public user:String; // @ts-ignore @@ -24,42 +25,17 @@ export class GeneralComponent implements OnInit { // @ts-ignore public password: string; - // @ts-ignore - public currentUser; + // @ts-ignore public selectedUser; - public userList = [ - { - id: 1, - name: 'Yuki Vachot', - login: 'yuki', - password: 'vachot1', - room: 'general' - }, - { - id: 2, - name: 'Wilfried Vallee', - login: 'wilfried', - password: 'vallee2', - room: 'general' - }, - { - id: 3, - name: 'Khai Phan', - login: 'khai', - password: 'phan3', - room: 'general' - } - ]; - constructor(private chatService:ChatService, - private Auth: AuthService + constructor(private Auth: AuthService, + private chatService: ChatService, + private MS: MessageService ) { - this.currentUser = this.Auth.sendAuth(this.currentUser); - this.userList = this.userList.filter((user) => user.password !== this.currentUser.password.toString()); - console.log(this.userList); + this.chatService.newUserJoined() .subscribe(data=> this.messageArray.push(data)); @@ -72,39 +48,44 @@ export class GeneralComponent implements OnInit { .subscribe(data=>this.messageArray.push(data)); } ngOnInit(): void { - this.chatService.getMessage() - .subscribe((data: {user: string, message: string}) => { - this.messageArray.push(data); - if (this.room) { - setTimeout( () => { - this.storageArray = this.chatService.getStorage(); - //@ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); - //@ts-ignore - this.messageArray = this.storageArray[storeIndex].chats; - }, 500); - } - }); + this.MS.sendMessage('Cours/CoursGet', {}).subscribe( send => { + console.log(send.data); + this.dataSource.data = send.data as userList[]; + + }); + // this.chatService.getMessage() + // .subscribe((data: {user: string, message: string}) => { + // this.messageArray.push(data); + // if (this.room) { + // setTimeout( () => { + // this.storageArray = this.chatService.getStorage(); + // //@ts-ignore + // const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); + // //@ts-ignore + // this.messageArray = this.storageArray[storeIndex].chats; + // }, 500); + // } + // }); } - selectUserHandler(password: string): void { - this.selectedUser = this.userList.find(user => user.password === password); - this.room = this.selectedUser.room[this.currentUser.id]; - this.messageArray = []; - - this.storageArray = this.chatService.getStorage(); - // @ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); - - if (storeIndex > -1) { - // @ts-ignore - this.messageArray = this.storageArray[storeIndex].chats; - } - - // @ts-ignore - this.join(this.currentUser.name, this.room); - } + // selectUserHandler(password: string): void { + // //this.selectedUser = this.userList.find(user => user.password === password); + // this.room = this.selectedUser.room[this.currentUser.id]; + // this.messageArray = []; + // + // this.storageArray = this.chatService.getStorage(); + // // @ts-ignore + // const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); + // + // if (storeIndex > -1) { + // // @ts-ignore + // this.messageArray = this.storageArray[storeIndex].chats; + // } + // + // // @ts-ignore + // this.join(this.currentUser.name, this.room); + // } join(username: string, room: string): void { this.chatService.joinRoom({user: username, room: room}); @@ -114,35 +95,38 @@ export class GeneralComponent implements OnInit { { this.chatService.sendMessage({user:this.user, room:this.room, message:this.messageText}); - this.storageArray = this.chatService.getStorage(); - // @ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); - - if (storeIndex > -1) { - // @ts-ignore - this.storageArray[storeIndex].chats.push({ - user: this.currentUser.name, - message: this.messageText - }) - } else { - const updateStorage = { - room: this.room, - chats: [{ - user: this.currentUser.name, - message: this.messageText - }] - }; - // @ts-ignore - this.storageArray.push(updateStorage); - } - this.chatService.setStorage(this.storageArray); - this.messageText = ''; + // this.storageArray = this.chatService.getStorage(); + // // @ts-ignore + // const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); + // + // if (storeIndex > -1) { + // // @ts-ignore + // this.storageArray[storeIndex].chats.push({ + // user: this.currentUser.name, + // message: this.messageText + // }) + // } else { + // const updateStorage = { + // room: this.room, + // chats: [{ + // user: this.currentUser.name, + // message: this.messageText + // }] + // }; + // // @ts-ignore + // this.storageArray.push(updateStorage); + // } + // this.chatService.setStorage(this.storageArray); + // this.messageText = ''; } leave(){ - this.chatService.leaveRoom({user:this.user, room:this.room}); + this.chatService.leaveRoom({login:this.dataSource.data, room:this.room}); } } +export interface userList { + login: string; +} diff --git a/frontend/src/app/login/login.component.html b/frontend/src/app/login/login.component.html index 403c3a5..28e356d 100644 --- a/frontend/src/app/login/login.component.html +++ b/frontend/src/app/login/login.component.html @@ -10,7 +10,7 @@ + [(ngModel)]="login"> diff --git a/frontend/src/app/login/login.component.ts b/frontend/src/app/login/login.component.ts index bc34816..5ef93c3 100644 --- a/frontend/src/app/login/login.component.ts +++ b/frontend/src/app/login/login.component.ts @@ -11,41 +11,30 @@ import {AuthService} from "../services/auth/auth.service"; export class LoginComponent implements OnInit { - public password = ''; - public name = ''; + login = ''; + password = ''; + errorMessage = ''; - constructor( - private auth: AuthService, - private router: Router - ) { - - - } + constructor(private auth: AuthService, + private router: Router) { } ngOnInit(): void { } + showCredentials(): void { + console.log('Login :', this.login); + console.log('Password :', this.password); + this.auth.sendAuthentication(this.login, this.password).subscribe(data => { + this.auth.finalizeAuthentication(data); + if (this.auth.islog === true) { + this.router.navigateByUrl('/private'); + } else { + this.errorMessage = data.data.reason; + console.log(this.errorMessage); + } + }); - login() : void { - console.log(this.name, this.password); - if (this.auth.sendAuthentication(this.name, this.password) === true){ - this.auth.sendAuth(this.password); - this.router.navigateByUrl('/private'); - } else { - console.log("error"); - } } - - login2() : void { - console.log(this.name, this.password); - if (this.auth.sendAuthentication(this.name, this.password) === true){ - this.auth.sendAuth(this.password); - this.router.navigateByUrl('/general'); - } else { - console.log("error"); - } - } - } diff --git a/frontend/src/app/private/private.component.html b/frontend/src/app/private/private.component.html index 4e01e3b..775a86b 100644 --- a/frontend/src/app/private/private.component.html +++ b/frontend/src/app/private/private.component.html @@ -5,14 +5,12 @@
-

{{user?.name}}

+

@@ -28,7 +26,7 @@
diff --git a/frontend/src/app/private/private.component.ts b/frontend/src/app/private/private.component.ts index 49c9b88..b1a4812 100644 --- a/frontend/src/app/private/private.component.ts +++ b/frontend/src/app/private/private.component.ts @@ -2,6 +2,8 @@ import {NgModule, Component, OnInit, Input} from '@angular/core'; import {ChatService} from "../services/chat/chat.service"; import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import {AuthService} from "../services/auth/auth.service"; +import {MessageService} from "../services/message/message.service"; +import {MatTableDataSource} from "@angular/material/table"; @Component({ @@ -11,42 +13,7 @@ import {AuthService} from "../services/auth/auth.service"; }) export class PrivateComponent implements OnInit { - public userList = [ - { - id: 1, - name: 'Yuki Vachot', - login: 'yuki', - password: 'vachot1', - roomId: { - 2: 'room-1', - 3: 'room-2', - 4: 'room-3' - } - }, - { - id: 2, - name: 'Wilfried Vallee', - login: 'wilfried', - password: 'vallee2', - roomId: { - 1: 'room-1', - 3: 'room-4', - 4: 'room-5' - } - }, - { - id: 3, - name: 'Khai Phan', - login: 'khai', - password: 'phan3', - roomId: { - 1: 'room-2', - 2: 'room-4', - 4: 'room-6' - } - } - ]; - + dataSource = new MatTableDataSource(); // @ts-ignore public roomId: string; // @ts-ignore @@ -69,81 +36,88 @@ export class PrivateComponent implements OnInit { constructor( private Auth: AuthService, private chatService: ChatService, + private MS: MessageService ) { - this.currentUser = this.Auth.sendAuth(this.currentUser); - this.userList = this.userList.filter((user) => user.password !== this.currentUser.password.toString()); - console.log(this.userList); } ngOnInit(): void { - this.chatService.getMessage() - .subscribe((data: {user: string, message: string}) => { - this.messageArray.push(data); - if (this.roomId) { - setTimeout( () => { - this.storageArray = this.chatService.getStorage(); - //@ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); - //@ts-ignore - this.messageArray = this.storageArray[storeIndex].chats; - }, 500); - } - }); + this.MS.sendMessage('Cours/CoursGet', {}).subscribe( send => { + console.log(send.data); + this.dataSource.data = send.data as userList[]; + }); + + // this.chatService.getMessage() + // .subscribe((data: {user: string, message: string}) => { + // this.messageArray.push(data); + // if (this.roomId) { + // setTimeout( () => { + // this.storageArray = this.chatService.getStorage(); + // //@ts-ignore + // const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); + // //@ts-ignore + // this.messageArray = this.storageArray[storeIndex].chats; + // }, 500); + // } + // }); } - selectUserHandler(password: string): void { - this.selectedUser = this.userList.find(user => user.password === password); - this.roomId = this.selectedUser.roomId[this.currentUser.id]; - this.messageArray = []; - - this.storageArray = this.chatService.getStorage(); - // @ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); - - if (storeIndex > -1) { - // @ts-ignore - this.messageArray = this.storageArray[storeIndex].chats; - } - - this.join(this.currentUser.name, this.roomId); - } + // selectUserHandler(login: string): void { + // this.login = login; + // this.selectedUser = this.userList.find(user => user.password === password); + // this.roomId = this.selectedUser.roomId[this.currentUser.id]; + // this.messageArray = []; + // + // // this.storageArray = this.chatService.getStorage(); + // // // @ts-ignore + // // const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); + // // + // // if (storeIndex > -1) { + // // // @ts-ignore + // // this.messageArray = this.storageArray[storeIndex].chats; + // // } + // + // this.join(this.login); + // } join(username: string, roomId: string): void { - this.chatService.joinRoom({user: username, room: roomId}); + this.chatService.joinRoom({user: username}); } sendMessage(): void { this.chatService.sendMessage({ user: this.currentUser.name, - room: this.roomId, message: this.messageText }); - this.storageArray = this.chatService.getStorage(); - // @ts-ignore - const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); - - if (storeIndex > -1) { - // @ts-ignore - this.storageArray[storeIndex].chats.push({ - user: this.currentUser.name, - message: this.messageText - }) - } else { - const updateStorage = { - roomId: this.roomId, - chats: [{ - user: this.currentUser.name, - message: this.messageText - }] - }; - // @ts-ignore - this.storageArray.push(updateStorage); - } - this.chatService.setStorage(this.storageArray); + // this.storageArray = this.chatService.getStorage(); + // // @ts-ignore + // const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); + // + // if (storeIndex > -1) { + // // @ts-ignore + // this.storageArray[storeIndex].chats.push({ + // user: this.currentUser.name, + // message: this.messageText + // }) + // } else { + // const updateStorage = { + // roomId: this.roomId, + // chats: [{ + // user: this.currentUser.name, + // message: this.messageText + // }] + // }; + // // @ts-ignore + // this.storageArray.push(updateStorage); + // } + // this.chatService.setStorage(this.storageArray); this.messageText = ''; } } + +export interface userList { + login: string; +} diff --git a/frontend/src/app/services/auth/auth.service.ts b/frontend/src/app/services/auth/auth.service.ts index 01ff8d9..a740fe4 100644 --- a/frontend/src/app/services/auth/auth.service.ts +++ b/frontend/src/app/services/auth/auth.service.ts @@ -1,5 +1,7 @@ import { Injectable } from '@angular/core'; import {Observable} from "rxjs"; +import {JSdata, MessageService} from "../message/message.service"; +import {HttpClient} from "@angular/common/http"; @@ -10,74 +12,31 @@ import {Observable} from "rxjs"; export class AuthService { // @ts-ignore - public roomId: string; - // @ts-ignore - public name: string; - // @ts-ignore - public login: string; + islog: boolean; - // @ts-ignore - public showScreen: boolean; - // @ts-ignore - public password: string; - // @ts-ignore - public currentUser; + constructor( + private http: HttpClient, + private MS: MessageService + ) {} - public userList = [ - { - id: 1, - name: 'Yuki Vachot', - login: 'yuki', - password: 'vachot1', - roomId: { - 2: 'room-1', - 3: 'room-2', - 4: 'room-3' - } - }, - { - id: 2, - name: 'Wilfried Vallee', - login: 'wilfried', - password: 'vallee2', - roomId: { - 1: 'room-1', - 3: 'room-4', - 4: 'room-5' - } - }, - { - id: 3, - name: 'Khai Phan', - login: 'khai', - password: 'phan3', - roomId: { - 1: 'room-2', - 2: 'room-4', - 4: 'room-6' - } + sendAuthentication(login: string, password: string): Observable { + const data = new FormData(); + if (login !== null && login !== undefined && password !== null && password !== undefined) { + data.append(login, password); } - ]; - - constructor() {} - - sendAuthentication(login:string, password: string): boolean { - this.login = login; - this.password = password; - this.currentUser = this.userList.find(user => user.password === this.password.toString()); - this.userList = this.userList.filter((user) => user.password !== this.password.toString()); - if(this.currentUser) { - this.showScreen = true; - } else { - console.log("Password Error", this.password.toString()); - } - return this.showScreen ; + return this.MS.sendMessage('checkLogin', { + login : login, + Password: password + }); } - sendAuth(password: string): any { - this.password = password; - return this.currentUser ; + finalizeAuthentication(data: JSdata): void{ + if (data.status === 'ok') { + this.islog = true; + } else { + this.islog = false; + } } } diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index f56ff47..4385f27 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -3,7 +3,8 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false + production: false, + urlCL: 'http://service-authentication:3000' }; /*