本文整理匯總了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')