Commit bed8c44e authored by Manish Kumar's avatar Manish Kumar
Browse files

Merge branch 'master' of gitlab.unige.ch:Manish.Kumar/webpoke

parents e7c88d1a ebfe0e59
......@@ -24,6 +24,12 @@ exports.auth = (req, res) => {
});
};
exports.desAuth = (req, res) => {
req.session.destroy((err) => {
res.redirect('/')
});
}
exports.checkLogin = (req, response) => {
if (req.session.loggedIn) {
response.send({ res: true, body: req.session.pseudo, uid: req.session.uid });
......
......@@ -18,7 +18,7 @@ Partie.create = (uid, pseudo, result) => {
}
console.log("created request: " + pseudo + " " + uid);
result(null, {id: res.insertId});
result(null, { id: res.insertId });
});
};
......
......@@ -22,4 +22,7 @@ module.exports = app => {
//Friend declined
app.post("/nayami", joueur.refuse);
// Logout
app.get("/logout", joueur.desAuth);
};
\ No newline at end of file
......@@ -20,21 +20,21 @@ module.exports.listen = function(app) {
usersMap.set(username, socket.id)
console.log("new user added, connected users : " + connectedUsers);
// echo globally (all clients) that a person has connected
socket.broadcast.emit('user joined', {
username: username,
numUsers: numUsers
});
});
socket.on('get active users', () =>{
socket.on('get active users', () => {
var temp = [];
var user = undefined;
Array.from(usersMap.keys()).map(key => {
//console.log(key);
if(usersMap.get(key) == socket.id){user = key};
});
connectedUsers.forEach(curUser => {if(curUser != user) temp.push(curUser);});
if (usersMap.get(key) == socket.id) { user = key };
});
connectedUsers.forEach(curUser => { if (curUser != user) temp.push(curUser); });
io.to(socket.id).emit('send list', temp);
});
......@@ -49,13 +49,13 @@ module.exports.listen = function(app) {
var disconnectedUser = undefined;
Array.from(usersMap.keys()).map(key => {
//console.log(key);
if(usersMap.get(key) == socket.id){disconnectedUser = key};
});
if (usersMap.get(key) == socket.id) { disconnectedUser = key };
});
console.log('user disconnected : ' + disconnectedUser);
if(disconnectedUser != undefined){
for(let i = 0; i < connectedUsers.length; i++){
if (disconnectedUser != undefined) {
for (let i = 0; i < connectedUsers.length; i++) {
//console.log(disconnectedUser + " " + connectedUsers[i]);
if(connectedUsers[i] == disconnectedUser) connectedUsers.splice(i, 1);
if (connectedUsers[i] == disconnectedUser) connectedUsers.splice(i, 1);
}
usersMap.delete(disconnectedUser);
}
......
......@@ -38,7 +38,6 @@ export class AccountMenuComponent implements OnInit {
if(response.res){
this.chatService.notify(response.body);
this.accountData.updateUsername(response.body);
//location.reload();
} else {
console.log("wrong user");
}
......
......@@ -22,6 +22,12 @@
<div class="container py-3" *ngIf="amis!=null">
<div *ngFor="let ami of amis; let i=index">
<h4>{{ami.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="refuser(ami)">
<h6>Effacer</h6>
</div>
<!-- <div class="btn btn-primary" (click)="">
<h6>Défier</h6>
</div> -->
</div>
</div>
</div>
......
......@@ -50,17 +50,19 @@ export class FriendsMenuComponent implements OnInit {
}
ordre(){
this.httpClient.get('http://localhost:3000/allfriends', { responseType: 'json', withCredentials:true }).subscribe((res => {this.resultat = res; this.isFriend(); console.log(res)}))
this.httpClient.get('http://localhost:3000/allfriends', { responseType: 'json', withCredentials:true }).subscribe(res => {this.resultat = res; this.isFriend(); console.log(res)})
}
isFriend(){
if(this.resultat.res.length > 0){
for(let i = 0; i < this.resultat.res.length; i++){
if(this.resultat.res[i].accept === 1){
this.amis.push(this.resultat.res[i])
} else {
this.requests.push(this.resultat.res[i])
}
}
}
}
}
accepter(idAmi){
......
<h1>it works!</h1>
\ No newline at end of file
<h1>it works!</h1>
<div class="btn btn-primary" (click)="logout()">
<h2>Logout</h2>
</div>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { AccountSyncService } from "../services/account-sync/account-sync.service";
@Component({
selector: 'app-profil',
......@@ -9,7 +11,13 @@ import { HttpClient } from '@angular/common/http';
export class ProfilComponent implements OnInit {
user: String;
res: any[];
constructor(private http: HttpClient) { }
constructor(private httpClient: HttpClient, private router: Router, private accountData: AccountSyncService) { }
logout(){
this.httpClient.get("http://localHost:3000/logout", { withCredentials: true}).subscribe( (res => { console.log(res) }));
this.accountData.updateUsername("Account");
this.router.navigate(['/pokedex']);
}
ngOnInit(): void {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment