# Path: metamodel.py
# def createLocalSession():
# 	request._session = scoped_session(sessionmaker())
# 	request._session.configure(bind=engine)
# 
# def closeLocalSession():
# 	request._session.remove()
# 
# Path: model.py
# class User(object):
# 	enabled = Boolean
# 	admin = Boolean
# 	username = Unicode(255)
# 	password = String(88)
# 	gold = Integer
# 	email = String
# 	email_verified = Boolean
# 	email_verification = String
# 	email_notifications = Boolean
# 	phone_number = String
# 	phone_verified = Boolean
# 	phone_verification_code = Integer
# 	phone_verification_tries = Integer
# 	phone_notifications = Boolean
# 	feedback_score = Integer
# 	feedback_positive = Integer
# 	feedback_negative = Integer
# 
# 	characters = Character.relation(backref='user')
# 	news = News.relation(backref='creator')
# 	jobs = Job.relation(backref='user')
# 	gold_history = GoldHistory.relation(backref='user')
# 	feedbacks = Feedback.relation(backref='profile')
# 
# 
# 	@staticmethod
# 	def hash(password):
# 		salt = ''.join('%02x' % ord(c) for c in os.urandom(24))
# 		for i in range(1000):
# 			password = hashlib.sha1(salt + password + salt).hexdigest()
# 		return salt+password
# 
# 	@staticmethod
# 	def checkHash(hash, password):
# 		salt, hash = hash[:48], hash[48:]
# 		for i in range(1000):
# 			password = hashlib.sha1(salt + password + salt).hexdigest()
# 		if password == hash:
# 			return True
# 		return False
# 
# 	@staticmethod
# 	def add(username, password, admin):
# 		if User.one(enabled=True, username=username):
# 			return None
# 		with transact:
# 			return User.create(
# 				enabled=True, 
# 				username=username, 
# 				password=User.hash(password), 
# 				admin=admin, 
# 				gold=0, 
# 				phone_number='', 
# 				phone_verified=False, 
# 				phone_notifications=True, 
# 				email='', 
# 				email_verified=False,
# 				email_notifications=True, 
# 				feedback_score = 0,
# 				feedback_positive = 0,
# 				feedback_negative = 0
# 			)
# 	
# 	@staticmethod
# 	def find(username, password):
# 		if username == None or password == None:
# 			return None
# 		user = User.one(enabled=True, username=username)
# 		if user and User.checkHash(user.password, password):
# 			return user
# 		if not user and len(User.all()) == 0:
# 			return User.add(username, password, True)
# 		return None
# 	
# 	def change(self, email=None):
# 		if email != None and email != self.email:
# 			with transact:
# 				self.update(
# 						email=email, 
# 						email_verified=False
# 					)
# 			self.generateEmailVerification()
# 
# 	def generateEmailVerification(self):
# 		from handler import email
# 		code = ''.join('%02X' % random.randrange(256) for i in range(20))
# 		with transact:
# 			self.update(email_verification=code)
# 		email(self.email, 'verify', code=code)
# 
# 	def addGold(self, amount, price):
# 		with transact:
# 			self.update(gold=self.gold+amount)
# 			GoldHistory.create(
# 					user=self, 
# 					date=datetime.now(), 
# 					amount=amount, 
# 					balance=self.gold, 
# 					dollars=price, 
# 					job=None, 
# 					desc=u'Bought %i gold for $%.2f' % (amount, price / 100.0)
# 				)
# 
# 	def sms(self, message):
# 		if not self.phone_verified:
# 			return False
# 
# 		sms(self.phone_number, message)
# 		return True


import os
import smtplib
from json import dumps
from flask import abort, render_template, request, session
from flask import redirect as _redirect
from werkzeug.exceptions import HTTPException
from metamodel import createLocalSession, closeLocalSession
from model import User
from urllib import quote, urlencode
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from jinja2 import Environment, FileSystemLoader
				ret = ret.replace('$CSRF$', csrf)

			closeLocalSession()
			return ret

		func.func_name = '__%s__%s__' % (module, name)

		def url(_id=None, **kwargs):
			if module == 'index':
				url = '/'
				trailing = True
			else:
				url = '/%s' % module
				trailing = False
			if name != 'index':
				if not trailing:
					url += '/'
				url += '%s' % name
				trailing = False
			if _id != None:
				if not trailing:
					url += '/'
				url += quote(str(_id))
			if len(kwargs):
				url += '?'
				url += urlencode(dict((k, str(v)) for k, v in kwargs.items()))
			return url

		ustr = StrObject(url())
		ustr.__call__ = ofunc

# Path: metamodel.py
# def createLocalSession():
# 	request._session = scoped_session(sessionmaker())
# 	request._session.configure(bind=engine)
# 
# def closeLocalSession():
# 	request._session.remove()
# 
# Path: model.py
# class User(object):
# 	enabled = Boolean
# 	admin = Boolean
# 	username = Unicode(255)
# 	password = String(88)
# 	gold = Integer
# 	email = String
# 	email_verified = Boolean
# 	email_verification = String
# 	email_notifications = Boolean
# 	phone_number = String
# 	phone_verified = Boolean
# 	phone_verification_code = Integer
# 	phone_verification_tries = Integer
# 	phone_notifications = Boolean
# 	feedback_score = Integer
# 	feedback_positive = Integer
# 	feedback_negative = Integer
# 
# 	characters = Character.relation(backref='user')
# 	news = News.relation(backref='creator')
# 	jobs = Job.relation(backref='user')
# 	gold_history = GoldHistory.relation(backref='user')
# 	feedbacks = Feedback.relation(backref='profile')
# 
# 
# 	@staticmethod
# 	def hash(password):
# 		salt = ''.join('%02x' % ord(c) for c in os.urandom(24))
# 		for i in range(1000):
# 			password = hashlib.sha1(salt + password + salt).hexdigest()
# 		return salt+password
# 
# 	@staticmethod
# 	def checkHash(hash, password):
# 		salt, hash = hash[:48], hash[48:]
# 		for i in range(1000):
# 			password = hashlib.sha1(salt + password + salt).hexdigest()
# 		if password == hash:
# 			return True
# 		return False
# 
# 	@staticmethod
# 	def add(username, password, admin):
# 		if User.one(enabled=True, username=username):
# 			return None
# 		with transact:
# 			return User.create(
# 				enabled=True, 
# 				username=username, 
# 				password=User.hash(password), 
# 				admin=admin, 
# 				gold=0, 
# 				phone_number='', 
# 				phone_verified=False, 
# 				phone_notifications=True, 
# 				email='', 
# 				email_verified=False,
# 				email_notifications=True, 
# 				feedback_score = 0,
# 				feedback_positive = 0,
# 				feedback_negative = 0
# 			)
# 	
# 	@staticmethod
# 	def find(username, password):
# 		if username == None or password == None:
# 			return None
# 		user = User.one(enabled=True, username=username)
# 		if user and User.checkHash(user.password, password):
# 			return user
# 		if not user and len(User.all()) == 0:
# 			return User.add(username, password, True)
# 		return None
# 	
# 	def change(self, email=None):
# 		if email != None and email != self.email:
# 			with transact:
# 				self.update(
# 						email=email, 
# 						email_verified=False
# 					)
# 			self.generateEmailVerification()
# 
# 	def generateEmailVerification(self):
# 		from handler import email
# 		code = ''.join('%02X' % random.randrange(256) for i in range(20))
# 		with transact:
# 			self.update(email_verification=code)
# 		email(self.email, 'verify', code=code)
# 
# 	def addGold(self, amount, price):
# 		with transact:
# 			self.update(gold=self.gold+amount)
# 			GoldHistory.create(
# 					user=self, 
# 					date=datetime.now(), 
# 					amount=amount, 
# 					balance=self.gold, 
# 					dollars=price, 
# 					job=None, 
# 					desc=u'Bought %i gold for $%.2f' % (amount, price / 100.0)
# 				)
# 
# 	def sms(self, message):
# 		if not self.phone_verified:
# 			return False
# 
# 		sms(self.phone_number, message)
# 		return True


# Path: handler.py
import os
import smtplib
from json import dumps
from flask import abort, render_template, request, session
from flask import redirect as _redirect
from werkzeug.exceptions import HTTPException
from metamodel import createLocalSession, closeLocalSession
from model import User
from urllib import quote, urlencode
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from jinja2 import Environment, FileSystemLoader

				ret = ret.replace('$CSRF$', csrf)

			closeLocalSession()
			return ret

		func.func_name = '__%s__%s__' % (module, name)

		def url(_id=None, **kwargs):
			if module == 'index':
				url = '/'
				trailing = True
			else:
				url = '/%s' % module
				trailing = False
			if name != 'index':
				if not trailing:
					url += '/'
				url += '%s' % name
				trailing = False
			if _id != None:
				if not trailing:
					url += '/'
				url += quote(str(_id))
			if len(kwargs):
				url += '?'
				url += urlencode(dict((k, str(v)) for k, v in kwargs.items()))
			return url

		ustr = StrObject(url())
		ustr.__call__ = ofunc

		ustr.url = url