<commit_before># -*- coding: utf-8 -*-

import os
import time
import logging
import unicodedata

import string, pickle
from random import choice

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render

from django.contrib.auth.models import User
from userprofile.models import Profile as userprofile

from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth import logout

logger = logging.getLogger(__name__)

from django.core.mail import send_mail


def _remove_accents(data):
    return ''.join(x for x in unicodedata.normalize('NFKD', data) if x in string.ascii_letters).lower()


def user_logout(request):
	
	print '-- logout'
	
	try:
		logout(request)
	except:
		pass
		
	print request.user
	
	return HttpResponseRedirect("/goodbye/")



def goodbye(request):

	return render_to_response('goodbye.html', {}, context_instance=RequestContext(request))


def register(request):

	print '-- registration:'

	err = None

	if request.POST:

		name = request.POST[u'username']
		email = request.POST[u'email']
		username = email

		password1 = request.POST[u'password1']
		password2 = request.POST[u'<PASSWORD>']

		print username


		if not password1 or not password2:
			err = "empty_password"
			print err

		if(password1 != password2):
			err = "password_mismatch"
			print err

		if not err:

			passwd = <PASSWORD>

			try:
				User.objects.create_user(username, email, passwd)
			except:
				err = "duplicate_username"
				print err

			if not err:

				user = authenticate(username=username, password=<PASSWORD>)

				if(user):

					secret = (''.join([choice(string.digits) for i in range(3)]) + '-' + \
						''.join([choice(string.letters + string.digits) for i in range(4)]) + '-' + \
						''.join([choice(string.digits) for i in range(5)])).upper()

					username = _remove_accents(username)

					userprofile.objects.get_or_create(user=user,secret=secret,name=name,language="EN")
					login(request, user)

					request.session['language'] = "us"
					
					send_mail('New user has registered.', 'New user ' + request.user.email + ' has registered.', '<EMAIL>', ['<EMAIL>'], fail_silently=True)

					print 'new user registered'
					print username

					return HttpResponseRedirect("/welcome/")


	return render_to_response('register.html', {'err':err,}, context_instance=RequestContext(request))


def auth(request):
	
	print '-- auth:'
	
	if(request.method == 'POST'):

		post = request.POST
		
		print post
		
		try:
			email = request.POST['username']
			passwprd = request.POST['password']
		except:
			print 'failed login code:1'
			return HttpResponseRedirect("/register")

		
		try:
			user = User.objects.get(email=email)
		except:
			print 'failed login code:2'
			return HttpResponseRedirect("/register")

		try:
			user = authenticate(username=user.username, password=<PASSWORD>)
			login(request, user)
		except:
			print 'failed login code:3'
			return HttpResponseRedirect("/register")
			
		print 'user logged in', user
		
		return HttpResponseRedirect("/")
		
	
	return render_to_response('login.html', {}, context_instance=RequestContext(request))


def cloud_settings(request):
	
	return HttpResponse("working on this currently")
	

def lock(request):
	
	print '-- lock screen:'

	if not request.user.is_authenticated():
		return HttpResponseRedirect("/")

	user = request.user
	profile = userprofile.objects.get(user=request.user)
	secret = profile.secret

	print request.user

	return render_to_response('lock.html', locals(), context_instance=RequestContext(request))

	
def change_password(request):
<commit_msg>made the cloud settings to serve the template from its url<commit_after># -*- coding: utf-8 -*-

import os
import time
import logging
import unicodedata

import string, pickle
from random import choice

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render

from django.contrib.auth.models import User
from userprofile.models import Profile as userprofile

from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth import logout

logger = logging.getLogger(__name__)

from django.core.mail import send_mail


def _remove_accents(data):
    return ''.join(x for x in unicodedata.normalize('NFKD', data) if x in string.ascii_letters).lower()


def user_logout(request):
	
	print '-- logout'
	
	try:
		logout(request)
	except:
		pass
		
	print request.user
	
	return HttpResponseRedirect("/goodbye/")



def goodbye(request):

	return render_to_response('goodbye.html', {}, context_instance=RequestContext(request))


def register(request):

	print '-- registration:'

	err = None

	if request.POST:

		name = request.POST[u'username']
		email = request.POST[u'email']
		username = email

		password1 = request.POST[u'password1']
		password2 = request.POST[u'password2']

		print username


		if not password1 or not password2:
			err = "empty_password"
			print err

		if(password1 != password2):
			err = "password_mismatch"
			print err

		if not err:

			passwd = <PASSWORD>

			try:
				User.objects.create_user(username, email, passwd)
			except:
				err = "duplicate_username"
				print err

			if not err:

				user = authenticate(username=username, password=<PASSWORD>)

				if(user):

					secret = (''.join([choice(string.digits) for i in range(3)]) + '-' + \
						''.join([choice(string.letters + string.digits) for i in range(4)]) + '-' + \
						''.join([choice(string.digits) for i in range(5)])).upper()

					username = _remove_accents(username)

					userprofile.objects.get_or_create(user=user,secret=secret,name=name,language="EN")
					login(request, user)

					request.session['language'] = "us"
					
					print 'new user registered'
					print username

					return HttpResponseRedirect("/welcome/")


	return render_to_response('register.html', {'err':err,}, context_instance=RequestContext(request))


def auth(request):
	
	print '-- auth:'
	
	if(request.method == 'POST'):

		post = request.POST
		
		print post
		
		try:
			email = request.POST['username']
			passwprd = request.POST['password']
		except:
			print 'failed login code:1'
			return HttpResponseRedirect("/register")

		
		try:
			user = User.objects.get(email=email)
		except:
			print 'failed login code:2'
			return HttpResponseRedirect("/register")

		try:
			user = authenticate(username=user.username, password=<PASSWORD>)
			login(request, user)
		except:
			print 'failed login code:3'
			return HttpResponseRedirect("/register")
			
		print 'user logged in', user
		
		return HttpResponseRedirect("/")
		
	
	return render_to_response('login.html', {}, context_instance=RequestContext(request))


def cloud_settings(request):
	
	print '-- cloud settings:'

	if not request.user.is_authenticated():
		return HttpResponseRedirect("/")

	user = request.user
	profile = userprofile.objects.get(user=request.user)
	secret = profile.secret

	print request.user

	return render_to_response('cloud_settings.html', locals(), context_instance=RequestContext(request))
	

def lock(request):
	
	print '-- lock screen:'

	if not request.user.is_authenticated():
		return HttpResponseRedirect("/")

	user = request.user
	profile = userprofile.objects.get(user=request.user)
	secret = profile.secret

	print request.user

	return render_to_response('lock.html', locals(), context_instance=RequestContext(request))

	
def change_password(request):

{'fraction_non_alphanumeric': 0.11538950311348328, 'fraction_numerical': 0.0036853475663997967, 'mean_word_length': 4.232712765957447, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '6499172', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2309, 'n_words': 601}