本文整理汇总了Python中itsdangerous.TimedJSONWebSignatureSerializer方法的典型用法代码示例。如果您正苦于以下问题:Python itsdangerous.TimedJSONWebSignatureSerializer方法的具体用法?Python itsdangerous.TimedJSONWebSignatureSerializer怎么用?Python itsdangerous.TimedJSONWebSignatureSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itsdangerous
的用法示例。
在下文中一共展示了itsdangerous.TimedJSONWebSignatureSerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unsubscribe_user
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def unsubscribe_user(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except:
return None, None
id = data.get('talk')
email = data.get('email')
if not id or not email:
return None, None
talk = Talk.query.get(id)
if not talk:
return None, None
Comment.query\
.filter_by(talk=talk).filter_by(author_email=email)\
.update({'notify': False})
db.session.commit()
return talk, email
示例2: change_email
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def change_email(self, token):
"""Verify the new email for this user."""
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except (BadSignature, SignatureExpired):
return False
if data.get('change_email') != self.id:
return False
new_email = data.get('new_email')
if new_email is None:
return False
if self.query.filter_by(email=new_email).first() is not None:
return False
self.email = new_email
db.session.add(self)
db.session.commit()
return True
示例3: verify_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def verify_auth_token(token):
"""Validate the token whether is night."""
serializer = Serializer(
current_app.config['SECRET_KEY'])
try:
# serializer object already has tokens in itself and wait for
# compare with token from HTTP Request /api/posts Method `POST`.
data = serializer.loads(token)
except SignatureExpired:
return None
except BadSignature:
return None
user = User.query.filter_by(id=data['id']).first()
return user
示例4: get_reset_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def get_reset_token(self, expires_sec=300):
s = Serializer(current_app.config["SECRET_KEY"], expires_sec)
return s.dumps({"user_id": self.id}).decode("utf-8")
示例5: verify_reset_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def verify_reset_token(token):
s = Serializer(current_app.config["SECRET_KEY"])
try:
user_id = s.loads(token)["user_id"]
except (KeyError, TypeError):
return None
return User.query.get(user_id)
示例6: generate_confirmation_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_confirmation_token(self, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'confirm': self.id})
示例7: confirm
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def confirm(self, token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except:
return False
if data.get('confirm') != self.id:
return False
self.confirmed = True
db.session.add(self)
return True
示例8: generate_reset_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_reset_token(self, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'reset': self.id})
示例9: reset_password
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def reset_password(self, token, new_password):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except:
return False
if data.get('reset') != self.id:
return False
self.password = new_password
db.session.add(self)
return True
示例10: generate_email_change_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_email_change_token(self, new_email, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'change_email': self.id, 'new_email': new_email})
示例11: generate_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_auth_token(self, expiration):
s = Serializer(current_app.config['SECRET_KEY'],
expires_in=expiration)
return s.dumps({'id': self.id}).decode('ascii')
示例12: verify_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def verify_auth_token(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except:
return None
return User.query.get(data['id'])
示例13: generate_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_auth_token(self, expiration):
s = Serializer(current_app.config['ECRET_KEY'],expires_in=expiration)
return s.dumps({'id': self.id})
示例14: verify_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def verify_auth_token(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
data = s.loads(token)
except:
return None
return User.query.get(data['id'])
# 把用户转换成JSON格式的序列化字典
# 提供给客户端的内容无需和数据库模型内部完全一致
示例15: generate_auth_token
# 需要导入模块: import itsdangerous [as 别名]
# 或者: from itsdangerous import TimedJSONWebSignatureSerializer [as 别名]
def generate_auth_token(self, expires_in=3600):
s = Serializer(current_app.config['SECRET_KEY'], expires_in=expires_in)
return s.dumps({'id': self.id}).decode('utf-8')