Permalink
Browse files

Updated georegistry to latest pylons-authentication

  • Loading branch information...
1 parent 3744aa8 commit aaa1415b57eaf03f9e8cc50f33153edfead975de @invisibleroads committed Nov 16, 2010
View
@@ -1,4 +1,4 @@
-.development.cfg
-.production.cfg
-*.pyc
data
+production.ini
+*.pyc
+*.swp
View
@@ -1,13 +0,0 @@
-[mail support]
-smtp = localhost
-email = support@localhost
-nickname = Support
-
-[recaptcha]
-public =
-private =
-
-[database]
-name =
-username =
-password =
View
@@ -1,5 +1,16 @@
+#
+# georegistry - Pylons development environment configuration
+#
+# The %(here)s variable will be replaced with the parent directory of this file
+#
[DEFAULT]
debug = true
+email_to =
+error_email_from = support@example.com
+smtp_server = localhost
+# smtp_username =
+# smtp_password =
+# smtp_use_tls = True
[server:main]
use = egg:Paste#http
@@ -13,8 +24,9 @@ static_files = true
cache_dir = %(here)s/data
beaker.session.key = georegistry
beaker.session.secret = somesecret
-sqlalchemy.url = postgresql://${username}:${password}@localhost/${name}
-safe_path = %(here)s/.development.cfg
+sqlalchemy.url = sqlite:///%(here)s/development.db
+# recaptcha.public =
+# recaptcha.private =
[loggers]
keys = root, routes, georegistry, sqlalchemy
View
@@ -17,6 +17,7 @@
DEFAULT_VERSION = "0.6c9"
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
+
md5_data = {
'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
@@ -54,10 +55,12 @@
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
}
+
import sys, os
try: from hashlib import md5
except ImportError: from md5 import md5
+
def _validate_md5(egg_name, data):
if egg_name in md5_data:
digest = md5(data).hexdigest()
@@ -69,6 +72,7 @@ def _validate_md5(egg_name, data):
sys.exit(2)
return data
+
def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15
@@ -110,6 +114,7 @@ def do_download():
except pkg_resources.DistributionNotFound:
return do_download()
+
def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay = 15
@@ -158,40 +163,6 @@ def download_setuptools(
return os.path.realpath(saveto)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
try:
@@ -233,6 +204,7 @@ def main(argv, version=DEFAULT_VERSION):
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
+
def update_md5(filenames):
"""Update our built-in md5 registry"""
@@ -0,0 +1,47 @@
+#
+# georegistry - Pylons configuration
+#
+# The %(here)s variable will be replaced with the parent directory of this file
+#
+[DEFAULT]
+debug = false
+email_to =
+error_email_from = support@example.com
+smtp_server = localhost
+# smtp_username =
+# smtp_password =
+# smtp_use_tls = True
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 5000
+
+[app:main]
+use = egg:georegistry
+full_stack = true
+static_files = true
+cache_dir = %(here)s/data
+app_instance_uuid = ${app_instance_uuid}
+beaker.session.key = georegistry
+beaker.session.secret = ${app_instance_secret}
+sqlalchemy.url = sqlite:///production.db
+# recaptcha.public =
+# recaptcha.private =
+
+[loggers]
+keys = root
+[handlers]
+keys = console
+[formatters]
+keys = generic
+[logger_root]
+level = WARN
+handlers = console
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s] [%(threadName)s] %(message)s
@@ -5,10 +5,9 @@
from mako.lookup import TemplateLookup
# Import system modules
import os
-import ConfigParser
from sqlalchemy import engine_from_config
# Import custom modules
-from georegistry.lib import app_globals, helpers, store
+from georegistry.lib import app_globals, helpers
from georegistry.config.routing import make_map
from georegistry.model import init_model
@@ -38,36 +37,8 @@ def load_environment(global_conf, app_conf):
module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import escape'])
- # Load safe
- config['safe'] = loadSafe(config['safe_path'])
- config['sqlalchemy.url'] = patchSQLAlchemyURL(config['sqlalchemy.url'], config['safe'])
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
# Return
return config
-
-
-def loadSafe(safePath):
- 'Load information that we do not want to include in the repository'
- # Validate
- if not os.path.exists(safePath):
- print 'Missing configuration: ' + safePath
- safePath = store.expandBasePath('default.cfg')
- # Initialize
- valueByName = {}
- # Load
- configuration = ConfigParser.ConfigParser()
- configuration.read(safePath)
- for sectionName in configuration.sections():
- valueByName[sectionName] = dict(configuration.items(sectionName))
- # Return
- return valueByName
-
-
-def patchSQLAlchemyURL(sqlalchemyURL, safe):
- 'Apply sensitive credentials'
- # Define
- getDBParameter = lambda x: safe['database'][x]
- # Return
- return sqlalchemyURL.replace('${username}', getDBParameter('username')).replace('${password}', getDBParameter('password')).replace('${name}', getDBParameter('name'))
@@ -2,6 +2,7 @@
# Import pylons modules
from routes import Mapper
+
def make_map(config):
'Create, configure and return the routes mapper'
# Initialize map
@@ -31,5 +32,7 @@ def make_map(config):
map.connect('region_index', '/regions.:(responseFormat)', controller='regions', action='index')
map.connect('region_show', '/regions/:(countryCode).:(responseFormat)', controller='regions', action='show')
map.connect('region_show_plain', '/regions/:(countryCode)', controller='regions', action='show')
+ # Redirect index
+ map.redirect('/', '/regions')
# Return
return map
@@ -0,0 +1,50 @@
+'General decorators'
+# Import pylons modules
+from pylons import request, url
+from pylons.controllers.util import redirect
+# Import system modules
+from decorator import decorator
+# Import custom modules
+from georegistry.lib import helpers as h
+
+
+# Authentication
+
+@decorator
+def requireLogin(func, *args, **kwargs):
+ 'Redirect to login if the user is not logged in'
+ # If the user is not logged in,
+ if not h.isPerson():
+ return redirect(url('person_login', targetURL=h.encodeURL(request.path)))
+ # Execute
+ return func(*args, **kwargs)
+
+@decorator
+def requireLoginJSON(func, *args, **kwargs):
+ 'Give error message if the user is not logged in'
+ # If the user is not logged in,
+ if not h.isPerson():
+ return dict(isOk=0, message='Login required')
+ # Execute
+ return func(*args, **kwargs)
+
+
+# Authorization
+
+@decorator
+def requireSuper(func, *args, **kwargs):
+ 'Redirect to homepage if the user is not a superuser'
+ # If the user is not a superuser,
+ if not h.isPersonSuper():
+ return redirect(url('person_login', targetURL=h.encodeURL('/')))
+ # Execute
+ return func(*args, **kwargs)
+
+@decorator
+def requireSuperJSON(func, *args, **kwargs):
+ 'Give error message if the user is not a superuser'
+ # If the user is not a superuser,
+ if not h.isPersonSuper():
+ return dict(isOk=0, message='Access denied')
+ # Execute
+ return func(*args, **kwargs)
Oops, something went wrong.

0 comments on commit aaa1415

Please sign in to comment.