<commit_before>querystring = require('querystring');

exports.getRoutes = () ->
	return [
		{
			method: 'GET'
			path:'/login' 
			config:
				handler: loginGetHandler
		}
		{
			method: 'GET'
			path: '/logout'
			config: 
            	handler: logoutHandler
            	auth: 
                	mode: 'try',
                	strategy: 'session'
            
           	 	plugins: 
                	'hapi-auth-cookie': 
                    	redirectTo: '/'   
		}
		{
			method: 'POST'
			path: '/login'
			config: 
            	handler: loginPostHandler
            	auth: 
                	mode: 'try',
                	strategy: 'session'
            
           	 	plugins: 
                	'hapi-auth-cookie': 
                    	redirectTo: false                            
		}
	]

navigationElement = 'account'

# Gets the login page
loginGetHandler = (req, reply) =>
	html = @renderer.render
		data: 
			results: ""
		template: "#{__dirname}/login.jade"

	reply html
# Sends a post to the api logging ing the user and starting a session.
loginPostHandler = (req, reply) =>
	body = 
		username : req.payload.username
		password : <PASSWORD>
		grant_type: "password"
	
	query = 
		headers:
			'Content-Type':'application/x-www-form-urlencoded'
		body: querystring.stringify body
		url: '/token'

	@post query, (status, response) =>	

		if(status is 200)
			url = "/users/" + response.username
			console.log url
			@get url, (sta, res) =>
				console.log sta
				if(sta is 200)
					credentials =
						toke: response
						user: res.users[0]
					req.auth.session.set credentials
					reply '<h2>Welcome </h2><a href="/logout">Logout</a>'
				else
					reply '<h2> Failed duh duh duuuuuhhh</h2>'
		else 
			reply '<h2> Failed duh duh duuuuuhhh</h2>'

#Logout the use, by clearing the session.
logoutHandler = (req, reply) =>
	credentials = req.auth.credentials
	console.log credentials
	req.auth.session.clear()
	html = "Logout"

	reply html
<commit_msg>Fixed error with setting of session<commit_after>querystring = require('querystring');

exports.getRoutes = () ->
	return [
		{
			method: 'GET'
			path:'/login' 
			config:
				handler: loginGetHandler
		}
		{
			method: 'GET'
			path: '/logout'
			config: 
            	handler: logoutHandler
            	auth: 
                	mode: 'try',
                	strategy: 'session'
            
           	 	plugins: 
                	'hapi-auth-cookie': 
                    	redirectTo: '/'   
		}
		{
			method: 'POST'
			path: '/login'
			config: 
            	handler: loginPostHandler
            	auth: 
                	mode: 'try',
                	strategy: 'session'
            
           	 	plugins: 
                	'hapi-auth-cookie': 
                    	redirectTo: false                            
		}
	]

navigationElement = 'account'

# Gets the login page
loginGetHandler = (req, reply) =>
	html = @renderer.render
		data: 
			results: ""
		template: "#{__dirname}/login.jade"

	reply html
# Sends a post to the api logging ing the user and starting a session.
loginPostHandler = (req, reply) =>
	body = 
		username : req.payload.username
		password : <PASSWORD>
		grant_type: "password"
	
	query = 
		headers:
			'Content-Type':'application/x-www-form-urlencoded'
		body: querystring.stringify body
		url: '/token'

	@post query, (status, response) =>	

		if(status is 200)
			url = "/users/" + response.username
			@get url, (sta, res) =>
				console.log sta
				if(sta is 200)
					data =
						token: response
						user:
							username: res.users[0].username
							gravatar: res.users[0].gravatar
							settings: res.users[0].settings

					req.auth.session.set data

					reply '<h2>Welcome </h2><a href="/logout">Logout</a>'
				else
					reply '<h2> Failed duh duh duuuuuhhh</h2>'
		else 
			reply '<h2> Failed duh duh duuuuuhhh</h2>'

#Logout the use, by clearing the session.
logoutHandler = (req, reply) =>
	req.auth.session.clear()
	html = "Logout"

	reply html

{'fraction_non_alphanumeric': 0.1181062704608411, 'fraction_numerical': 0.007051120624527827, 'mean_word_length': 1.8887272727272728, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '6477033', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1263, 'n_words': 314}