<commit_before>/**
 * Created by Nightpaws on 23/02/2016.
 */
var express = require('express'),
    bodyParser = require('body-parser'),
    responseFactory = require('./../response/response');

var users = function(){

    var userRouter = express.Router();

    userRouter.route('/auth')
        .post(function(req, res){

            var data = req.body;

            var Auth = require('./../modules/auth/userauth');
            var promise = Auth.validateUser(data.username, data.password);

            var response = responseFactory();

            promise
                .then(function(data){
                    response.setSuccessful(true);
                    response.setMessage('User logged in');
                    response.setResult(data);

                    res.json(response.getResponse());
                })
                .fail(function(data){

                    response.setSuccessful(false);
                    var message = (data.error) ? 'Error resolving password': (data.wrongPass) ? 'Incorrect username or password' : '';

                    response.setMessage(message);
                    res.json(response.getResponse());
                });

        });

    userRouter.route('/register')
        .post(function(req, res){

            var data = req.body;

            var auth = require('../modules/auth/userauth');
            var tokenPromise = auth.registerUser(data.username, data.email, data.password);

            var response = responseFactory();

            tokenPromise
                .then(function(data){

                    response.setSuccessful(true);
                    response.setMessage('User logged in');
                    response.setResult({token: data});

                    res.json(response.getResponse());

                })
                .fail(function(data){
                    response.setSuccessful(false);
                    response.setMessage(data);

                    res.json(response.getResponse());
                });
        });

    return userRouter;
};

module.exports = users;<commit_msg>Attempting to improve the authentication strategy for new registrations.<commit_after>/**
 * Created by Nightpaws on 23/02/2016.
 */
var express = require('express'),
    bodyParser = require('body-parser'),
    responseFactory = require('./../response/response');

var users = function(){

    var userRouter = express.Router();

    userRouter.route('/auth')
        .post(function(req, res){
            var data = req.body;
            var Auth = require('./../modules/auth/userauth');
            var promise = Auth.validateUser(data.username, data.password);
            var response = responseFactory();
            promise
                .then(function(data){
                    response.setSuccessful(true);
                    response.setMessage('User logged in');
                    response.setResult(data);
                    res.json(response.getResponse());
                })
                .fail(function(data){
                    response.setSuccessful(false);
                    var message = (data.error) ? 'Error resolving password': (data.wrongPass) ? 'Incorrect username or password' : '';
                    response.setMessage(message);
                    res.json(response.getResponse());
                });
        });

    userRouter.route('/register')
        .post(function(req, res){
            var data = req.body;
            var auth = require('../modules/auth/userauth');
            var tokenPromise = auth.registerUser(data.username, data.email, data.password);
            var authPromise = Auth.validateUser(data.username, data.password);
            var response = responseFactory();
            tokenPromise
                .then(function(data){
                    authPromise
                        .then(function(data){
                            response.setSuccessful(true);
                            response.setMessage('User logged in');
                            response.setResult({token: data});
                            res.json(response.getResponse());
                        })
                        .fail(function(data){
                            response.setSuccessful(false);
                            var message = (data.error) ? 'Error resolving password': (data.wrongPass) ? 'Registration Failed.' : '';
                            response.setMessage(message);
                            res.json(response.getResponse());
                        })

                })
                .fail(function(data){
                    response.setSuccessful(false);
                    response.setMessage(data);
                    res.json(response.getResponse());
                });
        });

    return userRouter;
};

module.exports = users;
{'fraction_non_alphanumeric': 0.12014940859099399, 'fraction_numerical': 0.0033201909109773814, 'mean_word_length': 1.4974093264248705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4540883', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1067, 'n_words': 210}