<commit_before>// middleware.js
//
// Some things you may need
//
// 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.

var databank = require('databank'),
    Step = require('step'),
    _ = require('underscore'),
    bcrypt  = require('bcrypt'),
    fs = require('fs'),
    Activity = require('./model/activity').Activity,
    User = require('./model/user').User,
    HTTPError = require('./httperror').HTTPError,
    NoSuchThingError = databank.NoSuchThingError;

// If there is a user in the params, gets that user and
// adds them to the request as req.user
// also adds the user's profile to the request as req.profile
// Note: req.user != req.remoteUser

var reqUser = function(req, res, next) {
    var user;

    Step(
        function() {
            User.get(req.params.nickname, this);
        },
        function(err, results) {
            if (err) {
                if (err instanceof NoSuchThingError) {
                    next(new HTTPError(err.message, 404));
                    return;
                } else {
                    throw err;
                }
            }
            user = results;
            user.sanitize();
            req.user = user;
            user.expand(this);
        },
        function(err) {
            if (err) {
                next(err);
            } else {
                req.person = user.profile;
                next();
            }
        }
    );
};

var sameUser = function(req, res, next) {
    if (!req.remoteUser ||
        !req.user ||
        req.remoteUser.nickname != req.user.nickname) {
        next(new Error("Not authorized"));<commit_msg>Throw it, don't next it<commit_after>// middleware.js
//
// Some things you may need
//
// 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.

var databank = require('databank'),
    Step = require('step'),
    _ = require('underscore'),
    bcrypt  = require('bcrypt'),
    fs = require('fs'),
    Activity = require('./model/activity').Activity,
    User = require('./model/user').User,
    HTTPError = require('./httperror').HTTPError,
    NoSuchThingError = databank.NoSuchThingError;

// If there is a user in the params, gets that user and
// adds them to the request as req.user
// also adds the user's profile to the request as req.profile
// Note: req.user != req.remoteUser

var reqUser = function(req, res, next) {
    var user;

    Step(
        function() {
            User.get(req.params.nickname, this);
        },
        function(err, results) {
            if (err) {
                if (err instanceof NoSuchThingError) {
                    throw new HTTPError(err.message, 404);
                } else {
                    throw err;
                }
            }
            user = results;
            user.sanitize();
            req.user = user;
            user.expand(this);
        },
        function(err) {
            if (err) {
                next(err);
            } else {
                req.person = user.profile;
                next();
            }
        }
    );
};

var sameUser = function(req, res, next) {
    if (!req.remoteUser ||
        !req.user ||
        req.remoteUser.nickname != req.user.nickname) {
        next(new Error("Not authorized"));
{'fraction_non_alphanumeric': 0.11856148491879351, 'fraction_numerical': 0.0069605568445475635, 'mean_word_length': 1.9227118644067798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3990466', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1165, 'n_words': 387}