third commit
This commit is contained in:
parent
87d97cf4fa
commit
18600e2874
8 changed files with 184 additions and 281 deletions
|
|
@ -5,14 +5,12 @@
|
|||
|
||||
<div class="user-list-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"/>
|
||||
<p class="username">{{user?.name}}</p>
|
||||
<p class="username"></p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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<userList>();
|
||||
// @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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<input type="text"
|
||||
placeholder="Entrez votre login"
|
||||
class="form-control"
|
||||
[(ngModel)]="name">
|
||||
[(ngModel)]="login">
|
||||
<input type="text"
|
||||
placeholder="Entrez votre password"
|
||||
class="form-control"
|
||||
|
|
@ -21,8 +21,8 @@
|
|||
</div>
|
||||
|
||||
<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) = "login2()">Connexion Générale</button>
|
||||
<button class="btn btn-sm btn-primary" (click) = "showCredentials()">Connexion Privée</button>
|
||||
<button class="btn btn-sm btn-primary" (click) = "showCredentials()">Connexion Générale</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,12 @@
|
|||
|
||||
<div class="user-list-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"/>
|
||||
<p class="username">{{user?.name}}</p>
|
||||
<p class="username"></p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -28,7 +26,7 @@
|
|||
|
||||
<div class="chat-body">
|
||||
<div *ngFor="let item of messageArray"
|
||||
[ngClass]="{'same-user' : item?.user === currentUser?.name}"
|
||||
|
||||
>
|
||||
<!---->
|
||||
|
||||
|
|
|
|||
|
|
@ -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<userList>();
|
||||
// @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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<JSdata> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
Reference in a new issue