# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from ipsilon.util.log import Log
from ipsilon.util.page import Page
from ipsilon.util.user import UserSession
from ipsilon.util.plugin import PluginLoader, PluginObject
import cherrypy
-class LoginManagerBase(PluginObject):
+class LoginManagerBase(PluginObject, Log):
def __init__(self):
super(LoginManagerBase, self).__init__()
if not ref:
ref = cherrypy.config.get('base.mount', "") + '/'
- session.login(username)
-
- # Save additional data provided by the login manager
- if userdata:
- for key in userdata:
- session.save_data('user', key, userdata[key])
+ session.login(username, userdata)
raise cherrypy.HTTPRedirect(ref)
raise cherrypy.HTTPRedirect(ref)
- def _debug(self, fact):
- if cherrypy.config.get('debug', False):
- cherrypy.log(fact)
-
def get_tree(self, site):
raise NotImplementedError
raise cherrypy.HTTPError(500)
+class LoginFormBase(LoginPageBase):
+
+ def __init__(self, site, mgr, page, template=None):
+ super(LoginFormBase, self).__init__(site, mgr)
+ self.formpage = page
+ self.formtemplate = template or 'login/form.html'
+
+ def GET(self, *args, **kwargs):
+ context = self.create_tmpl_context()
+ # pylint: disable=star-args
+ return self._template(self.formtemplate, **context)
+
+ def root(self, *args, **kwargs):
+ op = getattr(self, cherrypy.request.method, self.GET)
+ if callable(op):
+ return op(*args, **kwargs)
+
+ def create_tmpl_context(self, **kwargs):
+ next_url = None
+ if self.lm.next_login is not None:
+ next_url = self.lm.next_login.path
+
+ context = {
+ "title": 'Login',
+ "action": '%s/%s' % (self.basepath, self.formpage),
+ "service_name": self.lm.service_name,
+ "username_text": self.lm.username_text,
+ "password_text": self.lm.password_text,
+ "description": self.lm.help_text,
+ "next_url": next_url,
+ }
+ context.update(kwargs)
+ return context
+
+
FACILITY = 'login_config'