X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Fadmin%2Flogin.py;h=ae5b15acb2dd33c690e746b98bbb0da1eba51296;hp=70b477f5828e95b66daef97dbb7c3e02f58a0e41;hb=b7b80c5c0fc1895e85aae3acbfcbbc593a42697f;hpb=d7e4bbbf32e5bfae87bfa686fbb5f86efcb04ee1 diff --git a/ipsilon/admin/login.py b/ipsilon/admin/login.py index 70b477f..ae5b15a 100755 --- a/ipsilon/admin/login.py +++ b/ipsilon/admin/login.py @@ -1,150 +1,12 @@ #!/usr/bin/python # -# Copyright (C) 2014 Simo Sorce -# -# see file 'COPYING' for use and warranty information -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Copyright (C) 2014 Ipsilon Contributors see COPYING for license -import cherrypy -from ipsilon.util.page import Page -from ipsilon.util.page import admin_protect -from ipsilon.util.plugin import PluginObject -from ipsilon.admin.common import AdminPluginPage +from ipsilon.admin.common import AdminPlugins from ipsilon.login.common import FACILITY -class LoginPluginsOrder(Page): - +class LoginPlugins(AdminPlugins): def __init__(self, site, parent): - super(LoginPluginsOrder, self).__init__(site, form=True) - self.url = '%s/order' % parent.url - self.menu = [parent] - - @admin_protect - def GET(self, *args, **kwargs): - return self._template('admin/login_order.html', - title='login plugins order', - name='admin_login_order_form', - menu=self.menu, action=self.url, - options=self._site[FACILITY]['enabled']) - - @admin_protect - def POST(self, *args, **kwargs): - message = "Nothing was modified." - message_type = "info" - valid = self._site[FACILITY]['enabled'] - - if 'order' in kwargs: - order = kwargs['order'].split(',') - if len(order) != 0: - new_values = [] - try: - for v in order: - val = v.strip() - if val not in valid: - error = "Invalid plugin name: %s" % val - raise ValueError(error) - new_values.append(val) - if len(new_values) < len(valid): - for val in valid: - if val not in new_values: - new_values.append(val) - - po = PluginObject() - po.name = "global" - globalconf = dict() - globalconf['order'] = ','.join(new_values) - po.set_config(globalconf) - po.save_plugin_config(FACILITY) - - # When all is saved update also live config - self._site[FACILITY]['enabled'] = new_values - - message = "New configuration saved." - message_type = "success" - - except ValueError, e: - message = str(e) - message_type = "error" - - except Exception, e: # pylint: disable=broad-except - message = "Failed to save data!" - message_type = "error" - - return self._template('admin/login_order.html', - message=message, - message_type=message_type, - title='login plugins order', - name='admin_login_order_form', - menu=self.menu, action=self.url, - options=self._site[FACILITY]['enabled']) - - -class LoginPlugins(Page): - def __init__(self, site, parent): - super(LoginPlugins, self).__init__(site) - self._master = parent + super(LoginPlugins, self).__init__('login', site, parent, FACILITY) self.title = 'Login Plugins' - self.url = '%s/login' % parent.url - self.facility = FACILITY - parent.add_subtree('login', self) - - for plugin in self._site[FACILITY]['available']: - cherrypy.log.error('Admin login plugin: %s' % plugin) - obj = self._site[FACILITY]['available'][plugin] - self.__dict__[plugin] = AdminPluginPage(obj, self._site, self) - - self.order = LoginPluginsOrder(self._site, self) - - def root_with_msg(self, message=None, message_type=None): - login_plugins = self._site[FACILITY] - ordered = [] - for p in login_plugins['enabled']: - ordered.append(p.name) - return self._template('admin/login.html', title=self.title, - message=message, - message_type=message_type, - available=login_plugins['available'], - enabled=ordered, - menu=self._master.menu) - - def root(self, *args, **kwargs): - return self.root_with_msg() - - def enable(self, plugin): - msg = None - plugins = self._site[FACILITY] - if plugin not in plugins['available']: - msg = "Unknown plugin %s" % plugin - return self.root_with_msg(msg, "error") - obj = plugins['available'][plugin] - if obj not in plugins['enabled']: - obj.enable(self._site) - msg = "Plugin %s enabled" % obj.name - return self.root_with_msg(msg, "success") - enable.exposed = True - - def disable(self, plugin): - msg = None - plugins = self._site[FACILITY] - if plugin not in plugins['available']: - msg = "Unknown plugin %s" % plugin - return self.root_with_msg(msg, "error") - obj = plugins['available'][plugin] - if obj in plugins['enabled']: - obj.disable(self._site) - msg = "Plugin %s disabled" % obj.name - return self.root_with_msg(msg, "success") - disable.exposed = True