bottle authentication 插件
Bottle-Cork
Cork provides a simple set of methods to implement Authentication and Authorization in web applications based on Bottle.
http://cork.firelet.net/
code https://github.com/FedericoCeratto/bottle-cork
下面是个更简单的示例(利用bottle.auth_basic):
import bottle
def check(user, passwd):
if user == 'ben':
return True
return False
@[bottle.route('/')](/name/bottle.route('/')) @[bottle.auth_basic(ch](/name/bottle.auth_basic(ch) eck)
def index():
print 'auth', bottle.request.auth
print 'remote_addr', bottle.request.remote_addr
return "Yay - you made it!"
if __name__ == '__main__':
print "Starting server"
bottle.run(host='0.0.0.0', port=8080, reloader=True)
import urllib2, base64
(user, password) = ('ben', 'xyz')
request = urllib2.Request("http://localhost:8080/")
base64string = base64.encodestring('%s:%s' % (user, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
print result.read()
摘菜 http://fledglingpolymath.tumblr.com/post/39977900894/basic-authentication-in-bottle-py
基于 cookie 的
def require_uid(fn):
def check_uid(**kwargs):
cookie_uid = request.get_cookie('cookieName', secret='cookieSignature')
if cookie_uid:
//do stuff with a user object
return fn(**kwargs)
else:
redirect("/loginagain")
return check_uid
@[route('/userstuff',](/name/route('/userstuff',) method='GET')
@[require_uid](/name/require_uid) @[view('app')](/name/view('app'))
def app_userstuff():
//doing things is what i like to do
return dict(foo="bar")
摘菜 http://stackoverflow.com/questions/14087418/check-authentification-for-each-request-in-bottle
0
See Also
- 请问有没有分享插件
- bottle_leveldb.py plugin
- leveldb+bottle+gevent 是个不错的组合
- 12306抢票插件拖垮美国代码托管站Github后转托SAE
- 视频功能最好是用插件式的
Nearby
- 上一篇 › 站长请进,程序在新浪商店还支持不,想装个试试
- 下一篇 › 菜鸟求助,论坛头像怎么不显示?
auth_basic
bottlepy-user-auth
https://github.com/bbrodriges/bottlepy-user-auth