<commit_before>var MemSessionManager = require('./session/session').MemSessionManager,
	Cookie = require('./session/cookies').Cookie,
	vine = require('vine'),
	basic = require('./auth/basic');


exports.plugin = function(router)
{

	var session = new MemSessionManager();

	router.on({
		
		/**
		 */

		'pull -private session': function()
		{
			if(this.session) return this.next();

			var sessid = this.data.sessid,

			//key is an additional safe guard against session injections.
			key = 'undefined',
			req = this.req,
			self = this;

			//http?
			if(req)
			{
				key = req.headers['user-agent'];
				var sessidParts = (req.headers['cookie'] || '').match(/sessid=([^;]+)/);
				if(sessidParts) sessid = sessidParts[1];
			}


			session.getSession( { id: sessid, key: key }, function(session)
			{
				self.session = session;

				self.respond({ session: session });

				if(!self.next()) vine.message('session set').end(self);
			});
		},


		/**
		 * basic authentication passthru
		 */

		'pull -private basic/auth/:user/:pass': function()
		{
			if(!this.req) return vine.error('basic auth is specific to http for now').end();

			var self = this;


			basic.test({
				request: self.req,
				login: function(user, pass, callback)
				{
					if(self.data.user == user && self.data.pass == pass)
					{
						callback(false, { name: user, pass: pass });
					}
					else
					{
						callback(true);
					}
				},
				callback: function(err, user)
				{
					if(err)
					{
						self.respond({ authorization: { http: err } });

						return self.end(vine.error('Unauthorized.'));
					}

					self.user = user;

					if(!self.next()) vine.message('Authorized').end(self)
				}
			});
		},

		/**
		 * parses post body
		 */

		/*'pull -private /*': function()
		{
<commit_msg>added ability to pass login func in ops<commit_after>var MemSessionManager = require('./session/session').MemSessionManager,
	Cookie = require('./session/cookies').Cookie,
	vine = require('vine'),
	basic = require('./auth/basic');


exports.plugin = function(router)
{

	var session = new MemSessionManager();

	router.on({
		
		/**
		 */

		'pull -private session': function()
		{
			if(this.session) return this.next();

			var sessid = this.data.sessid,

			//key is an additional safe guard against session injections.
			key = 'undefined',
			req = this.req,
			self = this;

			//http?
			if(req)
			{
				key = req.headers['user-agent'];
				var sessidParts = (req.headers['cookie'] || '').match(/sessid=([^;]+)/);
				if(sessidParts) sessid = sessidParts[1];
			}


			session.getSession( { id: sessid, key: key }, function(session)
			{
				self.session = session;

				self.respond({ session: session });

				if(!self.next()) vine.message('session set').end(self);
			});
		},


		/**
		 * basic authentication passthru
		 */

		'pull -private (basic/auth/:user/:pass or basic/auth)': function()
		{
			if(!this.req) return vine.error('basic auth is specific to http for now').end();

			var self = this;


			basic.test({
				request: self.req,
				login: this.login || function(user, pass, callback)
				{
					if(self.data.user == user && self.data.pass == pass)
					{
						callback(false, { name: user, pass: pass });
					}
					else
					{
						callback(true);
					}
				},
				callback: function(err, user)
				{
					if(err)
					{
						self.respond({ authorization: { http: err } });

						return self.end(vine.error('Unauthorized.').end());
					}

					self.profile = user;

					if(!self.next()) vine.message('Authorized').result(user).end(self)
				}
			});
		},

		/**
		 * parses post body
		 */

		/*'pull -private /*': function()
		{

{'fraction_non_alphanumeric': 0.17659923455440132, 'fraction_numerical': 0.0005467468562055768, 'mean_word_length': 2.6156126482213438, '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': '1068917', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1175, 'n_words': 258}