本文整理汇总了Python中ajenti.middleware.AuthenticationMiddleware.get方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationMiddleware.get方法的具体用法?Python AuthenticationMiddleware.get怎么用?Python AuthenticationMiddleware.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ajenti.middleware.AuthenticationMiddleware
的用法示例。
在下文中一共展示了AuthenticationMiddleware.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_persona_auth
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_persona_auth(self, context):
assertion = context.query.getvalue('assertion', None)
audience = context.query.getvalue('audience', None)
if not assertion:
return self.context.respond_forbidden()
data = {
'assertion': assertion,
'audience': audience,
}
resp = requests.post('https://verifier.login.persona.org/verify', data=data, verify=True)
if resp.ok:
verification_data = json.loads(resp.content)
if verification_data['status'] == 'okay':
context.respond_ok()
email = verification_data['email']
for user in ajenti.config.tree.users.values():
if user.email == email:
AuthenticationMiddleware.get().login(context, user.name)
break
else:
context.session.data['login-error'] = _('Email "%s" is not associated with any user') % email
return ''
context.session.data['login-error'] = _('Login failed')
return context.respond_not_found()
示例2: handle_auth
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_auth(self, context):
username = context.query.getvalue("username", "")
password = context.query.getvalue("password", "")
if not AuthenticationMiddleware.get().try_login(context, username, password):
context.session.data["login-error"] = _("Invalid login or password")
gevent.sleep(3)
return context.redirect("/")
示例3: handle_auth
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_auth(self, context):
username = context.query.getvalue('username', '')
password = context.query.getvalue('password', '')
if not AuthenticationMiddleware.get().try_login(
context, username, password, env=context.env,
):
context.session.data['login-error'] = _('Invalid login or password')
gevent.sleep(3)
return context.redirect('/')
示例4: handle_persona_auth
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_persona_auth(self, context):
assertion = context.query.getvalue("assertion", None)
audience = context.query.getvalue("audience", None)
if not assertion:
return self.context.respond_forbidden()
data = {"assertion": assertion, "audience": audience}
resp = requests.post("https://verifier.login.persona.org/verify", data=data, verify=True)
if resp.ok:
verification_data = json.loads(resp.content)
if verification_data["status"] == "okay":
context.respond_ok()
email = verification_data["email"]
for user in ajenti.config.tree.users.values():
if user.email == email:
AuthenticationMiddleware.get().login(context, user.name)
break
else:
context.session.data["login-error"] = _('Email "%s" is not associated with any user') % email
return ""
context.session.data["login-error"] = _("Login failed")
return context.respond_not_found()
示例5: handle_logout
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_logout(self, context):
AuthenticationMiddleware.get().logout(context)
context.session.destroy()
return context.redirect("/")
示例6: handle_auth
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def handle_auth(self, context):
username = context.query.getvalue("username", "")
password = context.query.getvalue("password", "")
if not AuthenticationMiddleware.get().try_login(context, username, password):
gevent.sleep(3)
return context.redirect("/")
示例7: run
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def run():
ajenti.init()
reload(sys)
sys.setdefaultencoding('utf8')
try:
locale.setlocale(locale.LC_ALL, '')
except:
logging.warning('Couldn\'t set default locale')
logging.info('Ajenti %s running on platform: %s' % (ajenti.version, ajenti.platform))
if ajenti.debug:
def cmd_list_instances(ctx=None):
import pprint
if not ctx:
from ajenti.plugins import manager
ctx = manager.context
pprint.pprint(ctx._get_all_instances())
def cmd_sessions():
import pprint
sessions = SessionMiddleware.get().sessions
return sessions
def cmd_list_instances_session():
cmd_list_instances(cmd_sessions().values()[0].appcontext)
exconsole.register(commands=[
('_manager', 'PluginManager', ajenti.plugins.manager),
('_instances', 'return all @plugin instances', cmd_list_instances),
('_sessions', 'return all Sessions', cmd_sessions),
('_instances_session', 'return all @plugin instances in session #0', cmd_list_instances_session),
])
# Load plugins
ajenti.plugins.manager.load_all()
Inflater.get().precache()
bind_spec = (ajenti.config.tree.http_binding.host, ajenti.config.tree.http_binding.port)
if ':' in bind_spec[0]:
addrs = socket.getaddrinfo(bind_spec[0], bind_spec[1], socket.AF_INET6, 0, socket.SOL_TCP)
bind_spec = addrs[0][-1]
# Fix stupid socketio bug (it tries to do *args[0][0])
socket.socket.__getitem__ = lambda x, y: None
logging.info('Starting server on %s' % (bind_spec, ))
if bind_spec[0].startswith('/'):
if os.path.exists(bind_spec[0]):
os.unlink(bind_spec[0])
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
listener.bind(bind_spec[0])
except:
logging.error('Could not bind to %s' % bind_spec[0])
sys.exit(1)
listener.listen(10)
else:
listener = socket.socket(socket.AF_INET6 if ':' in bind_spec[0] else socket.AF_INET, socket.SOCK_STREAM)
try:
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
except:
try:
socket.TCP_NOPUSH = 4
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_NOPUSH, 1)
except:
logging.warn('Could not set TCP_CORK/TCP_NOPUSH')
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
listener.bind(bind_spec)
except:
logging.error('Could not bind to %s' % (bind_spec,))
sys.exit(1)
listener.listen(10)
stack = [
SessionMiddleware.get(),
AuthenticationMiddleware.get(),
CentralDispatcher.get()
]
ssl_args = {}
if ajenti.config.tree.ssl.enable:
ssl_args['certfile'] = ajenti.config.tree.ssl.certificate_path
ajenti.server = SocketIOServer(
listener,
log=open(os.devnull, 'w'),
application=HttpRoot(stack).dispatch,
policy_server=False,
resource='ajenti:socket',
transports=[
str('websocket'),
str('flashsocket'),
str('xhr-polling'),
str('jsonp-polling'),
],
**ssl_args
#.........这里部分代码省略.........
示例8: run
# 需要导入模块: from ajenti.middleware import AuthenticationMiddleware [as 别名]
# 或者: from ajenti.middleware.AuthenticationMiddleware import get [as 别名]
def run():
ajenti.init()
reload(sys)
sys.setdefaultencoding("utf8")
try:
locale.setlocale(locale.LC_ALL, "")
except:
logging.warning("Couldn't set default locale")
logging.info("Ajenti %s running on platform: %s" % (ajenti.version, ajenti.platform))
if not ajenti.platform in ["debian", "centos", "freebsd"]:
logging.warn("%s is not officially supported!" % ajenti.platform)
if ajenti.debug:
def cmd_list_instances(ctx=None):
import pprint
if not ctx:
from ajenti.plugins import manager
ctx = manager.context
pprint.pprint(ctx._get_all_instances())
def cmd_sessions():
import pprint
sessions = SessionMiddleware.get().sessions
return sessions
def cmd_list_instances_session():
cmd_list_instances(cmd_sessions().values()[0].appcontext)
exconsole.register(
commands=[
("_manager", "PluginManager", ajenti.plugins.manager),
("_instances", "return all @plugin instances", cmd_list_instances),
("_sessions", "return all Sessions", cmd_sessions),
("_instances_session", "return all @plugin instances in session #0", cmd_list_instances_session),
]
)
# Load plugins
ajenti.plugins.manager.load_all()
Inflater.get().precache()
bind_spec = (ajenti.config.tree.http_binding.host, ajenti.config.tree.http_binding.port)
if ":" in bind_spec[0]:
addrs = socket.getaddrinfo(bind_spec[0], bind_spec[1], socket.AF_INET6, 0, socket.SOL_TCP)
bind_spec = addrs[0][-1]
# Fix stupid socketio bug (it tries to do *args[0][0])
socket.socket.__getitem__ = lambda x, y: None
logging.info("Starting server on %s" % (bind_spec,))
if bind_spec[0].startswith("/"):
if os.path.exists(bind_spec[0]):
os.unlink(bind_spec[0])
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
listener.bind(bind_spec[0])
except:
logging.error("Could not bind to %s" % bind_spec[0])
sys.exit(1)
listener.listen(10)
else:
listener = socket.socket(socket.AF_INET6 if ":" in bind_spec[0] else socket.AF_INET, socket.SOCK_STREAM)
if not ajenti.platform in ["freebsd", "osx"]:
try:
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
except:
logging.warn("Could not set TCP_CORK")
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
listener.bind(bind_spec)
except:
logging.error("Could not bind to %s" % (bind_spec,))
sys.exit(1)
listener.listen(10)
stack = [SessionMiddleware.get(), AuthenticationMiddleware.get(), CentralDispatcher.get()]
ssl_args = {}
if ajenti.config.tree.ssl.enable:
ssl_args["certfile"] = ajenti.config.tree.ssl.certificate_path
logging.info("SSL enabled: %s" % ssl_args["certfile"])
ajenti.server = SocketIOServer(
listener,
log=open(os.devnull, "w"),
application=HttpRoot(stack).dispatch,
policy_server=False,
handler_class=RootHttpHandler,
resource="ajenti:socket",
transports=[str("websocket"), str("flashsocket"), str("xhr-polling"), str("jsonp-polling")],
**ssl_args
)
#.........这里部分代码省略.........