Skip to content

Commit

Permalink
#157801301 resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
OlatunjiYso committed Jun 25, 2018
2 parents 1bdc34e + 82c0231 commit 3937521
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/controllers/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ exports.saveGame = (req, res) => {
Game.findOne({ gameId: req.body.gameId })
.exec((err, game) => {
if (err) return res.status(500).json({ message: 'An error occured' });
if (!game && req.body.players.length < 6) return res.status(404).json({ message: 'Game not found' });
if (!game && req.body.players.length === 6) {
if (!game && req.body.players.length < 12) return res.status(404).json({ message: 'Game not found' });
if (!game && req.body.players.length === 12) {
const newGame = new Game(req.body);
newGame.save((err) => {
if (err) return err;
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Module dependencies.
*/
const mongoose = require('mongoose'),
Game = mongoose.model('Game'),
User = mongoose.model('User');
const avatars = require('./avatars').all();
const jwt = require('jsonwebtoken');
Expand Down Expand Up @@ -445,3 +446,41 @@ exports.searchUser = (req, res) => {
});
});
};


exports.profile = (req, res) => {
const { id } = req.params;
const details = {};
User.findById({ _id: id }).then((user) => {
if (!user) {
return res.status(404).json({
message: 'User Not Found',
});
}
Game.find({ gameWinner: user.username })
.then((games) => {
details.id = user._id;
details.email = user.email;
details.name = user.name;
details.username = user.username;
details.image = user.profileImage;
details.gamesWon = games.length;
Game.find().exec((err, games) => {
if (err) {
return res.status(400).json({
message: 'Error Occured'
});
}
const userGameLog = games.map(game => ({
gameId: game.gameId,
playedAt: game.played,
log: game.players
.filter(player => player.username === user.username),
gameWinner: game.gameWinner === user.username ? 'WON' : 'LOST'
}));
details.userGame = userGameLog.filter(eachUserLog => eachUserLog.log.length !== 0);
return res.status(200).json(details);
});
});
}).catch(() => res.status(500).json({ message: 'Server Error' }));
};
2 changes: 1 addition & 1 deletion app/views/includes/foot.jade
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ script(type='text/javascript', src='https://code.angularjs.org/1.1.5/angular-coo
//Angular UI
script(type='text/javascript', src='/lib/angular-bootstrap/ui-bootstrap-tpls.js')
script(type='text/javascript', src='/lib/angular-ui-utils/modules/route/route.js')
script(type='text/javascript', src='https://cdn.jsdelivr.net/npm/jwt-decode@2.2.0/build/jwt-decode.min.js')

//Toastr
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js')
Expand All @@ -42,7 +43,6 @@ script(type='text/javascript', src='/js/controllers/index.js')
script(type='text/javascript', src='/js/controllers/header.js')
script(type='text/javascript', src='/js/controllers/game.js')
script(type='text/javascript', src='/js/controllers/search.js')
script(type='text/javascript', src='/js/init.js')

//Socket.io Client Library
script(type='text/javascript', src='/socket.io/socket.io.js')
Expand Down
5 changes: 4 additions & 1 deletion config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ module.exports = (app, passport) => {
// Invitation
app.post('/api/invite', middleWare.isLoggedIn, users.invite);

// Search User
// User Profile
app.get('/api/profile/:id', users.profile);

// Search
app.post('/api/search', users.searchUser);
};
18 changes: 17 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1048,4 +1048,20 @@

.white-text a {
vertical-align: 350px;
}
}

.user-details img{
margin-top: 50px;
height: 200px;
width: 200px
}

.bg-grey {
background-color: rgba(245, 155, 91, 0.281);
/* background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='192' height='192' viewBox='0 0 192 192'%3E%3Cpath fill='%239C92AC' fill-opacity='0.4' d='M192 15v2a11 11 0 0 0-11 11c0 1.94 1.16 4.75 2.53 6.11l2.36 2.36a6.93 6.93 0 0 1 1.22 7.56l-.43.84a8.08 8.08 0 0 1-6.66 4.13H145v35.02a6.1 6.1 0 0 0 3.03 4.87l.84.43c1.58.79 4 .4 5.24-.85l2.36-2.36a12.04 12.04 0 0 1 7.51-3.11 13 13 0 1 1 .02 26 12 12 0 0 1-7.53-3.11l-2.36-2.36a4.93 4.93 0 0 0-5.24-.85l-.84.43a6.1 6.1 0 0 0-3.03 4.87V143h35.02a8.08 8.08 0 0 1 6.66 4.13l.43.84a6.91 6.91 0 0 1-1.22 7.56l-2.36 2.36A10.06 10.06 0 0 0 181 164a11 11 0 0 0 11 11v2a13 13 0 0 1-13-13 12 12 0 0 1 3.11-7.53l2.36-2.36a4.93 4.93 0 0 0 .85-5.24l-.43-.84a6.1 6.1 0 0 0-4.87-3.03H145v35.02a8.08 8.08 0 0 1-4.13 6.66l-.84.43a6.91 6.91 0 0 1-7.56-1.22l-2.36-2.36A10.06 10.06 0 0 0 124 181a11 11 0 0 0-11 11h-2a13 13 0 0 1 13-13c2.47 0 5.79 1.37 7.53 3.11l2.36 2.36a4.94 4.94 0 0 0 5.24.85l.84-.43a6.1 6.1 0 0 0 3.03-4.87V145h-35.02a8.08 8.08 0 0 1-6.66-4.13l-.43-.84a6.91 6.91 0 0 1 1.22-7.56l2.36-2.36A10.06 10.06 0 0 0 107 124a11 11 0 0 0-22 0c0 1.94 1.16 4.75 2.53 6.11l2.36 2.36a6.93 6.93 0 0 1 1.22 7.56l-.43.84a8.08 8.08 0 0 1-6.66 4.13H49v35.02a6.1 6.1 0 0 0 3.03 4.87l.84.43c1.58.79 4 .4 5.24-.85l2.36-2.36a12.04 12.04 0 0 1 7.51-3.11A13 13 0 0 1 81 192h-2a11 11 0 0 0-11-11c-1.94 0-4.75 1.16-6.11 2.53l-2.36 2.36a6.93 6.93 0 0 1-7.56 1.22l-.84-.43a8.08 8.08 0 0 1-4.13-6.66V145H11.98a6.1 6.1 0 0 0-4.87 3.03l-.43.84c-.79 1.58-.4 4 .85 5.24l2.36 2.36a12.04 12.04 0 0 1 3.11 7.51A13 13 0 0 1 0 177v-2a11 11 0 0 0 11-11c0-1.94-1.16-4.75-2.53-6.11l-2.36-2.36a6.93 6.93 0 0 1-1.22-7.56l.43-.84a8.08 8.08 0 0 1 6.66-4.13H47v-35.02a6.1 6.1 0 0 0-3.03-4.87l-.84-.43c-1.59-.8-4-.4-5.24.85l-2.36 2.36A12 12 0 0 1 28 109a13 13 0 1 1 0-26c2.47 0 5.79 1.37 7.53 3.11l2.36 2.36a4.94 4.94 0 0 0 5.24.85l.84-.43A6.1 6.1 0 0 0 47 84.02V49H11.98a8.08 8.08 0 0 1-6.66-4.13l-.43-.84a6.91 6.91 0 0 1 1.22-7.56l2.36-2.36A10.06 10.06 0 0 0 11 28 11 11 0 0 0 0 17v-2a13 13 0 0 1 13 13c0 2.47-1.37 5.79-3.11 7.53l-2.36 2.36a4.94 4.94 0 0 0-.85 5.24l.43.84A6.1 6.1 0 0 0 11.98 47H47V11.98a8.08 8.08 0 0 1 4.13-6.66l.84-.43a6.91 6.91 0 0 1 7.56 1.22l2.36 2.36A10.06 10.06 0 0 0 68 11 11 11 0 0 0 79 0h2a13 13 0 0 1-13 13 12 12 0 0 1-7.53-3.11l-2.36-2.36a4.93 4.93 0 0 0-5.24-.85l-.84.43A6.1 6.1 0 0 0 49 11.98V47h35.02a8.08 8.08 0 0 1 6.66 4.13l.43.84a6.91 6.91 0 0 1-1.22 7.56l-2.36 2.36A10.06 10.06 0 0 0 85 68a11 11 0 0 0 22 0c0-1.94-1.16-4.75-2.53-6.11l-2.36-2.36a6.93 6.93 0 0 1-1.22-7.56l.43-.84a8.08 8.08 0 0 1 6.66-4.13H143V11.98a6.1 6.1 0 0 0-3.03-4.87l-.84-.43c-1.59-.8-4-.4-5.24.85l-2.36 2.36A12 12 0 0 1 124 13a13 13 0 0 1-13-13h2a11 11 0 0 0 11 11c1.94 0 4.75-1.16 6.11-2.53l2.36-2.36a6.93 6.93 0 0 1 7.56-1.22l.84.43a8.08 8.08 0 0 1 4.13 6.66V47h35.02a6.1 6.1 0 0 0 4.87-3.03l.43-.84c.8-1.59.4-4-.85-5.24l-2.36-2.36A12 12 0 0 1 179 28a13 13 0 0 1 13-13zM84.02 143a6.1 6.1 0 0 0 4.87-3.03l.43-.84c.8-1.59.4-4-.85-5.24l-2.36-2.36A12 12 0 0 1 83 124a13 13 0 1 1 26 0c0 2.47-1.37 5.79-3.11 7.53l-2.36 2.36a4.94 4.94 0 0 0-.85 5.24l.43.84a6.1 6.1 0 0 0 4.87 3.03H143v-35.02a8.08 8.08 0 0 1 4.13-6.66l.84-.43a6.91 6.91 0 0 1 7.56 1.22l2.36 2.36A10.06 10.06 0 0 0 164 107a11 11 0 0 0 0-22c-1.94 0-4.75 1.16-6.11 2.53l-2.36 2.36a6.93 6.93 0 0 1-7.56 1.22l-.84-.43a8.08 8.08 0 0 1-4.13-6.66V49h-35.02a6.1 6.1 0 0 0-4.87 3.03l-.43.84c-.79 1.58-.4 4 .85 5.24l2.36 2.36a12.04 12.04 0 0 1 3.11 7.51A13 13 0 1 1 83 68a12 12 0 0 1 3.11-7.53l2.36-2.36a4.93 4.93 0 0 0 .85-5.24l-.43-.84A6.1 6.1 0 0 0 84.02 49H49v35.02a8.08 8.08 0 0 1-4.13 6.66l-.84.43a6.91 6.91 0 0 1-7.56-1.22l-2.36-2.36A10.06 10.06 0 0 0 28 85a11 11 0 0 0 0 22c1.94 0 4.75-1.16 6.11-2.53l2.36-2.36a6.93 6.93 0 0 1 7.56-1.22l.84.43a8.08 8.08 0 0 1 4.13 6.66V143h35.02z'%3E%3C/path%3E%3C/svg%3E"); */
}

.game-log {
margin-top: 5rem;
margin-bottom: 10rem;
}
Binary file added public/img/Blank-profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', '
when('/signin', {
templateUrl: '/views/signin.html'
}).
when('/profile', {
templateUrl: '/views/userProfile.html'
}).
when('/signup', {
templateUrl: '/views/signup.html'
}).
Expand Down
5 changes: 4 additions & 1 deletion public/js/controllers/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ angular.module('mean.system')
}
const gamePlayers = [];
$scope.game.players.forEach((player) => {
gamePlayers.push(player.username);
gamePlayers.push({
username: player.username,
points: player.points
});
})
if (game.state === 'game ended') {
const saveGame = {
Expand Down
16 changes: 16 additions & 0 deletions public/js/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ angular.module('mean.system').controller('IndexController', [
$scope.loginError = null;
$scope.dontShow = false;
$scope.avatars = [];
let userId = null;
if (window.user) {
userId = window.user._id;
}
$scope.user = {};

AvatarService.getAvatars()
.then((data) => {
$scope.avatars = data;
});

if (window.user) {
$window.onload = $http.get(`/api/profile/${userId}`)
.then((res) => {
$scope.user = res.data;
});
} else if ($location.path === '/profile') {
$location.path('/');
}
$scope.image = '';
$scope.image_preview = '';
$scope.readImage = () => {
Expand Down Expand Up @@ -106,4 +119,7 @@ angular.module('mean.system').controller('IndexController', [
$location.path('/#!');
});
};
$scope.openDropdown = () => {
$('.dropdown-toggle').dropdown();
};
}]);
21 changes: 20 additions & 1 deletion public/js/init.js
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
if (window.location.hash == "#_=_") window.location.hash = "#!";
/* eslint-disable */
if (window.location.hash == '#_=_') window.location.hash = '#!';

// Decode token to determine if user is logged in and token hasn't expired
const userToken = localStorage.getItem('token');
const checkAuthenticationStatus = (token) => {
const decoded = jwt_decode(token);
try {
const timeLeft = decoded.exp - (Date.now() / 1000);
if (timeLeft <= 0) {
// token has expired, user isn't logged in
return localStorage.setItem('token', '');
}
} catch (e) {
// error in decoding token, user isn't logged in
return localStorage.setItem('token', '');
}
window.user = decoded;
};
checkAuthenticationStatus(userToken);
5 changes: 5 additions & 0 deletions public/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<li class="nav-item" ng-hide="showOptions">
<a class="nav-link" ng-click="logout()">SIGN OUT</a>
</li>
<div class="profile-icon ml-5">
<li class="nav-item">
<a href="#!/profile"> <i id="user" class="nav-link fa fa-user"></i> </a>
</li>
</div>
</ul>
</div>
</nav>
Expand Down
102 changes: 102 additions & 0 deletions public/views/userProfile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<div ng-controller="IndexController">

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse center-link" id="navbarNavDropdown">
<ul class="navbar-nav cfh-navbar">
<li class="nav-item">
<a class="nav-link" target="_self" href="#!/#howToPlay">HOW TO PLAY
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_self" href="#!/#charitySect">CHARITY</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" target="_self" ng-click="openDropdown()" id="navbarDropdown" data-toggle="dropdown">PLAY GAME</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="/play">Play with strangers</a>
<a class="dropdown-item" href="/play?custom">Play with friends</a>
</div>
</li>

</ul>
<a class="navbar-brand" href="#!/">
<img src="../img/landing/logo.png" width="100px" alt="logo" />
</a>
<ul class="navbar-nav">
<div class="auth" ng-show="showOptions">
<li class="nav-item">
<a class="nav-link" href="#!/signup">SIGN UP</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#!/signin">SIGN IN</a>
</li>
</div>
<li class="nav-item">
<a class="nav-link" target="_self" href="#!/#charitySect">DASHBOARD</a>
</li>
<li class="nav-item" ng-hide="showOptions">
<a class="nav-link" ng-click="logout()">SIGN OUT</a>
</li>
<div class="profile-icon ml-5">
<li class="nav-item">
<a href="#!/profile"> <i id="user" class="nav-link fa fa-user"></i> </a>
</li>
</div>
</ul>
</div>
</nav>


<div class="jumbotron bg-grey">
<div class="text-center user-details">
<img ng-src = "{{ user.image ? user.image : 'img/profile.png' }}" alt="">
<p class="lead mt-3">Name: {{user.name}}</p>
<p class="lead">Email: {{user.email}} </p>
<p class="lead">Game won: {{user.gamesWon}} </p>
</div>
</div>

<div class="container text-center game-log">
<h2 class=" my-4 ">Game Log</h2>
<div>
<table class="table">
<thead class="t">
<tr>
<th scope="col">#</th>
<th scope="col">Games Played</th>
<th scope="col">Points</th>
<th scope="col">Result</th>
</tr>
</thead>
<tbody class="">
<tr ng-repeat="game in user.userGame">
<th scope="row">{{ $index + 1 }}</th>
<td>{{ game.gameId }}</td>
<td ng-repeat="log in game.log">{{ log.points }}</td>
<td>{{ game.gameWinner}}</td>
</tr>
</tbody>
</table>
</div>

</div>

<footer >
<div class="business-footer">
<div class="text-center">
<p class="footer">
Legal stuff: This game is based on the Cards Against Humanity card game, which is CC licensed (BY-NC-SA).
<br/> Cards for Humanity is not affiliated with Cards Against Humanity. In complying with the Creative Commons license
of the Cards Against Humanity card game,
<br /> all proceeds from donations go directly to charity, as managed by crowdrise.
</p>
<span class="asgard"> created By: Team Asgard</span>
</div>
</div>
</footer>
</div>
18 changes: 18 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,23 @@ console.log(`Express app started on port ${port}`);
// Initializing logger
logger.init(app, passport, mongoose);

// const Game = mongoose.model('Game');

// Game.find().exec((err, games) => {
// if (err) {
// return res.status(400).json({
// message: 'Error Occured'
// })
// }
// const userGameLog = games.map(game => ({
// gameId: game.gameId,
// playedAt: game.played,
// userGame: game.players
// .filter(player => player.username === 'Rotimi')
// }));
// const userGame = userGameLog.filter(y => y.userGame.length !== 0);
// });


// expose app
export default app;
8 changes: 7 additions & 1 deletion test/endpoints/game.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const gameData = {
const gameData2 = {
gameId: 'E5TGR46',
players: [
'Ajiboye Daramola',
'Clinton Fidelis',
'Rotimi Isaiah',
'Fortune Ekeruo',
'Douglas',
'Olatunji',
'Ajiboye Daramola',
'Clinton Fidelis',
'Rotimi Isaiah',
Expand Down Expand Up @@ -76,7 +82,7 @@ describe('Game', () => {
});
});

it('Should create and save game if it has 6 players', (done) => {
it('Should create and save game if it has 12 players', (done) => {
request.post('/api/game/save')
.send(gameData2)
.expect(200)
Expand Down

0 comments on commit 3937521

Please sign in to comment.