]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Don't let non-residents create new users.
authorEvan Broder <broder@mit.edu>
Thu, 25 Feb 2010 04:17:27 +0000 (23:17 -0500)
committerEvan Broder <broder@mit.edu>
Thu, 25 Feb 2010 04:22:12 +0000 (23:22 -0500)
bluechips/controllers/user.py
bluechips/lib/permissions.py

index 8fff3c8efa3ec92b5faa6015a80475966200a1c0..e06a8d99e38abb307d0cf41299ab1e8715bfb61c 100644 (file)
@@ -5,10 +5,13 @@ Calculate the current state of the books
 import logging
 
 from bluechips.lib.base import *
+from bluechips.lib.permissions import BlueChipResident
 
 import sqlalchemy
 from sqlalchemy import orm
 
+from authkit.authorize.pylons_adaptors import authorize
+
 from pylons import request
 from pylons.decorators import validate
 from pylons.decorators.secure import authenticate_form
@@ -70,11 +73,13 @@ class UserController(BaseController):
             h.flash("Updated email address to '%s'." % new_email)
         return h.redirect_to('/')
 
+    @authorize(BlueChipResident())
     def new(self):
         c.title = 'Register a New User'
         return render('/user/new.mako')
 
     @authenticate_form
+    @authorize(BlueChipResident())
     @validate(schema=NewUserSchema(), form='new')
     def create(self):
         u = model.User(username=self.form_result['username'],
index 75429eae20d9024dd973a3a5598fa7d1caab40f7..2249726b8a554e264e79632e4b03654f130625ef 100644 (file)
@@ -20,6 +20,16 @@ class BlueChipUser(RequestPermission):
             raise NotAuthorizedError('You are not allowed access.') # pragma: nocover
         return app(environ, start_response)
 
+class BlueChipResident(RequestPermission):
+    def check(self, app, environ, start_response):
+        if 'user' not in environ:
+            raise NotAuthenticatedError('Not Authenticated')
+
+        if not getattr(environ['user'], 'resident', False):
+            raise NotAuthorizedError('You are not allowed access.')
+
+        return app(environ, start_response)
+
 class DummyAuthenticate(AddDictToEnviron):
     """
     Set the authkit.authenticate environment variable so