From 52c19cee63cd80e3d3315e9c2141c3ad0ce20ef1 Mon Sep 17 00:00:00 2001 From: NyxiumYuuki Date: Sat, 29 May 2021 16:01:57 +0200 Subject: [PATCH 1/5] Change messageservice, base url added for different server --- frontend/src/app/services/auth/auth.service.ts | 3 ++- frontend/src/app/services/message/message.service.ts | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/services/auth/auth.service.ts b/frontend/src/app/services/auth/auth.service.ts index fa68650..2b070eb 100644 --- a/frontend/src/app/services/auth/auth.service.ts +++ b/frontend/src/app/services/auth/auth.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import {Observable} from "rxjs"; import {JSdata, MessageService} from "../message/message.service"; +import {environment} from "../../../environments/environment"; @Injectable({ providedIn: 'root' @@ -22,7 +23,7 @@ export class AuthService { } sendAuthentication(login: string, password: string): Observable { - return this.messageService.sendMessage('checkLogin', { + return this.messageService.sendMessage(environment.urlCL,'checkLogin', { 'login': login, 'password': password }); diff --git a/frontend/src/app/services/message/message.service.ts b/frontend/src/app/services/message/message.service.ts index 746899a..13b1560 100644 --- a/frontend/src/app/services/message/message.service.ts +++ b/frontend/src/app/services/message/message.service.ts @@ -1,8 +1,6 @@ import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/common/http'; - import {Observable} from 'rxjs'; -import {environment} from "../../../environments/environment"; export interface JSdata{ status: string; @@ -16,8 +14,8 @@ export interface JSdata{ export class MessageService { constructor(private http: HttpClient) { } - sendMessage(url: string, data: any): Observable { - const CreatURL = environment.urlCL.concat('/').concat(url); + sendMessage(baseurl: string, url: string, data: any): Observable { + const CreatURL = baseurl.concat('/').concat(url); //console.log(CreatURL, data); return this.http.post( CreatURL, From 596e890d6cb2a22d04a40707106d7f7f56bd7205 Mon Sep 17 00:00:00 2001 From: NyxiumYuuki Date: Sat, 29 May 2021 16:02:24 +0200 Subject: [PATCH 2/5] Add getUsers --- backend/service-authentication/getUsers.js | 17 +++++++++++++++++ .../service-authentication/mongodbQueries.js | 13 +++++++++++++ backend/service-authentication/server.js | 5 +++++ 3 files changed, 35 insertions(+) create mode 100644 backend/service-authentication/getUsers.js diff --git a/backend/service-authentication/getUsers.js b/backend/service-authentication/getUsers.js new file mode 100644 index 0000000..2dd4645 --- /dev/null +++ b/backend/service-authentication/getUsers.js @@ -0,0 +1,17 @@ +const {sendError, sendMessage} = require ("./message"); +const queries = require('./mongodbQueries'); + +async function getUsers (req,res) { + if (typeof req.body.username === 'undefined') + return sendError(res, 'Vous n\'avez pas envoyé le champ username'); + + const users = await queries.getUsersQuery(req.body.username); + console.log(users); + if (users){ + return sendMessage(res, users); + } + else{ + return sendError(res, 'no users'); + } +} +module.exports = getUsers; diff --git a/backend/service-authentication/mongodbQueries.js b/backend/service-authentication/mongodbQueries.js index 7db7e8c..e9028f2 100644 --- a/backend/service-authentication/mongodbQueries.js +++ b/backend/service-authentication/mongodbQueries.js @@ -29,3 +29,16 @@ function register(login, password){ } module.exports.register = register; +function getUsersQuery(username){ + return new Promise((resolve, reject) => { + mongoDB.collection(config.mongodbUtilisateurs).find( + { $and: [{'login': {$ne: 'Server'}}, {'login': {$ne: username}}]}, + {projection: {_id: 0, password: 0}} + ).toArray(function (err, result){ + if(err) throw err; + resolve(result); + }); + }); +} +module.exports.getUsersQuery = getUsersQuery + diff --git a/backend/service-authentication/server.js b/backend/service-authentication/server.js index 0acca8f..cb75bfa 100644 --- a/backend/service-authentication/server.js +++ b/backend/service-authentication/server.js @@ -18,6 +18,7 @@ mongoConnect.connectToServer(function( err, client ) { if (err) console.log(err); const checkLogin = require('./checkLogin'); const register = require('./register'); + const getUsers = require('./getUsers'); const queries = require('./mongodbQueries'); const auth = require('./auth'); @@ -41,6 +42,10 @@ mongoConnect.connectToServer(function( err, client ) { register(req,res); }); + app.post('/getUsers', (req, res) => { + getUsers(req,res); + }); + app.listen(port, () => { console.log (`listening on port ${port}`); }); From 7f718ccdc8c78a3ef8ce40fa19f09b93fb140aad Mon Sep 17 00:00:00 2001 From: NyxiumYuuki Date: Sat, 29 May 2021 16:02:58 +0200 Subject: [PATCH 3/5] Remove test html file --- backend/service-message/server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/service-message/server.js b/backend/service-message/server.js index f57e942..9798225 100644 --- a/backend/service-message/server.js +++ b/backend/service-message/server.js @@ -22,9 +22,9 @@ app.use(bodyParser.json()); app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true})); app.use(cookieParser()); -app.get('/', (req, res) => { - res.sendFile(__dirname + '/index.html'); -}); +// app.get('/', (req, res) => { +// res.sendFile(__dirname + '/index.html'); +// }); io.on('connection',socket => { From d79a8fd73509ec406449c499f8d5d694299582cf Mon Sep 17 00:00:00 2001 From: NyxiumYuuki Date: Sat, 29 May 2021 16:03:41 +0200 Subject: [PATCH 4/5] get users login for a test --- frontend/src/app/general/general.component.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/general/general.component.ts b/frontend/src/app/general/general.component.ts index 81e43b1..096d68b 100644 --- a/frontend/src/app/general/general.component.ts +++ b/frontend/src/app/general/general.component.ts @@ -1,7 +1,8 @@ -import {Component, ElementRef, Inject, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {ChatInfo, ChatService} from "../services/chat/chat.service"; import {environment} from "../../environments/environment"; import {DatePipe} from "@angular/common"; +import {MessageService} from "../services/message/message.service"; @Component({ selector: 'app-general', @@ -18,10 +19,20 @@ export class GeneralComponent implements OnInit { @ViewChild('ulMessages') ulMsg: ElementRef; - constructor(private chatservice: ChatService, private pipe: DatePipe) {} + constructor(private chatservice: ChatService, private pipe: DatePipe, private messageservice: MessageService) {} ngOnInit() { console.log('General working'); + this.messageservice.sendMessage(environment.urlCL,'getUsers', {username: this.username}).subscribe( + data => { + if (data.status !== 'ok'){ + console.log(data.data.reason); + } + else{ + console.log(data.data); + } + } + ); this.chatservice.setUrl(environment.urlCG); this.chatservice.setRoom(this.room); this.chatservice.onNewMessage(this.room).subscribe((infos: ChatInfo[]) => { From 3aaddde24ed4b8347f52ce803052b79037d6af65 Mon Sep 17 00:00:00 2001 From: NyxiumYuuki Date: Sat, 29 May 2021 16:03:58 +0200 Subject: [PATCH 5/5] add directory keys --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d253f32..d0638fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,7 @@ services: volumes: - backend/service-authentication - backend/service-authentication/node_modules + - backend/service-authentication/keys ports: - 3000:3000 depends_on: @@ -53,7 +54,7 @@ services: image: mongo container_name: mongodb-authentication volumes: - - ./backend/service-authentication/database:/data/db + - ./backend/service-authentication/database:/data/db-authentication ports: - 27017:27017 @@ -61,6 +62,6 @@ services: image: mongo container_name: mongodb-message volumes: - - ./backend/service-message/database:/data/db + - ./backend/service-message/database:/data/db-message ports: - 27020:27017 \ No newline at end of file