# 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 random, re
import markdown2
from sms import sms
from handler import *
from model import *
from datetime import datetime
		return phone_number

	user = User.one(id=id)
	if not user or user != session.user: abort(403)

	phone_number = normalize(phone_number)
	if phone_number != '' and len(phone_number) != 10:
		redirect(get_index.url(id, error='Invalid phone number'))
	elif email != '' and (u'@' not in email or '\n' in email or '\r' in email or ',' in email):
		redirect(get_index.url(id, error='Invalid email'))
	with transact:
		user.update(
				phone_notifications=phone_notify == u'on', 
				email_notifications=email_notify == u'on'
			)
		if phone_number != user.phone_number:
			user.update(
					phone_number=phone_number, 
					phone_verified=False
				)
		user.change(email=email)

	redirect(get_index.url(id))

def generatePhoneVerification():
	with transact:
		session.user.update(
				phone_verification_code=random.randrange(1, 1000000), 
				phone_verification_tries=0
			)

# 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: handlers/user.py
import random, re
import markdown2
from sms import sms
from handler import *
from model import *
from datetime import datetime

		return phone_number

	user = User.one(id=id)
	if not user or user != session.user: abort(403)

	phone_number = normalize(phone_number)
	if phone_number != '' and len(phone_number) != 10:
		redirect(get_index.url(id, error='Invalid phone number'))
	elif email != '' and (u'@' not in email or '\n' in email or '\r' in email or ',' in email):
		redirect(get_index.url(id, error='Invalid email'))
	with transact:
		user.update(
				phone_notifications=phone_notify == u'on', 
				email_notifications=email_notify == u'on'
			)
		if phone_number != user.phone_number:
			user.update(
					phone_number=phone_number, 
					phone_verified=False
				)
		user.change(email=email)

	redirect(get_index.url(id))

def generatePhoneVerification():
	with transact:
		session.user.update(
				phone_verification_code=random.randrange(1, 1000000), 
				phone_verification_tries=0
			)

	sms(session.user.phone_number, 'Quest Companions verification code: %06i' % session.user.phone_verification_code)