Skip to content

Commit

Permalink
Updated georegistry to latest pylons-authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
invisibleroads committed Nov 16, 2010
1 parent 3744aa8 commit aaa1415
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 249 deletions.
6 changes: 3 additions & 3 deletions .gitignore
@@ -1,4 +1,4 @@
.development.cfg
.production.cfg
*.pyc
data data
production.ini
*.pyc
*.swp
13 changes: 0 additions & 13 deletions default.cfg

This file was deleted.

16 changes: 14 additions & 2 deletions development.ini
@@ -1,5 +1,16 @@
#
# georegistry - Pylons development environment configuration
#
# The %(here)s variable will be replaced with the parent directory of this file
#
[DEFAULT] [DEFAULT]
debug = true debug = true
email_to =
error_email_from = support@example.com
smtp_server = localhost
# smtp_username =
# smtp_password =
# smtp_use_tls = True


[server:main] [server:main]
use = egg:Paste#http use = egg:Paste#http
Expand All @@ -13,8 +24,9 @@ static_files = true
cache_dir = %(here)s/data cache_dir = %(here)s/data
beaker.session.key = georegistry beaker.session.key = georegistry
beaker.session.secret = somesecret beaker.session.secret = somesecret
sqlalchemy.url = postgresql://${username}:${password}@localhost/${name} sqlalchemy.url = sqlite:///%(here)s/development.db
safe_path = %(here)s/.development.cfg # recaptcha.public =
# recaptcha.private =


[loggers] [loggers]
keys = root, routes, georegistry, sqlalchemy keys = root, routes, georegistry, sqlalchemy
Expand Down
40 changes: 6 additions & 34 deletions ez_setup.py
Expand Up @@ -17,6 +17,7 @@
DEFAULT_VERSION = "0.6c9" DEFAULT_VERSION = "0.6c9"
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]



md5_data = { md5_data = {
'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
Expand Down Expand Up @@ -54,10 +55,12 @@
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
} }



import sys, os import sys, os
try: from hashlib import md5 try: from hashlib import md5
except ImportError: from md5 import md5 except ImportError: from md5 import md5



def _validate_md5(egg_name, data): def _validate_md5(egg_name, data):
if egg_name in md5_data: if egg_name in md5_data:
digest = md5(data).hexdigest() digest = md5(data).hexdigest()
Expand All @@ -69,6 +72,7 @@ def _validate_md5(egg_name, data):
sys.exit(2) sys.exit(2)
return data return data



def use_setuptools( def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15 download_delay=15
Expand Down Expand Up @@ -110,6 +114,7 @@ def do_download():
except pkg_resources.DistributionNotFound: except pkg_resources.DistributionNotFound:
return do_download() return do_download()



def download_setuptools( def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay = 15 delay = 15
Expand Down Expand Up @@ -158,40 +163,6 @@ def download_setuptools(
return os.path.realpath(saveto) return os.path.realpath(saveto)






































def main(argv, version=DEFAULT_VERSION): def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall""" """Install or upgrade setuptools and EasyInstall"""
try: try:
Expand Down Expand Up @@ -233,6 +204,7 @@ def main(argv, version=DEFAULT_VERSION):
print "Setuptools version",version,"or greater has been installed." print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'



def update_md5(filenames): def update_md5(filenames):
"""Update our built-in md5 registry""" """Update our built-in md5 registry"""


Expand Down
47 changes: 47 additions & 0 deletions georegistry/config/deployment.ini_tmpl
@@ -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
31 changes: 1 addition & 30 deletions georegistry/config/environment.py
Expand Up @@ -5,10 +5,9 @@
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
# Import system modules # Import system modules
import os import os
import ConfigParser
from sqlalchemy import engine_from_config from sqlalchemy import engine_from_config
# Import custom modules # 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.config.routing import make_map
from georegistry.model import init_model from georegistry.model import init_model


Expand Down Expand Up @@ -38,36 +37,8 @@ def load_environment(global_conf, app_conf):
module_directory=os.path.join(app_conf['cache_dir'], 'templates'), module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', default_filters=['escape'], input_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import 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 # Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.') engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine) init_model(engine)
# Return # Return
return config 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'))
3 changes: 3 additions & 0 deletions georegistry/config/routing.py
Expand Up @@ -2,6 +2,7 @@
# Import pylons modules # Import pylons modules
from routes import Mapper from routes import Mapper



def make_map(config): def make_map(config):
'Create, configure and return the routes mapper' 'Create, configure and return the routes mapper'
# Initialize map # Initialize map
Expand Down Expand Up @@ -31,5 +32,7 @@ def make_map(config):
map.connect('region_index', '/regions.:(responseFormat)', controller='regions', action='index') 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', '/regions/:(countryCode).:(responseFormat)', controller='regions', action='show')
map.connect('region_show_plain', '/regions/:(countryCode)', controller='regions', action='show') map.connect('region_show_plain', '/regions/:(countryCode)', controller='regions', action='show')
# Redirect index
map.redirect('/', '/regions')
# Return # Return
return map return map
50 changes: 50 additions & 0 deletions georegistry/controllers/__init__.py
@@ -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)

0 comments on commit aaa1415

Please sign in to comment.