Commit ebfe0e59 authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

you can now logout, cya pokemon trainer

parent e7280e68
......@@ -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 });
......
......@@ -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");
}
......
......@@ -50,7 +50,7 @@ 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(){
......
<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