fixes #1449
codename "he who late imports by default makes everybody's life a misery for no speedup at all"
This commit is contained in:
@@ -8,9 +8,11 @@ License: LGPL v3
|
|||||||
|
|
||||||
Tinkered by Szabolcs Gyuris < szimszo n @ o regpreshaz dot eu>
|
Tinkered by Szabolcs Gyuris < szimszo n @ o regpreshaz dot eu>
|
||||||
"""
|
"""
|
||||||
|
import xml.dom.minidom as dom
|
||||||
|
import xml.parsers.expat as expat
|
||||||
|
|
||||||
from gluon import current, redirect, URL
|
from gluon import current, redirect, URL
|
||||||
|
from gluon._compat import urlopen, to_native
|
||||||
|
|
||||||
class CasAuth(object):
|
class CasAuth(object):
|
||||||
"""
|
"""
|
||||||
@@ -59,7 +61,7 @@ class CasAuth(object):
|
|||||||
# vars commented because of
|
# vars commented because of
|
||||||
# https://code.google.com/p/web2py/issues/detail?id=1774
|
# https://code.google.com/p/web2py/issues/detail?id=1774
|
||||||
self.cas_my_url = URL(args=current.request.args,
|
self.cas_my_url = URL(args=current.request.args,
|
||||||
#vars=current.request.vars,
|
#vars=current.request.vars,
|
||||||
scheme=True)
|
scheme=True)
|
||||||
|
|
||||||
def login_url(self, next="/"):
|
def login_url(self, next="/"):
|
||||||
@@ -86,7 +88,6 @@ class CasAuth(object):
|
|||||||
exposed as CAS.login(request)
|
exposed as CAS.login(request)
|
||||||
returns a token on success, None on failed authentication
|
returns a token on success, None on failed authentication
|
||||||
"""
|
"""
|
||||||
import urllib
|
|
||||||
self.ticket = current.request.vars.ticket
|
self.ticket = current.request.vars.ticket
|
||||||
if not current.request.vars.ticket:
|
if not current.request.vars.ticket:
|
||||||
redirect("%s?service=%s" % (self.cas_login_url,
|
redirect("%s?service=%s" % (self.cas_login_url,
|
||||||
@@ -95,7 +96,7 @@ class CasAuth(object):
|
|||||||
url = "%s?service=%s&ticket=%s" % (self.cas_check_url,
|
url = "%s?service=%s&ticket=%s" % (self.cas_check_url,
|
||||||
self.cas_my_url,
|
self.cas_my_url,
|
||||||
self.ticket)
|
self.ticket)
|
||||||
data = urllib.urlopen(url).read()
|
data = to_native(urlopen(url).read())
|
||||||
if data.startswith('yes') or data.startswith('no'):
|
if data.startswith('yes') or data.startswith('no'):
|
||||||
data = data.split('\n')
|
data = data.split('\n')
|
||||||
if data[0] == 'yes':
|
if data[0] == 'yes':
|
||||||
@@ -108,19 +109,16 @@ class CasAuth(object):
|
|||||||
a = b = c = data[1]
|
a = b = c = data[1]
|
||||||
return dict(user=a, email=b, username=c)
|
return dict(user=a, email=b, username=c)
|
||||||
return None
|
return None
|
||||||
import xml.dom.minidom as dom
|
|
||||||
import xml.parsers.expat as expat
|
|
||||||
try:
|
try:
|
||||||
dxml = dom.parseString(data)
|
dxml = dom.parseString(data)
|
||||||
envelop = dxml.getElementsByTagName(
|
envelop = dxml.getElementsByTagName("cas:authenticationSuccess")
|
||||||
"cas:authenticationSuccess")
|
|
||||||
if len(envelop) > 0:
|
if len(envelop) > 0:
|
||||||
res = dict()
|
res = dict()
|
||||||
for x in envelop[0].childNodes:
|
for x in envelop[0].childNodes:
|
||||||
if x.nodeName.startswith('cas:') and len(x.childNodes):
|
if x.nodeName.startswith('cas:') and len(x.childNodes):
|
||||||
key = x.nodeName[4:].encode('utf8')
|
key = to_native(x.nodeName[4:])
|
||||||
value = x.childNodes[0].nodeValue.encode('utf8')
|
value = to_native(x.childNodes[0].nodeValue)
|
||||||
if not key in res:
|
if key not in res:
|
||||||
res[key] = value
|
res[key] = value
|
||||||
else:
|
else:
|
||||||
if not isinstance(res[key], list):
|
if not isinstance(res[key], list):
|
||||||
@@ -136,5 +134,4 @@ class CasAuth(object):
|
|||||||
exposed CAS.logout()
|
exposed CAS.logout()
|
||||||
redirects to the CAS logout page
|
redirects to the CAS logout page
|
||||||
"""
|
"""
|
||||||
import urllib
|
|
||||||
redirect("%s?service=%s" % (self.cas_logout_url, self.cas_my_url))
|
redirect("%s?service=%s" % (self.cas_logout_url, self.cas_my_url))
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ Contains the classes for the global used variables:
|
|||||||
- Session
|
- Session
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT
|
from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT, long
|
||||||
from gluon.storage import Storage, List
|
from gluon.storage import Storage, List
|
||||||
from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
|
from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
|
||||||
from gluon.contenttype import contenttype
|
from gluon.contenttype import contenttype
|
||||||
|
|||||||
Reference in New Issue
Block a user