Skip to content

Instantly share code, notes, and snippets.

@loopdream
Last active January 20, 2017 14:06
Show Gist options
  • Save loopdream/6dcf88828f45d209cbb828257b4bb0d9 to your computer and use it in GitHub Desktop.
Save loopdream/6dcf88828f45d209cbb828257b4bb0d9 to your computer and use it in GitHub Desktop.
App engine python script for only letting certain users view a static site build
from google.appengine.api import users
from base import handlers
class RootHandler(handlers.BaseHandler):
def get(self, path):
email = users.get_current_user().email()
is_google = email.endswith('@somedomain.com')
is_rga = email.endswith('@someotherdomain.com')
is_admin = users.is_current_user_admin()
if not any(is_google, is_rga, is_admin):
webapp2.abort(403)
static_dir = os.path.join(os.path.dirname(__file__), 'static')
fp = os.path.join(static_dir, path.rstrip('/'), 'index.html')
if not os.path.exists(fp):
webapp2.abort(404)
with open(fp) as f:
self.response.write(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment