Skip to content

Commit

Permalink
Rectifications To The Admin Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham committed Jun 19, 2020
1 parent 422f75d commit 147367a
Show file tree
Hide file tree
Showing 24 changed files with 413 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=shubham@2506
File renamed without changes.
6 changes: 3 additions & 3 deletions config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var mysql = require('mysql');

var pool = mysql.createPool({multipleStatements: true,
connectionLimit : 100,
host: 'localhost',
user: 'root',
password: 'shubham@2506',
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: 'game',
charset: 'UTF8MB4_GENERAL_CI'
});
Expand Down
2 changes: 1 addition & 1 deletion flappy/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ const gameOver = {
ctx.drawImage(sprite, this.sX, this.sY, this.w, this.h, this.x, this.y, this.w, this.h);
}
}

}

// PIPES
Expand Down Expand Up @@ -362,3 +361,4 @@ function loop(){
requestAnimationFrame(loop);
}
loop();

12 changes: 11 additions & 1 deletion flower/flower.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var score = 0;
localStorage.setItem('flower_score',score);

function Flower(x, y) {
this.x = x;
this.y = y;
Expand All @@ -6,7 +9,14 @@ function Flower(x, y) {
this.xdir = 1;

this.grow = function() {
this.r = this.r + 2;
if(this.r > 0){
this.r = this.r - 2;
}
if(this.r == 0){
score++;
localStorage.setItem('flower_score',score);
this.r = -0.000000000001;
}
};

this.shiftDown = function() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"async": "^3.2.0",
"body-parser": "^1.19.0",
"connect-flash": "^0.1.1",
"dotenv": "^8.2.0",
"ejs": "^2.6.1",
"express": "^4.16.4",
"express-session": "^1.16.1",
Expand Down
Binary file added public/img/anand.jpeg
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/rishabh.jpeg
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/shubham.JPG
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/somnath.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 37 additions & 32 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,55 @@ router.get('/notification',function(req,res){
})
router.post('/notification',function(req,res,next){
console.log(req.body)
async.waterfall([
function(done) {
var sql="SELECT * FROM login WHERE id='"+req.body.id+"'";
pool.query(sql,function(err, user) {
if (!user.length) {
req.flash('error', 'No account with that email address exists.');
return res.redirect('/admin/notification');
}

var sql1="INSERT into notification(`game_id`,`notification`,`user_id`,`warning`) VALUES ('"+req.body.game_id+"','"+req.body.notification+"','"+req.body.id+"','"+req.body.warning+"')";
var warning;
if(!req.body.warning){
warning=0;
}
else{
warning=1;
}
var sql1="INSERT into notification(`game_id`,`notification`,`user_id`,`warning`) VALUES ('"+req.body.game_id+"','"+req.body.notification+"','"+req.body.id+"','"+warning+"')";
pool.query(sql1,function(err,result){
if(err)throw err;
done(err, user);
});
});
},
function(user, done) {
console.log(user[0].email)
var smtpTransport = nodemailer.createTransport({
service: 'Gmail',
port: 587,
secure: false,
auth: {
user: '',
pass: '',
}
});
var mailOptions = {
from: '"Gaming Website"',
to: '[email protected]',
subject: 'Online Gaming Website',
text: 'You are receiving this because you (or someone else) has been sent a notification by the admin of the gaming Website +\n\n+'+req.body.notification+'\n\n' +
'If you did not request this, please ignore this email.\n'
};
let info = smtpTransport.sendMail(mailOptions, function(err) {
console.log('mail sent');
req.flash('success', 'An e-mail has been sent your mail with further instructions.');
done(err, 'done');
});
}
], function(err) {
if (err) return next(err);
res.redirect('/admin/notification');
});

router.get('/report_bugs',function(req,res){
var sql="SELECT a.sr_no,a.uid,a.bug,a.time,b.name FROM report_bugs AS a INNER JOIN login AS b ON a.uid=b.id";
console.log(sql)
pool.query(sql,function(err,result){
if(err)throw err;
console.log(result)
result.forEach(res => {
res.time = moment(res.time).format("MMMM Do YYYY, h:mm:ss a");
});
res.render('admin_reported_bugs.ejs',{
bugs:result
});
});
});

router.get('/report_feedback',function(req,res){
var sql="SELECT a.id,a.uid,a.feedback,a.time,b.name,b.username FROM feedback AS a INNER JOIN login AS b ON a.uid=b.id";
console.log(sql)
pool.query(sql,function(err,result){
if(err)throw err;
console.log(result)
result.forEach(res => {
res.time = moment(res.time).format("MMMM Do YYYY, h:mm:ss a");
});
res.render('admin_feedback.ejs',{
feedback:result
});
});
});


Expand Down
9 changes: 9 additions & 0 deletions routes/flappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ router.get('/', function(req,res){
res.render('flappy.ejs');
});

router.post('/score',function(req,res){
console.log(req.body)
var time=moment().format("HH:mm:ss");
var sql2="INSERT INTO game_2(`user_id`,`high_score`,`last_vis`) VALUES('"+req.user.id+"','"+req.body.score+"','"+time+"')";
pool.query(sql2,function(err,result2){
if(err)throw err;
console.log(result2);
});
});
module.exports = router;
10 changes: 10 additions & 0 deletions routes/flower.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ router.get('/', function(req,res){
res.render('flower.ejs');
});

router.post('/score',function(req,res){
console.log(req.body)
var time=moment().format("HH:mm:ss");
var sql2="INSERT INTO game_1(`user_id`,`high_score`,`last_vis`) VALUES('"+req.user.id+"','"+req.body.score+"','"+time+"')";
pool.query(sql2,function(err,result2){
if(err)throw err;
console.log(result2);
});
});

module.exports = router;
20 changes: 20 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ router.get('/', function(req,res){
}
});

router.post('/feedback',function(req,res){
console.log("here")
var time=moment().format("YYYY-MM-DD HH:mm:ss");
var sql="INSERT INTO `feedback`(`uid`, `feedback`, `subject`,`time`) VALUES ('"+req.user.id+"','"+req.body.feedback+"','"+req.body.subject+"','"+time+"')";
pool.query(sql,function(err,result){
if(err)throw err;
console.log(result);
});
});

router.post('/report',function(req,res){
console.log("here")
var time=moment().format("YYYY-MM-DD HH:mm:ss");
var sql="INSERT INTO `report_bugs`(`uid`, `bug`, `time`) VALUES ('"+req.user.id+"','"+req.body.bug+"','"+time+"')";
pool.query(sql,function(err,result){
if(err)throw err;
console.log(result);
});
});



module.exports = router;
25 changes: 4 additions & 21 deletions routes/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,10 @@ router.get('/', function(req,res){
router.post('/score',function(req,res){
console.log(req.body)
var time=moment().format("HH:mm:ss");
var sql="SELECT * FROM game_3 WHERE user_id='"+req.user.id+"'";
var sql2;
pool.query(sql,function(err,result){
if(err)throw err;
console.log(result)
if(result.length){
if(result[0].high_score < req.body.score){
sql2="UPDATE `game_3` SET `high_score`='"+req.body.score+"' WHERE id='"+req.user.id+"'";
pool.query(sql2,function(err,result2){
if(err)throw err;
console.log(result2);
});
}
}
else{
sql2="INSERT INTO game_3(`user_id`,`high_score`,`last_vis`) VALUES('"+req.user.id+"','"+req.body.score+"','"+time+"')";
pool.query(sql2,function(err,result2){
if(err)throw err;
console.log(result2);
});
}
var sql2="INSERT INTO game_3(`user_id`,`high_score`,`last_vis`) VALUES('"+req.user.id+"','"+req.body.score+"','"+time+"')";
pool.query(sql2,function(err,result2){
if(err)throw err;
console.log(result2);
});
});

Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const passport = require('passport');
const session = require('express-session');
var flash = require('connect-flash');

//Require dotenv For Variables
require('dotenv').config();

// Routes Being Set Here
const login = require('./routes/login');
Expand Down
2 changes: 1 addition & 1 deletion space_invader/js/spaceinvaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ GameOverState.prototype.draw = function(game, dt, ctx) {
ctx.font="16px Arial";
ctx.fillText("You scored " + game.score + " and got to level " + game.level, game.width / 2, game.height/2);
ctx.font="16px Arial";
ctx.fillText("Press 'Space' to play again.", game.width / 2, game.height/2 + 40);
ctx.fillText("Press 'Space' to play again.Press Esc to save score", game.width / 2, game.height/2 + 40);
//Storing The Values in Local Storage//
localStorage.setItem('space_invader_score', game.score)
localStorage.setItem('space_invader_level', game.level)
Expand Down
2 changes: 1 addition & 1 deletion views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="description" content="">
<meta name="author" content="">

<title>Trouvaille - Dashboard</title>
<title>Admin - Dashboard</title>

<%- include('./partials/head') %>

Expand Down
116 changes: 116 additions & 0 deletions views/admin_feedback.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">

<title>Online Gaming Website - Admin</title>

<%- include('./partials/head') %>

<link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

<body id="page-top" class="sidebar-toggled">

<!-- Page Wrapper -->
<div id="wrapper">

<%- include('./partials/sidebar') %>

<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">

<!-- Main Content -->
<div id="content">

<%- include('./partials/header') %>

<!-- Begin Page Content -->
<div class="container-fluid">

<h1 class="h3 mb-2 text-gray-800">Users</h1>

<div class="card shadow">
<div class="card-header">
<h6 class="m-0 font-weight-bold text-primary">User Details</h6>
</div>

<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="user_table" width="100%" cellspacing="0">
<thead>
<tr>
<th>User Id</th>
<th>User Name</th>
<th>User Handle</th>
<th>Feedback</th>
<th>Time</th>
</tr>
</thead>
<tfoot>
<tr>
<th>User Id</th>
<th>User Name</th>
<th>User Handle</th>
<th>Feedback</th>
<th>Time</th>
</tr>
</tfoot>
<tbody>
<%
if(feedback.length) {
for(var i = 0;i < feedback.length;i++) { %>
<tr>
<td><%=feedback[i].id%></td>
<td><%=feedback[i].name%></td>
<td><%=feedback[i].username%></td>
<td><%=feedback[i].feedback%></td>
<td><%=feedback[i].time%></td>
</tr>
<% }
} %>
</tbody>
</table>
</div>
</div>
</div>

</div>
</div>
<!-- End of Main Content -->

<%- include('./partials/footer') %>

</div>
<!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>

<%- include('./partials/foot') %>

<!--Page Level Plugins -->
<script src="vendor/datatables/jquery.dataTables.min.js"></script>
<script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>

<script>
$(document).ready(function() {
$("#user_table").DataTable();
});
</script>

</body>

</html>
2 changes: 1 addition & 1 deletion views/admin_notification.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</div>

<div class="form-group col-md-12">
<label for="select2-multiple-input-sm" class="control-label"><h5>User</h5></label>
<label for="select2-multiple-input-sm" class="control-label"><h5>Game</h5></label>
<select id="user_id" name="game_id" class="form-control input-sm select2-multiple">
<!-- <option></option> -->
<%
Expand Down
Loading

0 comments on commit 147367a

Please sign in to comment.