<commit_before>/**
 * GET /
 * Challenges.
 */
var _ = require('lodash'),
    debug = require('debug')('freecc:cntr:challenges'),
    Challenge = require('./../models/Challenge'),
    resources = require('./resources');

var highestChallengeNumber = 53;


exports.returnNextChallenge = function(req, res) {
    if (req.user) {
        ch = req.user.challengesHash;
        if (req.user.challengesHash[0] > 0) {
            var max = Object.keys(ch).reduce(function(max, key) {
                return (max === undefined || ch[key] > ch[max]) ? +key : max;
            });
            nextChallenge = max + 1;
            res.redirect('challenges/' + nextChallenge);
        } else {
            res.redirect('challenges/0');
        }
    } else {
        res.render('home', {
            title: 'Learn to Code and Become a Software Engineer',
        });
    }
};

exports.returnChallenge = function(req, res) {
    var challengeNumber = parseInt(req.params.challengeNumber) || 0;
    if (challengeNumber === 2) {
        return res.redirect('../challenges/3');
    }
    if (challengeNumber > highestChallengeNumber) {
        req.flash('errors', {
            msg: "It looks like you've either completed all the challenges we have available or requested a challenge we don't have."
        });
        return res.redirect('../challenges/0');
    }
    Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
        if (err) {
            debug('Challenge err: ', err);
            next(err);
        }
        res.render('challenges/show', {
            title: 'Challenge: ' + c[challengeNumber].name,
            name: c[challengeNumber].name,
            video: c[challengeNumber].video,
            time: c[challengeNumber].time,
            steps: c[challengeNumber].steps,
            number: challengeNumber,
            cc: req.user ? req.user.challengesHash : undefined,
            points: req.user ? req.user.points : undefined,
            verb: resources.randomVerb(),<commit_msg>fix an issue of unathenticated users not being able to access challenges<commit_after>/**
 * GET /
 * Challenges.
 */
var _ = require('lodash'),
    debug = require('debug')('freecc:cntr:challenges'),
    Challenge = require('./../models/Challenge'),
    resources = require('./resources');

var highestChallengeNumber = 53;


exports.returnNextChallenge = function(req, res) {
    if (req.user) {
        ch = req.user.challengesHash;
        if (req.user.challengesHash[0] > 0) {
            var max = Object.keys(ch).reduce(function(max, key) {
                return (max === undefined || ch[key] > ch[max]) ? +key : max;
            });
            nextChallenge = max + 1;
            res.redirect('challenges/' + nextChallenge);
        } else {
            res.redirect('challenges/0');
        }
    } else {
        return res.redirect('../challenges/0');
    }
};

exports.returnChallenge = function(req, res) {
    var challengeNumber = parseInt(req.params.challengeNumber) || 0;
    if (challengeNumber === 2) {
        return res.redirect('../challenges/3');
    }
    if (challengeNumber > highestChallengeNumber) {
        req.flash('errors', {
            msg: "It looks like you've either completed all the challenges we have available or requested a challenge we don't have."
        });
        return res.redirect('../challenges/0');
    }
    Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
        if (err) {
            debug('Challenge err: ', err);
            next(err);
        }
        res.render('challenges/show', {
            title: 'Challenge: ' + c[challengeNumber].name,
            name: c[challengeNumber].name,
            video: c[challengeNumber].video,
            time: c[challengeNumber].time,
            steps: c[challengeNumber].steps,
            number: challengeNumber,
            cc: req.user ? req.user.challengesHash : undefined,
            points: req.user ? req.user.points : undefined,
            verb: resources.randomVerb(),
{'fraction_non_alphanumeric': 0.14356558393255642, 'fraction_numerical': 0.005702950657079098, 'mean_word_length': 2.206677265500795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253793', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1132, 'n_words': 258}