本文整理汇总了Python中itsdangerous.Signer.unsign方法的典型用法代码示例。如果您正苦于以下问题:Python Signer.unsign方法的具体用法?Python Signer.unsign怎么用?Python Signer.unsign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itsdangerous.Signer
的用法示例。
在下文中一共展示了Signer.unsign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_machine_token
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def validate_machine_token(self, token):
s = Signer(self.secret)
try:
s.unsign(token)
return True
except BadSignature:
return False
示例2: get_from_signed_code
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def get_from_signed_code(cls, code):
"""Returns a discount policy given a valid signed code, returns None otherwise"""
if not cls.is_signed_code_format(code):
return None
discount_code_base = code.split('.')[0]
policy = cls.query.filter_by(discount_code_base=discount_code_base).one_or_none()
if not policy:
return None
signer = Signer(policy.secret)
try:
signer.unsign(code)
return policy
except BadSignature:
return None
示例3: validate_csrf_token
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def validate_csrf_token(csrf_token):
secret_key = current_app.config.get("WTF_CSRF_SECRET_KEY", current_app.secret_key)
signer = Signer(secret_key)
# if current_user.is_anonymous():
# return False
try:
signer.unsign(csrf_token)
except BadSignature:
return False
# if str(current_user.get_id()) == id:
# return True
return True
示例4: reset_password
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def reset_password():
form = ResetPasswordForm(request.form)
if request.method == "POST" and form.validate():
token = form.token.data
s = Signer(app.config['SECRET_KEY'])
try:
email = s.unsign(token)
except BadSignature:
return render_template("reset_invalid_token.html")
user = User.query.filter_by(email=email).first()
if user:
user.set_password(form.password.data)
print user.password
login_user(user)
return redirect("/")
else:
return render_template("reset_invalid_token.html")
token = request.args.get('token', None)
if not token:
return render_template("reset_invalid_token.html")
return render_template("reset_password.html", form=form, token=token)
示例5: check_token
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def check_token(token):
signer = Signer(flask.current_app.config["SECRET_KEY"])
try:
id = int(signer.unsign(token).decode("ascii"))
except Exception as e:
return None
user = Subscriber.query.filter_by(id=id).first()
return user
示例6: split_cookie
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def split_cookie(self, rv):
signer = Signer(self.app.secret_key)
cookie_data = rv.headers['Set-Cookie'].split(';', 1)[0]
for cookie in cookie_data.split('&'):
name, value = cookie_data.split('=')
if name == self.app.session_cookie_name:
unsigned_value = signer.unsign(value)
return unsigned_value.split('_')
示例7: attachment
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def attachment(self, att_id):
s = Signer(current_app.config.get('SECRET_KEY'), sep='$')
try:
att_id = int(s.unsign(att_id))
attach_obj = self.model.client.model('ir.attachment')
content = attach_obj.read(att_id, ['datas'])['datas']
image_fp = StringIO(base64.b64decode(content))
return send_file(image_fp)
except BadSignature:
abort(404)
示例8: cookie_unserialize
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def cookie_unserialize(session_data, secure_key):
"""Unserialize the cookie: separate the session_id and expire_time timestamp."""
signer = Signer(secret_key=secure_key)
try:
session_data = signer.unsign(session_data).decode('utf-8')
except BadSignature:
session_data = None
if not session_data:
return None, None
session_id, session_expire = session_data.split('&')
return session_id, session_expire
示例9: split_cookie
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def split_cookie(app, rv):
signer = Signer(app.secret_key)
cookie_data = rv.headers['Set-Cookie'].split(';', 1)[0]
for cookie in cookie_data.split('&'):
name, value = cookie_data.split('=')
if name == app.session_cookie_name:
unsigned_value = signer.unsign(value)
sid, created = unsigned_value.split(b('_'))
return sid.decode('ascii'), int(created, 16)
示例10: verify
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def verify():
s = Signer(
bytes(input("Enter a secret(!!) key: "),
encoding="UTF-8"))
try:
unsigned = s.unsign(bytes(
input("Enter data\n"),
encoding="UTF-8")).decode('UTF-8')
except BadSignature:
print("!!!!! FAILED !!!!!")
return 0
print("---")
print(unsigned)
示例11: _get_user_id
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def _get_user_id():
if current_app.config.get('DEBUG'):
return request.values.get('user_id')
if 'mws-track-id' not in request.cookies:
raise MWSServerError(400, "Invalid request (missing cookie)")
key = current_app.config.get('EDX_SHARED_KEY')
s = Signer(key)
try:
user_id = s.unsign(request.cookies['mws-track-id'])
except (BadSignature, TypeError) as e:
_logger.exception(e)
raise MWSServerError(403, "Invalid request (invalid cookie)")
return user_id
示例12: task_run
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def task_run():
signer = Signer(current_app.secret_key)
_data = request.form['_']
data = json.loads(signer.unsign(_data))
callname = data.get('call')
a, kw = data['args'], data['kwargs']
modname, symname = callname.rsplit('.', 1)
mod = __import__(modname, fromlist=[symname])
call = getattr(mod, symname)
call.direct(*a, **kw)
return 'ok'
示例13: get_public_deploy_key
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def get_public_deploy_key(instance_dns_name, secret, salt):
''' Wait for and retrieve instance public key.
'''
signer = Signer(secret, salt)
path = '/.well-known/deploy-key.txt'
while True:
print(' Waiting for', path)
sleep(5)
resp = requests.get('http://{}{}'.format(instance_dns_name, path))
if resp.status_code == 200:
break
return signer.unsign(resp.content)
示例14: uid_is_valid
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def uid_is_valid(user, uid, festival):
s = Signer(SECRET_SIGN_KEY)
# cookie is uid hashed with our private key, check that the cookie was sent
cookie = cherrypy.request.cookie.get('mfc_sch'+str(uid))
if cookie:
# and if it's correct
return str(uid) == s.unsign(str(cookie.value))
elif user:
#check if this user is the user that's allowed for this uid.
with get_db() as cur:
cur.execute("select id from mfc.schedules where username = %s and festival = %s", [user['email'], festival])
r = cur.fetchall()
if r:
return str(uid) == str(r[0]['id'])
# else not valid
else:
return False
示例15: confirm_user
# 需要导入模块: from itsdangerous import Signer [as 别名]
# 或者: from itsdangerous.Signer import unsign [as 别名]
def confirm_user(data=None):
if not utils.get_config('verify_emails'):
# If the CTF doesn't care about confirming email addresses then redierct to challenges
return redirect(url_for('challenges.challenges_view'))
# User is confirming email account
if data and request.method == "GET":
try:
s = Signer(app.config['SECRET_KEY'])
email = s.unsign(urllib.unquote_plus(data.decode('base64')))
except BadSignature:
return render_template('confirm.html', errors=['Your confirmation link seems wrong'])
except:
return render_template('confirm.html', errors=['Your link appears broken, please try again.'])
team = Teams.query.filter_by(email=email).first_or_404()
team.verified = True
db.session.commit()
logger = logging.getLogger('regs')
logger.warn("[{0}] {1} confirmed {2}".format(time.strftime("%m/%d/%Y %X"), team.name.encode('utf-8'), team.email.encode('utf-8')))
db.session.close()
if utils.authed():
return redirect(url_for('challenges.challenges_view'))
return redirect(url_for('auth.login'))
# User is trying to start or restart the confirmation flow
if not utils.authed():
return redirect(url_for('auth.login'))
team = Teams.query.filter_by(id=session['id']).first_or_404()
if data is None:
if request.method == "POST":
# User wants to resend their confirmation email
if team.verified:
return redirect(url_for('views.profile'))
else:
utils.verify_email(team.email)
return render_template('confirm.html', team=team, infos=['Your confirmation email has been resent!'])
elif request.method == "GET":
# User has been directed to the confirm page
team = Teams.query.filter_by(id=session['id']).first_or_404()
if team.verified:
# If user is already verified, redirect to their profile
return redirect(url_for('views.profile'))
return render_template('confirm.html', team=team)