本文整理汇总了Python中db.User.salt方法的典型用法代码示例。如果您正苦于以下问题:Python User.salt方法的具体用法?Python User.salt怎么用?Python User.salt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.User
的用法示例。
在下文中一共展示了User.salt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_post
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import salt [as 别名]
def on_post(self, req, resp):
doc = req.context['doc']
users=Session.query(User).all()
unique=True
for user in users:
if doc['email'] == user.email:
unique=False
if unique:
user = User(name=doc['name'], email=doc['email'].lower(), signedin=False,registerTime=datetime.datetime.today())
print(datetime.datetime.today())
user.salt = bcrypt.gensalt()
user.pw_hash = bcrypt.hashpw(doc['password'].encode('utf-8'), user.salt)
s=smtplib.SMTP_SSL('smtp.gmail.com',465)
s.ehlo()
s.login('[email protected]','[email protected]')
code=randint(1000000,10000000)
user.code=code
msg=MIMEText('Hi '+user.name+', your verification URL is: '+'http://192.168.1.127:8000/confirmation/'+str(code))
msg['From']='[email protected]'
msg['To']=user.email
msg['Subject']='PhoenixNow Account Confirmation'
s.send_message(msg)
s.close()
Session.add(user)
Session.flush()
Session.commit()
req.context['user'] = user.id
req.context['result'] = {"result": "success", "action": "register"}
else:
user=get_user(req,resp)
td=datetime.timedelta(minutes=30)
if datetime.datetime.today()-td<user.registerTime or user.emailVerified==True:
description = "User was already made"
title = "User creation conflict"
raise falcon.HTTPConflict(title=title, description=description)
else:
Session.delete(user)
Session.flush()
user = User(name=doc['name'], email=doc['email'], signedin=False,registerTime=datetime.datetime.today())
print(datetime.datetime.today())
user.salt = bcrypt.gensalt()
user.pw_hash = bcrypt.hashpw(doc['password'].encode('utf-8'), user.salt)
s=smtplib.SMTP_SSL('smtp.gmail.com',465)
s.ehlo()
s.login('[email protected]','[email protected]')
code=randint(1000000,10000000)
user.code=code
msg=MIMEText('Hi '+user.name+', your verification URL is: '+'http://192.168.1.127:8000/confirmation/'+str(code))
msg['From']='[email protected]'
msg['To']=user.email
msg['Subject']='PhoenixNow Account Confirmation'
s.send_message(msg)
s.close()
Session.add(user)
Session.flush()
Session.commit()
req.context['user'] = user.id
req.context['result'] = {"result": "success", "action": "register"}