third commit

This commit is contained in:
wilfried 2021-05-28 14:57:38 +02:00
parent 87d97cf4fa
commit 18600e2874
8 changed files with 184 additions and 281 deletions

View file

@ -5,14 +5,12 @@
<div class="user-list-card"> <div class="user-list-card">
<div class="user-card" <div class="user-card"
[ngClass]="{'active' : user?.password === selectedUser?.password}"
*ngFor="let user of userList"
(click)="selectUserHandler(user.password)"
> >
<!----> <!---->
<img src="../../assets/image/user.png" height="25" width="25"/> <img src="../../assets/image/user.png" height="25" width="25"/>
<p class="username">{{user?.name}}</p> <p class="username"></p>
</div> </div>
</div> </div>

View file

@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ChatService} from "../services/chat/chat.service"; import {ChatService} from "../services/chat/chat.service";
import {AuthService} from "../services/auth/auth.service"; import {AuthService} from "../services/auth/auth.service";
import {MessageService} from "../services/message/message.service";
import {MatTableDataSource} from "@angular/material/table";
@Component({ @Component({
selector: 'app-general', selector: 'app-general',
@ -8,8 +10,7 @@ import {AuthService} from "../services/auth/auth.service";
styleUrls: ['./general.component.scss'] styleUrls: ['./general.component.scss']
}) })
export class GeneralComponent implements OnInit { export class GeneralComponent implements OnInit {
public currentUser; dataSource = new MatTableDataSource<userList>();
// @ts-ignore // @ts-ignore
public user:String; public user:String;
// @ts-ignore // @ts-ignore
@ -24,42 +25,17 @@ export class GeneralComponent implements OnInit {
// @ts-ignore // @ts-ignore
public password: string; public password: string;
// @ts-ignore
public currentUser;
// @ts-ignore // @ts-ignore
public selectedUser; 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, constructor(private Auth: AuthService,
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() this.chatService.newUserJoined()
.subscribe(data=> this.messageArray.push(data)); .subscribe(data=> this.messageArray.push(data));
@ -72,39 +48,44 @@ export class GeneralComponent implements OnInit {
.subscribe(data=>this.messageArray.push(data)); .subscribe(data=>this.messageArray.push(data));
} }
ngOnInit(): void { ngOnInit(): void {
this.chatService.getMessage() this.MS.sendMessage('Cours/CoursGet', {}).subscribe( send => {
.subscribe((data: {user: string, message: string}) => { console.log(send.data);
this.messageArray.push(data); this.dataSource.data = send.data as userList[];
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.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 { // selectUserHandler(password: string): void {
this.selectedUser = this.userList.find(user => user.password === password); // //this.selectedUser = this.userList.find(user => user.password === password);
this.room = this.selectedUser.room[this.currentUser.id]; // this.room = this.selectedUser.room[this.currentUser.id];
this.messageArray = []; // this.messageArray = [];
//
this.storageArray = this.chatService.getStorage(); // this.storageArray = this.chatService.getStorage();
// @ts-ignore // // @ts-ignore
const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); // const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room);
//
if (storeIndex > -1) { // if (storeIndex > -1) {
// @ts-ignore // // @ts-ignore
this.messageArray = this.storageArray[storeIndex].chats; // this.messageArray = this.storageArray[storeIndex].chats;
} // }
//
// @ts-ignore // // @ts-ignore
this.join(this.currentUser.name, this.room); // this.join(this.currentUser.name, this.room);
} // }
join(username: string, room: string): void { join(username: string, room: string): void {
this.chatService.joinRoom({user: username, room: room}); 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.chatService.sendMessage({user:this.user, room:this.room, message:this.messageText});
this.storageArray = this.chatService.getStorage(); // this.storageArray = this.chatService.getStorage();
// @ts-ignore // // @ts-ignore
const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room); // const storeIndex = this.storageArray.findIndex((storage) => storage.room === this.room);
//
if (storeIndex > -1) { // if (storeIndex > -1) {
// @ts-ignore // // @ts-ignore
this.storageArray[storeIndex].chats.push({ // this.storageArray[storeIndex].chats.push({
user: this.currentUser.name, // user: this.currentUser.name,
message: this.messageText // message: this.messageText
}) // })
} else { // } else {
const updateStorage = { // const updateStorage = {
room: this.room, // room: this.room,
chats: [{ // chats: [{
user: this.currentUser.name, // user: this.currentUser.name,
message: this.messageText // message: this.messageText
}] // }]
}; // };
// @ts-ignore // // @ts-ignore
this.storageArray.push(updateStorage); // this.storageArray.push(updateStorage);
} // }
this.chatService.setStorage(this.storageArray); // this.chatService.setStorage(this.storageArray);
this.messageText = ''; // this.messageText = '';
} }
leave(){ 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;
}

View file

@ -10,7 +10,7 @@
<input type="text" <input type="text"
placeholder="Entrez votre login" placeholder="Entrez votre login"
class="form-control" class="form-control"
[(ngModel)]="name"> [(ngModel)]="login">
<input type="text" <input type="text"
placeholder="Entrez votre password" placeholder="Entrez votre password"
class="form-control" class="form-control"
@ -21,8 +21,8 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-sm btn-primary" (click) = "login()">Connexion Privée</button> <button class="btn btn-sm btn-primary" (click) = "showCredentials()">Connexion Privée</button>
<button class="btn btn-sm btn-primary" (click) = "login2()">Connexion Générale</button> <button class="btn btn-sm btn-primary" (click) = "showCredentials()">Connexion Générale</button>
</div> </div>
</div> </div>

View file

@ -11,41 +11,30 @@ import {AuthService} from "../services/auth/auth.service";
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
public password = ''; login = '';
public name = ''; password = '';
errorMessage = '';
constructor( constructor(private auth: AuthService,
private auth: AuthService, private router: Router) { }
private router: Router
) {
}
ngOnInit(): void { ngOnInit(): void {
} }
showCredentials(): void {
login() : void { console.log('Login :', this.login);
console.log(this.name, this.password); console.log('Password :', this.password);
if (this.auth.sendAuthentication(this.name, this.password) === true){ this.auth.sendAuthentication(this.login, this.password).subscribe(data => {
this.auth.sendAuth(this.password); this.auth.finalizeAuthentication(data);
if (this.auth.islog === true) {
this.router.navigateByUrl('/private'); this.router.navigateByUrl('/private');
} else { } else {
console.log("error"); this.errorMessage = data.data.reason;
} console.log(this.errorMessage);
} }
});
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");
} }
}
} }

View file

@ -5,14 +5,12 @@
<div class="user-list-card"> <div class="user-list-card">
<div class="user-card" <div class="user-card"
[ngClass]="{'active' : user?.password === selectedUser?.password}"
*ngFor="let user of userList"
(click)="selectUserHandler(user.password)"
> >
<!----> <!---->
<img src="../../assets/image/user.png" height="25" width="25"/> <img src="../../assets/image/user.png" height="25" width="25"/>
<p class="username">{{user?.name}}</p> <p class="username"></p>
</div> </div>
</div> </div>
@ -28,7 +26,7 @@
<div class="chat-body"> <div class="chat-body">
<div *ngFor="let item of messageArray" <div *ngFor="let item of messageArray"
[ngClass]="{'same-user' : item?.user === currentUser?.name}"
> >
<!----> <!---->

View file

@ -2,6 +2,8 @@ import {NgModule, Component, OnInit, Input} from '@angular/core';
import {ChatService} from "../services/chat/chat.service"; import {ChatService} from "../services/chat/chat.service";
import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {AuthService} from "../services/auth/auth.service"; import {AuthService} from "../services/auth/auth.service";
import {MessageService} from "../services/message/message.service";
import {MatTableDataSource} from "@angular/material/table";
@Component({ @Component({
@ -11,42 +13,7 @@ import {AuthService} from "../services/auth/auth.service";
}) })
export class PrivateComponent implements OnInit { export class PrivateComponent implements OnInit {
public userList = [ dataSource = new MatTableDataSource<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'
}
}
];
// @ts-ignore // @ts-ignore
public roomId: string; public roomId: string;
// @ts-ignore // @ts-ignore
@ -69,81 +36,88 @@ export class PrivateComponent implements OnInit {
constructor( constructor(
private Auth: AuthService, private Auth: AuthService,
private chatService: ChatService, 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 { ngOnInit(): void {
this.chatService.getMessage() this.MS.sendMessage('Cours/CoursGet', {}).subscribe( send => {
.subscribe((data: {user: string, message: string}) => { console.log(send.data);
this.messageArray.push(data); this.dataSource.data = send.data as userList[];
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.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 { // selectUserHandler(login: string): void {
this.selectedUser = this.userList.find(user => user.password === password); // this.login = login;
this.roomId = this.selectedUser.roomId[this.currentUser.id]; // this.selectedUser = this.userList.find(user => user.password === password);
this.messageArray = []; // this.roomId = this.selectedUser.roomId[this.currentUser.id];
// this.messageArray = [];
this.storageArray = this.chatService.getStorage(); //
// @ts-ignore // // this.storageArray = this.chatService.getStorage();
const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); // // // @ts-ignore
// // const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId);
if (storeIndex > -1) { // //
// @ts-ignore // // if (storeIndex > -1) {
this.messageArray = this.storageArray[storeIndex].chats; // // // @ts-ignore
} // // this.messageArray = this.storageArray[storeIndex].chats;
// // }
this.join(this.currentUser.name, this.roomId); //
} // this.join(this.login);
// }
join(username: string, roomId: string): void { join(username: string, roomId: string): void {
this.chatService.joinRoom({user: username, room: roomId}); this.chatService.joinRoom({user: username});
} }
sendMessage(): void { sendMessage(): void {
this.chatService.sendMessage({ this.chatService.sendMessage({
user: this.currentUser.name, user: this.currentUser.name,
room: this.roomId,
message: this.messageText message: this.messageText
}); });
this.storageArray = this.chatService.getStorage(); // this.storageArray = this.chatService.getStorage();
// @ts-ignore // // @ts-ignore
const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId); // const storeIndex = this.storageArray.findIndex((storage) => storage.roomId === this.roomId);
//
if (storeIndex > -1) { // if (storeIndex > -1) {
// @ts-ignore // // @ts-ignore
this.storageArray[storeIndex].chats.push({ // this.storageArray[storeIndex].chats.push({
user: this.currentUser.name, // user: this.currentUser.name,
message: this.messageText // message: this.messageText
}) // })
} else { // } else {
const updateStorage = { // const updateStorage = {
roomId: this.roomId, // roomId: this.roomId,
chats: [{ // chats: [{
user: this.currentUser.name, // user: this.currentUser.name,
message: this.messageText // message: this.messageText
}] // }]
}; // };
// @ts-ignore // // @ts-ignore
this.storageArray.push(updateStorage); // this.storageArray.push(updateStorage);
} // }
this.chatService.setStorage(this.storageArray); // this.chatService.setStorage(this.storageArray);
this.messageText = ''; this.messageText = '';
} }
} }
export interface userList {
login: string;
}

View file

@ -1,5 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {Observable} from "rxjs"; 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 { export class AuthService {
// @ts-ignore // @ts-ignore
public roomId: string; islog: boolean;
// @ts-ignore
public name: string;
// @ts-ignore
public login: string;
// @ts-ignore
public showScreen: boolean;
// @ts-ignore constructor(
public password: string; private http: HttpClient,
// @ts-ignore private MS: MessageService
public currentUser; ) {}
public userList = [ sendAuthentication(login: string, password: string): Observable<JSdata> {
{ const data = new FormData();
id: 1, if (login !== null && login !== undefined && password !== null && password !== undefined) {
name: 'Yuki Vachot', data.append(login, password);
login: 'yuki',
password: 'vachot1',
roomId: {
2: 'room-1',
3: 'room-2',
4: 'room-3'
} }
}, return this.MS.sendMessage('checkLogin', {
{ login : login,
id: 2, Password: password
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'
}
}
];
constructor() {} finalizeAuthentication(data: JSdata): void{
if (data.status === 'ok') {
sendAuthentication(login:string, password: string): boolean { this.islog = true;
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 { } else {
console.log("Password Error", this.password.toString()); this.islog = false;
} }
return this.showScreen ;
}
sendAuth(password: string): any {
this.password = password;
return this.currentUser ;
} }
} }

View file

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false production: false,
urlCL: 'http://service-authentication:3000'
}; };
/* /*