<commit_before>// API for activity spam checker
//
// Copyright 2011, 2012 StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Training and measuring values

var config = require('../config'),
    _ = require('underscore'),
    User = require('../models/user').User,
    NoSuchThingError = require('databank').NoSuchThingError,
    Tokenizer = require('../lib/tokenizer').Tokenizer,
    SpamFilter = require('../lib/spamfilter').SpamFilter;

exports.index = function(req, res, next) {
    res.render('index', { title: 'Home', 
                          site: (config.site) ? config.site : "ActivitySpam" });
};

exports.api = function(req, res, next) {
    res.render('api', { title: 'API', 
                        site: (config.site) ? config.site : "ActivitySpam" });
};

exports.loginForm = function(req, res, next) {
    res.render('login', { title: 'Login', 
                          error: null,
                          site: (config.site) ? config.site : "ActivitySpam" });
};

exports.registerForm = function(req, res, next) {
    res.render('register', { title: 'Register', 
                             error: null,
                             site: (config.site) ? config.site : "ActivitySpam" });
};

exports.login = function(req, res, next) {

    var user, email, password,
        showError = function(message) {
            res.render('login', { title: 'Login',
                                  error: message,
                                  site: (config.site) ? config.site : "ActivitySpam" });
        };

    if (!_(req.params).has('email')) {
        showError("No email.");
        return;
    }

    if (!_(req.params).has('password')) {
        showError("No password.");
        return;
    }

    User.get(req.params.email, function(err, user) {
        if (err) {
            showError("Incorrect email or password.");
            return;
        }

        user.checkPassword(req.params.password, function(err, match) {
            if (!match) {
                showError("Incorrect email or password.");
                return;
            }
            req.session.email = email;
            res.redirect('/apps', 303);
        });
    });
};

exports.register = function(req, res, next) {
    var user, email, password,
        showError = function(message) {
            res.render('register', { title: 'Register',
                                     error: message,
                                     site: (config.site) ? config.site : "ActivitySpam" });
        };

    if (!_(req.params).has('email')) {
        showError("No email.");
        return;
    }

    email = req.params.email;

    if (!_(req.params).has('password')) {
        showError("No password.");
        return;
    }

    password = <PASSWORD>;

    if (!_(req.params).has('confirm')) {
        showError("No password confirmation.");
        return;
    }

    confirm = req.params.confirm;

    if (confirm !== password) {
        showError("Passwords don't match.");
        return;
    }

    User.get(req.params.email, function(err, old) {
        var newUser;
        if (old) {
            showError("User already exists");
            return;
        }
        newUser = {email: email,
                   password: password};
        User.create(newUser, function(err, user) {<commit_msg>req.params -> req.body for POST params<commit_after>// API for activity spam checker
//
// Copyright 2011, 2012 StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Training and measuring values

var config = require('../config'),
    _ = require('underscore'),
    User = require('../models/user').User,
    NoSuchThingError = require('databank').NoSuchThingError,
    Tokenizer = require('../lib/tokenizer').Tokenizer,
    SpamFilter = require('../lib/spamfilter').SpamFilter;

exports.index = function(req, res, next) {
    res.render('index', { title: 'Home', 
                          site: (config.site) ? config.site : "ActivitySpam" });
};

exports.api = function(req, res, next) {
    res.render('api', { title: 'API', 
                        site: (config.site) ? config.site : "ActivitySpam" });
};

exports.loginForm = function(req, res, next) {
    res.render('login', { title: 'Login', 
                          error: null,
                          site: (config.site) ? config.site : "ActivitySpam" });
};

exports.registerForm = function(req, res, next) {
    res.render('register', { title: 'Register', 
                             error: null,
                             site: (config.site) ? config.site : "ActivitySpam" });
};

exports.login = function(req, res, next) {

    var user, email, password,
        showError = function(message) {
            res.render('login', { title: 'Login',
                                  error: message,
                                  site: (config.site) ? config.site : "ActivitySpam" });
        };

    if (!_(req.body).has('email')) {
        showError("No email.");
        return;
    }

    if (!_(req.body).has('password')) {
        showError("No password.");
        return;
    }

    User.get(req.body.email, function(err, user) {
        if (err) {
            showError("Incorrect email or password.");
            return;
        }

        user.checkPassword(req.body.password, function(err, match) {
            if (!match) {
                showError("Incorrect email or password.");
                return;
            }
            req.session.email = email;
            res.redirect('/apps', 303);
        });
    });
};

exports.register = function(req, res, next) {
    var user, email, password,
        showError = function(message) {
            res.render('register', { title: 'Register',
                                     error: message,
                                     site: (config.site) ? config.site : "ActivitySpam" });
        };

    if (!_(req.body).has('email')) {
        showError("No email.");
        return;
    }

    email = req.body.email;

    if (!_(req.body).has('password')) {
        showError("No password.");
        return;
    }

    password = <PASSWORD>;

    if (!_(req.body).has('confirm')) {
        showError("No password confirmation.");
        return;
    }

    confirm = req.body.confirm;

    if (confirm !== password) {
        showError("Passwords don't match.");
        return;
    }

    User.get(req.body.email, function(err, old) {
        var newUser;
        if (old) {
            showError("User already exists");
            return;
        }
        newUser = {email: email,
                   password: password};
        User.create(newUser, function(err, user) {
{'fraction_non_alphanumeric': 0.1425783790815663, 'fraction_numerical': 0.0039026928580720697, 'mean_word_length': 1.9176470588235295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368133', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2069, 'n_words': 550}