當前位置: 首頁>>代碼示例>>Python>>正文


Python Customer.token方法代碼示例

本文整理匯總了Python中models.Customer.token方法的典型用法代碼示例。如果您正苦於以下問題:Python Customer.token方法的具體用法?Python Customer.token怎麽用?Python Customer.token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Customer的用法示例。


在下文中一共展示了Customer.token方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post_customer

# 需要導入模塊: from models import Customer [as 別名]
# 或者: from models.Customer import token [as 別名]
def post_customer(request):
	customer_data = json.loads(request.body)
	mail = customer_data.get('mail', None)
	phone = customer_data.get('phone', None)
	password = customer_data.get('password', None)
	name = customer_data.get('name', u'狗蛋兒')

	if mail is None or password is None or phone is None:
		content = dict()
		content['status'] = 422
		content['msg'] = u'信息缺失'
		return create_simple_response(422, json.dumps(content))
	if str(mail).split('@')[-1] != 'bjtu.edu.cn':
		content = dict()
		content['status'] = 422
		content['msg'] = u'郵箱不符,現階段隻對北京交大郵箱開放注冊'
		return create_simple_response(422, json.dumps(content))

	new_customer = Customer()
	new_customer.mail = mail
	new_customer.phone = phone
	new_customer.password = password
	new_customer.token = generate_token()
	new_customer.name = name
	if_signed = new_customer.signup_customer()

	if if_signed:
		content = dict()
		try:
			query_str = 'customers/'+str(new_customer.id)+'?validate=true&token='+new_customer.token
			reg_msg = u'感謝您注冊順道兒,請點擊鏈接完成驗證: <a href="%s%s%s">- 驗證 GO -</a>'%(BASE_SCHEMES, BASE_PATH, query_str)
			send_register_email(new_customer.mail, reg_msg, reg_subject)
		except:
			content['status'] = 422
			content['msg'] = u'驗證失敗'
		else:
			content['status'] = 201
			content['msg'] = u'注冊成功,請登錄郵箱進行驗證'
			content['href'] = '%s%s%s' % (BASE_PATH, 'customers/', str(new_customer.id))
		finally:
			return create_simple_response(201, json.dumps(content))
	else:
		content = dict()
		content['status'] = 422
		content['msg'] = u'注冊失敗'
		return create_simple_response(422, json.dumps(content))
開發者ID:carpaanddonkey,項目名稱:byway,代碼行數:48,代碼來源:customers.py


注:本文中的models.Customer.token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。