# 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
		new=True
	return dict(new=new)

@handler('user/verify')
def post_verify(code):
	if session.user.phone_verified:
		redirect(get_index.url(session.user.id))

	if session.user.phone_verification_code == int(code):
		with transact:
			session.user.update(phone_verified=True)
		redirect(get_index.url(session.user.id))
	elif session.user.phone_verification_tries < 9:
		with transact:
			session.user.update(phone_verification_tries=session.user.phone_verification_tries+1)
		new = False
	else:
		generatePhoneVerification()
		new = True
	return dict(code=code, new=new)

@handler('user/verify')
def get_resend_code():
	if session.user.phone_verified:
		redirect(get_index.url(session.user.id))

	new = False
	if not session.user.phone_verification_code:
		generatePhoneVerification()
		new=True

# 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

		new=True
	return dict(new=new)

@handler('user/verify')
def post_verify(code):
	if session.user.phone_verified:
		redirect(get_index.url(session.user.id))

	if session.user.phone_verification_code == int(code):
		with transact:
			session.user.update(phone_verified=True)
		redirect(get_index.url(session.user.id))
	elif session.user.phone_verification_tries < 9:
		with transact:
			session.user.update(phone_verification_tries=session.user.phone_verification_tries+1)
		new = False
	else:
		generatePhoneVerification()
		new = True
	return dict(code=code, new=new)

@handler('user/verify')
def get_resend_code():
	if session.user.phone_verified:
		redirect(get_index.url(session.user.id))

	new = False
	if not session.user.phone_verification_code:
		generatePhoneVerification()
		new=True

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