<commit_before>/*jshint unused:false*/
var util = require('util');

var config = require('../../config.json');
var talks = require('libtlks').talk;
var users = require('libtlks').user;

/**
 * Route /profile
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profile = function(req, res, next) {
    'use strict';

    var quantity = 25;
    var page = parseInt(req.params.page || 1);
    var pagination = {
        next: page + 1,
        prev: (page - 1 <= 1) ? 1 : page - 1
    };
    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s profile',
        user: user,
        page: page,
        pagination: pagination
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getByAuthorId(
                config.mongodb,
                profile.id,
                quantity,
                page,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    if (talks.length === 0) {
                        res.status(204).end();
                        return;
                    }
                    context.posted = talks;
                    res.render('profile.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profileUpvoted = function(req, res, next) {
    'use strict';

    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s upvoted talks',
        user: user
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getUpvotedByAuthorId(
                config.mongodb,
                profile.id,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    context.upvoted = talks;
                    res.render('profile.upvoted.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profileFavorited = function(req, res, next) {
    'use strict';

    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s upvoted talks',
        user: user
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getFavoritedByAuthorId(
                config.mongodb,
                profile.id,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    context.favorited = talks;
                    res.render('profile.favorited.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};


/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.settings = function(req, res, next) {
    'use strict';

    var user = req.session.user;
    if (user === undefined) {
        var err = {
            status: 401,
            message: 'Unauthorized'
        };
        return next(err);
    } else {
        var context = {
            title: 'tlks.io : ' + user.username + '\'s settings',
            user: user
        };
        res.render('settings', context);
    }
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.settingsSave = function(req, res, next) {
    'use strict';

    var user = req.session.user;
    user.bio = req.body.bio;
    user.email = req.body.email;
    user.url = req.body.url;
    users.update(config.mongodb, user, function(err) {
        if (err) {
            return next(err);
        }
        res.redirect('/');
    });
};
<commit_msg>Fixed  profiles that doesn't have any talk published<commit_after>/*jshint unused:false*/
var util = require('util');

var config = require('../../config.json');
var talks = require('libtlks').talk;
var users = require('libtlks').user;

/**
 * Route /profile
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profile = function(req, res, next) {
    'use strict';

    var quantity = 25;
    var page = parseInt(req.params.page || 1);
    var pagination = {
        next: page + 1,
        prev: (page - 1 <= 1) ? 1 : page - 1
    };
    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s profile',
        user: user,
        page: page,
        pagination: pagination
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getByAuthorId(
                config.mongodb,
                profile.id,
                quantity,
                page,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    if ((talks.length === 0) && (page>1)) {
                        res.status(204).end();
                        return;
                    }
                    context.posted = talks;
                    res.render('profile.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profileUpvoted = function(req, res, next) {
    'use strict';

    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s upvoted talks',
        user: user
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getUpvotedByAuthorId(
                config.mongodb,
                profile.id,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    context.upvoted = talks;
                    res.render('profile.upvoted.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.profileFavorited = function(req, res, next) {
    'use strict';

    var username = req.params.username;
    var user = req.session.user;
    var context = {
        title: 'tlks.io : ' + username + '\'s upvoted talks',
        user: user
    };
    users.getByUsername(config.mongodb, username, function(err, profile) {
        if (err) {
            return next(err);
        }
        if (profile) {
            context.profile = profile;
            talks.getFavoritedByAuthorId(
                config.mongodb,
                profile.id,
                function(err, talks) {
                    if (err) {
                        return next(err);
                    }
                    context.favorited = talks;
                    res.render('profile.favorited.jade', context);
                });
        } else {
            res.status(404).render('404', context);
        }
    });
};


/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.settings = function(req, res, next) {
    'use strict';

    var user = req.session.user;
    if (user === undefined) {
        var err = {
            status: 401,
            message: 'Unauthorized'
        };
        return next(err);
    } else {
        var context = {
            title: 'tlks.io : ' + user.username + '\'s settings',
            user: user
        };
        res.render('settings', context);
    }
};

/**
 * Route /settings
 * @param req   HTTP Request object
 * @param res   HTTP Response object
 */
exports.settingsSave = function(req, res, next) {
    'use strict';

    var user = req.session.user;
    user.bio = req.body.bio;
    user.email = req.body.email;
    user.url = req.body.url;
    users.update(config.mongodb, user, function(err) {
        if (err) {
            return next(err);
        }
        res.redirect('/');
    });
};

{'fraction_non_alphanumeric': 0.1271839392295171, 'fraction_numerical': 0.00727075420510038, 'mean_word_length': 1.4543275632490014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '4288915', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2550, 'n_words': 624}