<commit_before>﻿var express = require('express');
var router = express.Router();
var passport = require('passport');
var jwt = require('jsonwebtoken');

var User = require('../models/users.js');

/* GET users listing. */
router.get('/', function (req, res) {
    res.send('respond with a resource');
});

router.get('/register', function (req, res)
{
    res.render('partial/register', { title: 'Join Us' });
});
router.post('/register', function (req, res)
{
    User.findOne({ 'local.email': req.body.email }, function (err, user)
    {
        if (err) return res.status(500).send(err);
        if (user) return res.status(500).send('The email already taken');
        else
        {
            var aUser = new User();
            
            aUser.local.name = req.body.name;
            aUser.local.email = req.body.email;
            aUser.local.username = req.body.username;
            aUser.local.password = <PASSWORD>(req.body.password);

            aUser.save(function (err)
            {
                if (err) throw err;
                return done(null, aUser);
            });
        }
              
    });
});

router.get('/login', function (req, res)
{
    res.render('partial/login', { title: 'Login' });
});

router.post('/login', function (req, res)
{
    passport.authenticate('jwt', { session: false }),
    function (req, res)
    {
        res.send(req.user.profile);
    }
});


module.exports = router;<commit_msg>check username already taken like email<commit_after>﻿var express = require('express');
var router = express.Router();
var passport = require('passport');
var jwt = require('jsonwebtoken');

var User = require('../models/users.js');

/* GET users listing. */
router.get('/', function (req, res) {
    res.send('respond with a resource');
});

router.get('/register', function (req, res)
{
    res.render('partial/register', { title: 'Join Us' });
});
router.post('/register', function (req, res)
{
    User.findOne( {$or: [
            { 'local.email': req.body.email },
            {'local.username': req.body.username}
        ]}, function (err, user)
    {
        if (err) return res.status(500).send(err);
        if (user) return res.status(500).send('The email or username already taken');
        else
        {
            

            var aUser = new User();
            
            aUser.local.name = req.body.name;
            aUser.local.email = req.body.email;
            aUser.local.username = req.body.username;
            aUser.local.password = <PASSWORD>(<PASSWORD>);

            aUser.save(function (err)
            {
                if (err) throw err;
                return res.status(200).send('registered');
            });
        }
              
    });
});

router.get('/login', function (req, res)
{
    res.render('partial/login', { title: 'Login' });
});

router.post('/login', function (req, res)
{
    passport.authenticate('jwt', { session: false }),
    function (req, res)
    {
        res.send(req.user.profile);
    }
});


module.exports = router;
{'fraction_non_alphanumeric': 0.16529449018366055, 'fraction_numerical': 0.004749841671944269, 'mean_word_length': 1.9830028328611897, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1741151', 'n_tokens_mistral': 963, 'n_tokens_neox': 940, 'n_words': 202}