本文整理汇总了Python中models.Session.create方法的典型用法代码示例。如果您正苦于以下问题:Python Session.create方法的具体用法?Python Session.create怎么用?Python Session.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Session
的用法示例。
在下文中一共展示了Session.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signin
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import create [as 别名]
def signin(user):
sid = hashlib.sha256(repr(time.time()).encode()).hexdigest()
response.set_cookie('sid', sid, max_age=SESSION_LIFE_TIME, path='/')
response.set_cookie('username', user.username, max_age=SESSION_LIFE_TIME, path='/')
Session.create(
user=user,
sid=sid
)
示例2: auth
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import create [as 别名]
def auth(self, data):
if len(self.auth_salt) < SALT_LEN:
return
name = data["login"]
try:
user = User.get(god_name=name)
except User.DoesNotExist:
self.send("auth", {"status": "fail"})
return
req = hashlib.sha1((user.password + self.auth_salt).encode()).hexdigest()
if not data["password"] == req:
self.send("auth", {"status": "fail"})
return
self.auth_salt = ""
self.auth_sid = rnd_gen(32)
s = Session.create(sid=self.auth_sid, god=name)
s.save()
self.gvd.login(self, name)
self.auth_status = True
self.send("auth", {"status": "success", "sid": self.auth_sid})
示例3: signin
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import create [as 别名]
def signin(user):
site_id = hashlib.sha256(repr(time.time()).encode()).hexdigest()
response.set_cookie('site_id', site_id, max_age=SESSION_LIFE_TIME, path='/')
response.set_cookie('username', user.username, max_age=SESSION_LIFE_TIME, path='/')
session = SessionModel.create(
site_id=site_id,
username=user.username,
signined_at=datetime.datetime.now()
)
示例4: load_session
# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import create [as 别名]
def load_session(self, session_str):
session = Session.create(session_str)
if session:
self.connection.load_session(session)
self.session = session