# Path: sms.py
# def sms(number, message):
# 	client = TwilioRestClient(account, token)
# 	if number[0] != '+':
# 		if number[0] == '1':
# 			number = '+' + number
# 		else:
# 			assert len(number) == 10
# 			number = '+1' + number
# 	client.sms.messages.create(to=number, from_=from_number, body=message)


import math, json, os, random
import sqlalchemy as sa
import hashlib
import markdown2
from datetime import datetime
from sqlalchemy.orm import relationship
from sqlalchemy.types import *
from sms import sms
from metamodel import *
		from handler import handler
		from handler import handler
		from handler import email
			with transact:
				self.update(
						email=email, 
						email_verified=False
					)
			self.generateEmailVerification()

	def generateEmailVerification(self):
		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


# Path: sms.py
# def sms(number, message):
# 	client = TwilioRestClient(account, token)
# 	if number[0] != '+':
# 		if number[0] == '1':
# 			number = '+' + number
# 		else:
# 			assert len(number) == 10
# 			number = '+1' + number
# 	client.sms.messages.create(to=number, from_=from_number, body=message)


# Path: model.py
import math, json, os, random
import sqlalchemy as sa
import hashlib
import markdown2
from datetime import datetime
from sqlalchemy.orm import relationship
from sqlalchemy.types import *
from sms import sms
from metamodel import *
		from handler import handler
		from handler import handler
		from handler import email

			with transact:
				self.update(
						email=email, 
						email_verified=False
					)
			self.generateEmailVerification()

	def generateEmailVerification(self):
		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)