本文整理汇总了Python中www.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类www.models.User
的用法示例。
在下文中一共展示了User.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_register_user
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def api_register_user(*, email, name, passwd): # https://www.python.org/dev/peps/pep-3102/
if not name or not name.strip():
raise APIValueError('name')
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?', [email])
if len(users) > 0:
raise APIError('register:failed', 'email', 'email already in use')
uid = next_id()
sha1_passwd = '%s:%s' % (uid, passwd) # get SHA1 for uid+passwd
user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
yield from user.save()
# make session cookie:
r = web.Response()
r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
return r
示例2: api_register_user
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def api_register_user(*, email, name, passwd):
#判断name是否为空:
if not name or not name.strip():
raise APIValueError('name')
#判断email是否为空及是否满足email格式:
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
#判断password首付为空及是否满足password格式:
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
#数据中查询对应的email信息:
users = yield from User.findAll('email=?', [email])
#判断查询结果是否存在,若存在则返回异常提示邮件已存在:
if len(users) > 0:
raise APIError('register:failed', 'email', 'Email is already in use.')
#生成唯一ID:
uid = next_id()
#重构唯一ID和password成新的字符串:
sha1_passwd = '%s:%s' % (uid, passwd)
#构建用户对象信息:
#hashlib.sha1().hexdigest():取得SHA1哈希摘要算法的摘要值。
user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='http://www(first).gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
#将用户信息存储到数据库:
yield from user.save()
# make session cookie:
#构造session cookie信息:
r = web.Response()
#aiohttp.web.StreamResponse().set_cookie():设置cookie的方法。
r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True) #max_age:定义cookie的有效期(秒);
user.passwd = '******'
r.content_type = 'application/json'
#以json格式序列化响应信息; ensure_ascii默认为True,非ASCII字符也进行转义。如果为False,这些字符将保持原样。
r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
return r
示例3: do_signup
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def do_signup(sender, interval):
logger("Entering do_signup (%s)" % (sender))
try:
try:
user = User(phonenumber=sender,interval=int(interval))
except (ValueError, IndexError):
user = User(phonenumber=sender)
user.save()
except:
logger("user already exists! %s" % sender)
#TODO send a message back? fail silently?
#raise Exception, "User '%s' already exists" % sender
raise
return
signup_email = "Thank you for signing up! How to play: we will send you a message listing a definition and a choice of four words. You must choose the correct word corresponding to that definition. Respond with only the number of the word that you believe is correct. Text 'stats' to see how you're doing and 'quit' to leave WordiSMS."
SMS(user.phonenumber, signup_email).send()
logger("Exiting do_signup")
return
示例4: test_save
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test_save():
loop = asyncio.get_event_loop()
loop.run_until_complete(www.orm.create_pool(loop, user='root', password='root', db='awesome'))
u = User(name='Test', email='[email protected]', passwd='1234567890', image='about:blank')
loop.run_until_complete(u.save())
loop.stop()
示例5: api_register_user
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def api_register_user(*, email, name, passwd):
if not name or not name.strip():
raise APIValueError('name')
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?', [email])
if len(users) > 0:
raise APIError('register:failed', 'email', 'Email is already in use.')
uid = next_id()
sha1_password = '%s:%s' % (uid, passwd)
user = User(id=uid, name=name.strip(), email=email,passwd=hashlib.sha1(sha1_password.encode('utf-8').hexdigest(),
image=''))
yield from user.save()
r = web.Response()
r.set_cookie(COOKIE_NAME,user2cookie(user, 86400), max_age=86400, httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user,ensure_ascii=False).enconde('utf-8')
return r
示例6: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from orm.create_pool(loop=loop, user='www-data', password='www-data', database='awesome')
u=User(admin=True, name='kHRYSTAL', email='[email protected]', passwd=hashlib.sha1(('%s:%s' % (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(), image='about:blank')
yield from u.save()
示例7: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from www.orm.create_pool(host="127.0.0.1", port=3306, user="root", password="1", db="awesome", loop=loop)
u = User(name="test3", email="[email protected]", passwd="test", image="about:blank")
yield from u.save()
示例8: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from www.orm.create_pool(loop=loop, user='www-data', password='www-data', db='awesome')
u = User(name='test77',email='[email protected]',passwd='test',image='about:blank')
yield from u.save()
示例9: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from orm.create_pool(loop=loop, user='www-data', password='www-data', database='awesome')
u=User(name='Yao', email='[email protected]', passwd="sas", image='about:blank')
yield from u.save()
示例10: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from www.orm.create_pool(loop=loop, user='weibo', password='weibo', db='weibo')
u = User(name='Test1', email='[email protected]', passwd='1234567890', image='about:blank')
yield from u.save()
示例11: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop):
yield from www.orm.create_pool(loop=loop, host='localhost', port=3306, user='root', password='123456', db='awesome')
u = User(name='test85',email='[email protected]',passwd='test',image='about:blank')
yield from u.save()
示例12: test
# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import save [as 别名]
def test(loop, x):
yield from orm.create_pool(user='root', password='', database='awesome', loop=loop)
u = User(name='Test%d' % x, email='test%[email protected]' % x, passwd='123456', image='about:blank')
yield from u.save()