from MealParser import makeMessageResponse app = Flask(__name__) SECRET_KEY = "secret secret" app.config.from_object(__name__) if os.environ.get('MONGOLAB_URI', None): #we are in heroku, act accordingly app.config['mongodb_uri'] = os.environ['MONGOLAB_URI'] print "the mongodb uri is %s" % app.config['mongodb_uri'] client = MongoClient(app.config['mongodb_uri']) db = client['heroku_app15804168'] oa = OlinAuth(app, 'txt2helpme.herokuapp.com') oa.init_app(app, 'txt2helpme.herokuapp.com') else: #we are local, debug mode. app.config['mongodb_uri'] = 'mongodb://localhost/txt2helpme' #set db uri client = MongoClient(app.config['mongodb_uri']) db = client['txt2helpme'] oa = OlinAuth(app, 'localhost:5000') oa.init_app(app, 'localhost:5000') try: db.authenticate("app", "root") except: db.logout() db.authenticate("app", "root") collection = db.txt2helpme
authentication protocol. :copyright: (C) 2013 by Cory Dolphin. :license: MIT/X11, see LICENSE for more details. """ from flask import Flask, url_for from flask.ext.olinauth import OlinAuth, auth_required, current_user app = Flask(__name__) SECRET_KEY = "yeah, not actually a secret" DEBUG = True app.config.from_object(__name__) oa = OlinAuth(app, 'localhost:5000') #initial OlinAuth, with callback host of localhost:5000, for local server oa.init_app(app, 'localhost:5000') @app.route("/") def index(): # this view is public, does not require authentication if current_user: # if a user is logged in and authenticated responseString = "Awesome index, guess what? %s is logged in. Sweet,\ right? <a href=%s> Logout</a>" % (current_user['id'], url_for('__logout')) else: responseString = "<html>It is kind of lonely here... No users are logged in. <a href=%s>Checkout my secret</a> </html>" % url_for('secret') return responseString @app.route("/secret") @auth_required def secret(): # this view requires authentication, and will redirect if not.
from MealParser import makeMessageResponse app=Flask(__name__) SECRET_KEY = "secret secret" app.config.from_object(__name__) if os.environ.get('MONGOLAB_URI',None): #we are in heroku, act accordingly app.config['mongodb_uri'] = os.environ['MONGOLAB_URI'] print "the mongodb uri is %s" % app.config['mongodb_uri'] client = MongoClient(app.config['mongodb_uri']) db = client['heroku_app15804168'] oa = OlinAuth(app,'txt2helpme.herokuapp.com') oa.init_app(app,'txt2helpme.herokuapp.com') else: #we are local, debug mode. app.config['mongodb_uri'] = 'mongodb://localhost/txt2helpme' #set db uri client = MongoClient(app.config['mongodb_uri']) db = client['txt2helpme'] oa = OlinAuth(app,'localhost:5000') oa.init_app(app,'localhost:5000') try: db.authenticate("app","root") except: db.logout() db.authenticate("app","root") collection = db.txt2helpme