<commit_before># -*- coding: utf-8 -*-
"""
Autores: XXX
Grupo YYY

Este código es fruto ÚNICAMENTE del trabajo de sus miembros. Declaramos no 
haber colaborado de ninguna manera con otros grupos, haber compartido el ćodigo 
con otros ni haberlo obtenido de una fuente externa.
""" 

from bottle import run, post, get
# Resto de importaciones
import pymongo
from bottle import request, route, run, template, response, static_file
from pymongo import MongoClient 
from bson.son import SON
from bson.code import Code
import random
import string
import hashlib
from passlib.hash import sha256_crypt

client 	= MongoClient()
db 		= client['giw']


"""
User Schema

	User = {
		"_id" : username,
		"name": name,
		"country" : country,
		"email": email,
		"password" : password
	} 

"""


#####################################
########## ASSETS ROUTING ###########
#####################################

@route('/views/<filepath:path>')
def file_stac(filepath):
    return static_file(filepath, root="./views")

@route('/<filename:re:.*\.js>')
def javascripts(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.css>')
def stylesheets(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.(jpg|png|gif|ico)>')
def images(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.(eot|ttf|woff|svg)>')
def fonts(filename):
    return static_file(filename, root='static/')

##############
# APARTADO A #
##############

# Returns the hash
def encryptPass(password):
	return sha256_crypt.encrypt(password)

def validPassword(password, hash):
	return sha256_crypt.verify(password, hash);

@get('/signup')
def signup_view():
	return template('signup_login', signup=True);

@post('/signup')
def signup():

	username = request.forms.get('username')
	password = request.forms.get('password')
	password2 = request.forms.get('password2')	

	if password != password2:
		return template('result', message="Password doesn't match");

	result = db.users.find({ "_id": username })

	if result.count() > 0:
		return template('result', message="Username is already registered on our database");

	# Valid user to this point. Insert it on the database.

	encryptedPassword = <PASSWORD>(password);

	User = {
		"_id" : username,
		"name": request.forms.get('name'),
		"country" : request.forms.get('country'),
		"email": request.forms.get('email'),
		"password" : <PASSWORD>
	}  
<commit_msg>Adding function to generate random char with 18 length<commit_after># -*- coding: utf-8 -*-
"""
Autores: XXX
Grupo YYY

Este código es fruto ÚNICAMENTE del trabajo de sus miembros. Declaramos no 
haber colaborado de ninguna manera con otros grupos, haber compartido el ćodigo 
con otros ni haberlo obtenido de una fuente externa.
""" 

from bottle import run, post, get
# Resto de importaciones
import pymongo
from bottle import request, route, run, template, response, static_file
from pymongo import MongoClient 
from bson.son import SON
from bson.code import Code
import random
import string
import hashlib
from passlib.hash import sha256_crypt

client 	= MongoClient()
db 		= client['giw']


"""
User Schema

	User = {
		"_id" : username,
		"name": name,
		"country" : country,
		"email": email,
		"password" : password
	} 

"""


#####################################
########## ASSETS ROUTING ###########
#####################################

@route('/views/<filepath:path>')
def file_stac(filepath):
    return static_file(filepath, root="./views")

@route('/<filename:re:.*\.js>')
def javascripts(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.css>')
def stylesheets(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.(jpg|png|gif|ico)>')
def images(filename):
    return static_file(filename, root='static/')

@route('/<filename:re:.*\.(eot|ttf|woff|svg)>')
def fonts(filename):
    return static_file(filename, root='static/')

##############
# APARTADO A #
##############

# Returns the hash
def encryptPass(password):
	return sha256_crypt.encrypt(password)

def validPassword(password, hash):
	return sha256_crypt.verify(password, hash);

# Genera una cadena aleatoria de 16 caracteres a escoger entre las 26 
# letras mayúsculas del inglés y los dígitos 2, 3, 4, 5, 6 y 7. 

def random_char(n):
	chars = string.ascii_uppercase + "234567"
	return ''.join(random.choice(chars) for x in range(n))

##############
# APARTADO A #
##############

@get('/')
def home():
	i = 0

	while i < 10:
		print random_char(16)
		i += 1

@get('/signup')
def signup_view():
	return template('signup_login', signup=True);

@post('/signup')
def signup():

	username = request.forms.get('username')
	password = request.forms.get('password')
	password2 = request.forms.get('password2')	

	if password != password2:
		return template('result', message="Password doesn't match");

	result = db.users.find({ "_id": username })

	if result.count() > 0:
		return template('result', message="Username is already registered on our database");

	# Valid user to this point. Insert it on the database.

	encryptedPassword = encryptPass(password);

	User = {
		"_id" : username,
		"name": request.forms.get('name'),
		"country" : request.forms.get('country'),
		"email": request.forms.get('email'),
		"password" : <PASSWORD>
	}  

{'fraction_non_alphanumeric': 0.18897196261682242, 'fraction_numerical': 0.0097196261682243, 'mean_word_length': 5.032694475760992, 'pattern_counts': {'":': 10, '<': 17, '<?xml version=': 0, '>': 18, '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': '5188784', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1728, 'n_words': 475}