我想出的唯一解决方案是实现我自己的小后端并自己设置 cookie,无需烧杯。
为了后代的利益,代码在这里:
https ://github.com/paulbarbu/bottle-upload/blob/master/index.py
方法:login_bl
、、、和。请注意,这是一些非常旧的代码,还没有准备好生产,使用风险自负,上面链接中的一些代码片段如下:upload_view(db)
is_logged_in
logout()
登录:
@post('/login')
def login_bl(db):
import hashlib
nick = request.forms.nick.lower()
password = hashlib.sha1(request.forms.password).hexdigest()
message = {}
error = None
uid = get_user_id(db, nick, password)
if uid:
sess = request.environ.get('beaker.session')
sess['uid'] = uid
# .... do other stuff for the logged in user
登出:
@get('/logout')
def logout():
if not is_logged_in():
redirect('/login')
else:
sess = request.environ.get('beaker.session')
sess.delete()
return template('logout.tpl')
用户是否登录?
def is_logged_in():
'''Check whether the user sent a cookie that holds a Beaker created
session id
'''
sess_id = request.cookies.get('beaker.session.id', False)
if not sess_id:
return False
sess = request.environ.get('beaker.session')
if 'uid' not in sess:
return False
return True