def getHtml(self, request): # doAutoLogin = Config.section('IPAUTH').value('autoLogin', '0').getBool() ip = self.getIp() gm = GroupsManager(self.dbAuthenticator()) self.getGroups(ip, gm) if gm.hasValidGroups() and self.dbAuthenticator().isValidUser(ip, True): passw = '' return '<script type="text/javascript">$("#id_user").val("' + ip + '");$("#id_password").val("' + passw + '");$("#loginform").submit();</script>' else: return '<div>Invalid auth (' + ip + ')</div><script type="text/javascript">$("#backToLogin").click()</script>'
def recreateGroups(self, user): ''' Helper method, not needed to be overriden. It simply checks if the source is external and if so, recreates the user groups for storing them at database. user param is a database user object ''' if self.isExternalSource == True: groupsManager = GroupsManager(self._dbAuth) self.getGroups(user.name, groupsManager) user.groups = [g.dbGroup() for g in groupsManager.getValidGroups()]
def getJavascript(self, request): # doAutoLogin = Config.section('IPAUTH').value('autoLogin', '0').getBool() ip = self.getIp() gm = GroupsManager(self.dbAuthenticator()) self.getGroups(ip, gm) if gm.hasValidGroups() and self.dbAuthenticator().isValidUser( ip, True): return '''function setVal(element, value) {{ document.getElementById(element).value = value; }} setVal("id_user", "{ip}"); setVal("id_password", "{passwd}"); document.getElementById("loginform").submit();'''.format( ip=ip, passwd='') return 'alert("invalid authhenticator"); window.location.reload();'