Skip to content

Commit

Permalink
Merge 866e9a8 into 2de50ba
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlayhemmy committed May 24, 2018
2 parents 2de50ba + 866e9a8 commit 683c397
Show file tree
Hide file tree
Showing 23 changed files with 548 additions and 117 deletions.
62 changes: 62 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,67 @@ exports.game = function (req, res) {
});
};


exports.updateUser = (req, res) => {
const { preset } = req.body;
User.findOne({
_id: req.user.user._id,
}).then((foundUser) => {
if (foundUser) {
foundUser.presetId = preset;
foundUser.save();
const token = jwt.sign({ user: foundUser }, process.env.SECRET, {
expiresIn: 86400
});
let gameCard;
if (preset === 1) {
gameCard = 'Archaic';
} else if (preset === 2) {
gameCard = 'Aladdin';
} else if (preset === 3) {
gameCard = 'Classic';
} else if (preset === 4) {
gameCard = 'Modern';
} else if (preset === 5) {
gameCard = 'Beauty';
}
return res.status(200).send({
message: `Your game card has been successfully changed to ${gameCard}`,
foundUser,
token
});
}
}).catch(error => res.status(400).json({
message: 'An error occoured',
error
}));
};

const calculate = (user) => {
let sum = 0;
const amountDonated = user[0].donations.map((acc) => {
const dollar = acc.amount;
const money = dollar.replace('$', '');
sum += Number(money);
return sum;
});
return sum;
};

exports.checkUserDonation = (req, res) => {
User.find({
_id: req.user.user._id,
}).then((user) => {
const amountInvested = calculate(user);
return res.status(200).send({
amountInvested,
message: 'Ok'
});
}).catch(err => res.status(500).send({
message: 'Sorry, Donations not found at this time',
}));
};

exports.getDonations = function (req, res) {
const { page, limit, offset } = Helper.setupPagination(req);
User.$where('this.donations.length > 0').count()
Expand Down Expand Up @@ -423,4 +484,5 @@ exports.getDonations = function (req, res) {
error
});
});

};
3 changes: 2 additions & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const UserSchema = new Schema({
hashed_password: String,
facebook: {},
twitter: {},
google: {}
google: {},
presetId: String,
});

/**
Expand Down
64 changes: 39 additions & 25 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ module.exports = function (passport) {
name: profile.displayName,
username: profile.username,
provider: 'twitter',
twitter: profile._json, // eslint-disable-line
imageUrl: profile._json.profile_image_url, // eslint-disable-line
email: profile._json.email || profile.username,
});
Expand All @@ -98,32 +97,48 @@ module.exports = function (passport) {
{
clientID: process.env.FB_CLIENT_ID,
clientSecret: process.env.FB_CLIENT_SECRET,
callbackURL: process.env.FB_CALLBACK
callbackURL: process.env.FB_CALLBACK,
profileFields: [
'id',
'birthday',
'email',
'first_name',
'last_name',
'gender',
'picture.width(200).height(200)'
]
},
((accessToken, refreshToken, profile, done) => {
User.findOne({
'facebook.id': profile.id
}, (err, user) => {
if (err) {
return done(err);
}
if (!user) {
user = new User({
email: (profile.emails && profile.emails[0].value) || '',
username: profile.username,
provider: 'facebook',
facebook: profile._json, // eslint-disable-line
imageUrl: profile._json.picture || '' // eslint-disable-line
});
user.save((err) => {
if (err) console.log(err);
(accessToken, refreshToken, profile, done) => {
User.findOne(
{
'facebook.id': profile.id
},
(err, user) => {
if (err) {
return done(err);
}
if (!user) {
user = new User({
email: (profile.emails && profile.emails[0].value) || '',
username: profile.username,
provider: 'facebook',
imageUrl:
profile.photos[0].value ||
profile._json.picture ||
profile._json.avatar ||
profile.json.picture.data.url ||
profile.json.avatar.data.url
});
user.save((err) => {
if (err) console.log(err);
return done(err, user);
});
} else {
return done(err, user);
});
} else {
return done(err, user);
}
}
});
})
);
}
));

// Use google strategy
Expand All @@ -146,7 +161,6 @@ module.exports = function (passport) {
email: profile._json.email,
username: profile._json.given_name,
provider: 'google',
google: profile._json, // eslint-disable-line
imageUrl: profile._json.picture // eslint-disable-line
});
user.save((err) => {
Expand Down
6 changes: 6 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ module.exports = function (app, passport) {
validator.gameValidation,
game.saveGame,
);


app.put('/api/designPicked', auth.verifyToken, users.updateUser);
app.get('/api/checkDonations', auth.verifyToken, users.checkUserDonation);

// Game history API endpoint
app.get('/api/games/history', auth.verifyToken, game.gameHistory);

Expand All @@ -112,4 +117,5 @@ module.exports = function (app, passport) {

// Leaderboard API endpoint
app.get('/api/leaderboard', auth.verifyToken, game.gameLeaderboard);

};
37 changes: 24 additions & 13 deletions config/socket/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ module.exports = function (io) {
}
});

// store online users
socket.on('connectedUser', (data) => {
// store online users
socket.on('connectedUser', data => {
if (onlineUsers.find(user => user.username === data)) {
const index = onlineUsers.findIndex(value => value.username === data);
if (index < 0) {
onlineUsers.splice(0,1);
onlineUsers.splice(0, 1);
}
onlineUsers.splice(index, 1);
}
Expand All @@ -69,31 +69,42 @@ module.exports = function (io) {
username: data
};
onlineUsers.push(user);
io.sockets.emit('people', onlineUsers)

io.sockets.emit('people', onlineUsers);
console.log('connect', onlineUsers);
});

socket.on('showOnlineUsers', () => {
io.sockets.emit('people', onlineUsers)
io.sockets.emit('people', onlineUsers);
});

socket.on('removeUser', (data) => {
socket.on('removeUser', data => {
const index = onlineUsers.findIndex(value => value.username === data);
if (index < 0) {
onlineUsers.splice(0,1);
onlineUsers.splice(0, 1);
}
onlineUsers.splice(index, 1);
io.sockets.emit('people', onlineUsers)
})
io.sockets.emit('people', onlineUsers);
});

// send invite to player
socket.on('invitePlayer', (data) => {
socket.on('invitePlayer', data => {
if (onlineUsers.find(user => user.username === data.user)) {
const socketId = onlineUsers.find(user => user.username === data.user).userId;
io.sockets.connected[socketId].emit('invitation', {html:`You have been Invited to play a game.<br/> Click on this <a href=${data.gameLink} target="_blank">link to join</a>`});
const socketId = onlineUsers.find(user => user.username === data.user)
.userId;
if (socketId !== undefined) {
io
.to(socketId)
.emit('invitation', {
html: `You have been Invited to play a game.<br/> Click on this <span class="invite-link"><a style="color: red;" href=${
data.gameLink
} target="_blank">link to join</a></span>`
});
console.log(data)
}
}
});


socket.on('joinGame', (data) => {
if (!allPlayers[socket.id]) {
joinGame(socket, data);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"istanbul-coveralls": "^1.0.3",
"jade": "~0.35.0",
"jsonwebtoken": "^8.2.1",
"materialize": "^1.0.0",
"mean-logger": "~0.0.1",
"mongoose": "^5.0.15",
"nock": "^9.2.5",
Expand Down
46 changes: 44 additions & 2 deletions public/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
position: relative;
display: inline-block;
box-sizing: border-box;
width: 17.5%;
height: 215px;
width: 22%;
height: 213px;
padding: 1%;
margin: 1%;
background-color: #fff;
Expand All @@ -13,7 +13,9 @@
font-size: 20px;
font-weight: bold;
vertical-align: top;
font-family: 'Kalam', cursive;
}

@media (max-width: 520px) {
.card {
font-size: 14px;
Expand Down Expand Up @@ -47,6 +49,46 @@
.card.smallest {
font-size: 0.75em;
}

.preset-1 {
font-size: 1.2rem;
color: #ffffff;
background-image: url('../img/preset-1.jpg');
background-size: cover;
width: 22%;
}

.preset-2 {
font-size: 1.2rem;
color: black;
background-image: url('../img/preset-2.jpg');
background-size: cover;
}

.preset-3 {
font-size: 1.2rem;
color: red;
background-image: url('../img/preset-3.png');
background-size: cover;
}

.preset-4 {
font-size: 1.2rem;
background-image: url('../img/preset-4.jpeg');
background-size: cover;
color: #000000;
}

.preset-5 {
font-size: 1.2rem;
color: purple;
background-image: url('../img/preset-5.gif');
background-size: cover;
background-position: center;
background-repeat: no-repeat;

}

@media (max-width: 520px) {
.card.smallest {
font-size: 10px;
Expand Down
3 changes: 3 additions & 0 deletions public/css/game-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ body, html {
width: 80% !important;
margin-left: 10%;
height: inherit;
display: flex;
justify-content: center;
align-items: center;
}

.player-online {
Expand Down
3 changes: 1 addition & 2 deletions public/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ body {
color: gray;
}
.redfont {
background: #fff;
color: #fff;
border-radius: 50%;
color: red;
}
* {
box-sizing: border-box;
Expand Down
Loading

0 comments on commit 683c397

Please sign in to comment.