<file_sep>const router = require('express').Router();
const passport = require('passport');
const Score = require('../models/score-model');
const User = require('../models/user-model');
const bodyParser = require('body-parser');
const jsonParser = bodyParser.json();


router.get('/gameplay', (req, res) => {
  res.render('gameplay', {
    user: req.user,
  });
});

router.post("/score", jsonParser, function (req, res) {
  // Take the request...
  var newScore = req.body;
  newScore.googleId = req.user.googleId;
  newScore.thumbnail = req.user.thumbnail;
  newScore.postedBy = req.user.username;

  // console.log("I am line 24 game-routes\n", req.user);
  var latest = new Score({
    googleId: newScore.googleId,
    thumbnail: newScore.thumbnail,
    postedBy: newScore.postedBy,
    difficulty: newScore.difficulty,
    score: newScore.score
  });

  Score.create(latest)
    .then(score => {
      console.log("Created a score record!");
      res.status(201).json(score);
    })
    .catch(err => {
      res.status(400).json(err);
    });

});

module.exports = router;<file_sep># Whack-A-Bug #

### About Whack-A-Bug: ###

Whack-A-Bug is a full-stack game built for developers to release the inevitable stress that comes with being a developer. The goal of the game is to smash all of the "bugs" in the game box as quickly as possible.

This app is deployed to Heroku at: https://whackabug.herokuapp.com/

---------------------------------

### How to use Whack-A-Bug: ###

Log in using your Google account for authentication (or create a Google account if you do not have one).

You will be taken to your profile page, where you can view your Personal Bests as well as the Global Leaderboard.

Click "Play New Game" and be taken to the gameplay page.

Select your difficulty level (Easy, Medium, Hard, or Plague). The difficulty level corresponds to the number of "moles" that you will need to smash in the game.

When the game begins, click on the "bugs" (red circles) as quickly as you can. Be careful! You'll be penalized if you click on a non-bug (green circle).

Try to improve your score and compete with other users of the platform!

---------------------------------

### Built with: ###

#### Front-end ####

Bulma.io: https://bulma.io/

jQuery: https://jquery.com/


#### Back-end ####

Express: https://expressjs.com/

Node.js: https://nodejs.org/en/

Passport.js: http://www.passportjs.org/

MongoDB: https://www.mongodb.com/

Mongoose NPM: https://www.npmjs.com/package/mongoose


---------------------------------

### Contributers: ###

<NAME>: https://github.com/albertcoder

<NAME>: https://github.com/EthanPFisher

<NAME>: https://github.com/rsharar<file_sep>const router = require('express').Router();
const Score = require('../models/score-model');
const User = require('../models/user-model');

const authCheck = (req, res, next) => {
    if (!req.user) {
        res.redirect('/auth/login');
    } else {
        next();
    }
};

router.get('/', authCheck, (req, res) => {
    // console.log("This is the user: "+req.user.googleId);
    var googleIdee = req.user.googleId;

    var fetchAllScores = function () {
        return Score.find({}, function (err, usersReturned) {
            if (err) return handleError(err);
        }).sort({
            score: 1
        }).limit(3).then(function (data) {
            // console.log(data);
            return data;
        });
    };
    var fetchLoggedInUserScores = function () {
        return Score.find({
            googleId: googleIdee
        }, function (err, usersReturned) {
            if (err) return handleError(err);
        }).sort({
            score: 1
        }).limit(3).then(function (data) {
            return data;
        });
    };

    // fetchAllScores();
    Promise.all([fetchAllScores(), fetchLoggedInUserScores()]).then(function (data) {
        console.log("I am fetchLogged \n", data[0].length);
        if (data[0].length >= 3) {
            res.render('profile', {
                user: req.user,
                userData: data
            });
        }
        else {
            res.send("Please play at least 3 times to see your leaderboard.");
        }

    });
});

module.exports = router;<file_sep>module.exports = {
    google: {
        clientID: '744866401172-kp4aq9mevkpvfmo8kg3ce4iicken9l5c.apps.googleusercontent.com',
        clientSecret: '<KEY>'
    },
    mongodb: {
        dbURI: 'mongodb://test:<EMAIL>:57268/whackabug'
    },
    session: {
        cookieKey: 'thenetninjaisawesomeiguess'
    }
};