1 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
3 from ipsilon.login.common import LoginFormBase, LoginManagerBase, \
5 from ipsilon.util.plugin import PluginObject
6 from ipsilon.util import config as pconfig
11 class TestAuth(LoginFormBase):
13 def POST(self, *args, **kwargs):
14 username = kwargs.get("login_name")
15 password = kwargs.get("login_password")
18 if username and password:
19 if password == 'ipsilon':
20 cherrypy.log("User %s successfully authenticated." % username)
22 'givenname': 'Test User',
24 'fullname': 'Test User %s' % username,
25 'email': '%s@example.com' % username,
28 return self.lm.auth_successful(self.trans,
29 username, 'password', testdata)
31 cherrypy.log("User %s failed authentication." % username)
32 error = "Authentication failed"
34 error = "Username or password is missing"
35 cherrypy.log.error("Error: " + error, severity=logging.ERROR)
37 context = self.create_tmpl_context(
40 error_password=not password,
41 error_username=not username
43 self.lm.set_auth_error()
44 return self._template('login/form.html', **context)
47 class LoginManager(LoginManagerBase):
49 def __init__(self, *args, **kwargs):
50 super(LoginManager, self).__init__(*args, **kwargs)
51 self.name = 'testauth'
52 self.service_name = 'testauth'
53 self.path = 'testauth'
55 self.description = """
56 Form based TEST login Manager, DO NOT EVER ACTIVATE IN PRODUCTION """
61 'Text used to ask for the username at login time.',
65 'Text used to ask for the password at login time.',
69 'Text used to guide the user at login time.',
70 'DISABLE IN PRODUCTION, USE ONLY FOR TEST ' +
71 'Use any username they are all valid, "admin" gives ' +
72 'administrative powers. ' +
73 'Use the fixed password "ipsilon" for any user')
78 return self.get_config_value('help text')
81 def username_text(self):
82 return self.get_config_value('username text')
85 def password_text(self):
86 return self.get_config_value('password text')
88 def get_tree(self, site):
89 self.page = TestAuth(site, self, 'login/testauth')
93 class Installer(LoginManagerInstaller):
95 def __init__(self, *pargs):
96 super(Installer, self).__init__()
97 self.name = 'testauth'
100 def install_args(self, group):
101 group.add_argument('--testauth', choices=['yes', 'no'], default='no',
102 help='Configure PAM authentication')
104 def configure(self, opts, changes):
105 if opts['testauth'] != 'yes':
108 logging.debug(self.pargs)
109 # Add configuration data to database
110 po = PluginObject(*self.pargs)
114 # Update global config to add login plugin
116 po.save_enabled_state()