Merge branch 'frontend_test_general' into 'master'
Frontend test general See merge request groupe100idee/chatless!3
This commit is contained in:
commit
7c35bbaeb7
8 changed files with 58 additions and 12 deletions
17
backend/service-authentication/getUsers.js
Normal file
17
backend/service-authentication/getUsers.js
Normal file
|
|
@ -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;
|
||||||
|
|
@ -29,3 +29,16 @@ function register(login, password){
|
||||||
}
|
}
|
||||||
module.exports.register = register;
|
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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ mongoConnect.connectToServer(function( err, client ) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
const checkLogin = require('./checkLogin');
|
const checkLogin = require('./checkLogin');
|
||||||
const register = require('./register');
|
const register = require('./register');
|
||||||
|
const getUsers = require('./getUsers');
|
||||||
const queries = require('./mongodbQueries');
|
const queries = require('./mongodbQueries');
|
||||||
const auth = require('./auth');
|
const auth = require('./auth');
|
||||||
|
|
||||||
|
|
@ -41,6 +42,10 @@ mongoConnect.connectToServer(function( err, client ) {
|
||||||
register(req,res);
|
register(req,res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/getUsers', (req, res) => {
|
||||||
|
getUsers(req,res);
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log (`listening on port ${port}`);
|
console.log (`listening on port ${port}`);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ app.use(bodyParser.json());
|
||||||
app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true}));
|
app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true}));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
// app.get('/', (req, res) => {
|
||||||
res.sendFile(__dirname + '/index.html');
|
// res.sendFile(__dirname + '/index.html');
|
||||||
});
|
// });
|
||||||
|
|
||||||
io.on('connection',socket => {
|
io.on('connection',socket => {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- backend/service-authentication
|
- backend/service-authentication
|
||||||
- backend/service-authentication/node_modules
|
- backend/service-authentication/node_modules
|
||||||
|
- backend/service-authentication/keys
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 3000:3000
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
@ -53,7 +54,7 @@ services:
|
||||||
image: mongo
|
image: mongo
|
||||||
container_name: mongodb-authentication
|
container_name: mongodb-authentication
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend/service-authentication/database:/data/db
|
- ./backend/service-authentication/database:/data/db-authentication
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
|
|
||||||
|
|
@ -61,6 +62,6 @@ services:
|
||||||
image: mongo
|
image: mongo
|
||||||
container_name: mongodb-message
|
container_name: mongodb-message
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend/service-message/database:/data/db
|
- ./backend/service-message/database:/data/db-message
|
||||||
ports:
|
ports:
|
||||||
- 27020:27017
|
- 27020:27017
|
||||||
|
|
@ -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 {ChatInfo, ChatService} from "../services/chat/chat.service";
|
||||||
import {environment} from "../../environments/environment";
|
import {environment} from "../../environments/environment";
|
||||||
import {DatePipe} from "@angular/common";
|
import {DatePipe} from "@angular/common";
|
||||||
|
import {MessageService} from "../services/message/message.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-general',
|
selector: 'app-general',
|
||||||
|
|
@ -18,10 +19,20 @@ export class GeneralComponent implements OnInit {
|
||||||
@ViewChild('ulMessages') ulMsg: ElementRef;
|
@ViewChild('ulMessages') ulMsg: ElementRef;
|
||||||
|
|
||||||
|
|
||||||
constructor(private chatservice: ChatService, private pipe: DatePipe) {}
|
constructor(private chatservice: ChatService, private pipe: DatePipe, private messageservice: MessageService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
console.log('General working');
|
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.setUrl(environment.urlCG);
|
||||||
this.chatservice.setRoom(this.room);
|
this.chatservice.setRoom(this.room);
|
||||||
this.chatservice.onNewMessage(this.room).subscribe((infos: ChatInfo[]) => {
|
this.chatservice.onNewMessage(this.room).subscribe((infos: ChatInfo[]) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +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 {JSdata, MessageService} from "../message/message.service";
|
||||||
|
import {environment} from "../../../environments/environment";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|
@ -22,7 +23,7 @@ export class AuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendAuthentication(login: string, password: string): Observable<JSdata> {
|
sendAuthentication(login: string, password: string): Observable<JSdata> {
|
||||||
return this.messageService.sendMessage('checkLogin', {
|
return this.messageService.sendMessage(environment.urlCL,'checkLogin', {
|
||||||
'login': login,
|
'login': login,
|
||||||
'password': password
|
'password': password
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {environment} from "../../../environments/environment";
|
|
||||||
|
|
||||||
export interface JSdata{
|
export interface JSdata{
|
||||||
status: string;
|
status: string;
|
||||||
|
|
@ -16,8 +14,8 @@ export interface JSdata{
|
||||||
export class MessageService {
|
export class MessageService {
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
sendMessage(url: string, data: any): Observable<JSdata> {
|
sendMessage(baseurl: string, url: string, data: any): Observable<JSdata> {
|
||||||
const CreatURL = environment.urlCL.concat('/').concat(url);
|
const CreatURL = baseurl.concat('/').concat(url);
|
||||||
//console.log(CreatURL, data);
|
//console.log(CreatURL, data);
|
||||||
return this.http.post<JSdata>(
|
return this.http.post<JSdata>(
|
||||||
CreatURL,
|
CreatURL,
|
||||||
|
|
|
||||||
Reference in a new issue