from flask.ext.bcrypt import Bcrypt from couchbase.n1ql import N1QLQuery from datetime import datetime from app.api_1_0 import blueprint as api # configure according which machine we're running module = __import__('config') configuration = getattr(module, os.getenv('LOCAL_ENV', 'ProductionEnvironment')) # Basic App initialization =============================================== app = Flask(__name__) app.config.from_object(configuration) app.appBucket = Bucket('couchbase://' + app.config['CB_HOST'] + '/' + app.config['CB_APP_BUCKET']) app.userBucket = Bucket('couchbase://' + app.config['CB_HOST'] + '/' + app.config['CB_USERS_BUCKET']) jwt = JWT(app) app.bcrypt = Bcrypt(app) # initialize JWT authentication ====================================== @jwt.authentication_handler def authenticate(username, password): bucket = app.userBucket print '@authentication handler' user = [] try: q = N1QLQuery('SELECT * FROM ' + app.config['CB_USERS_BUCKET'] + ' WHERE username = $user', user=username) results = bucket.n1ql_query(q)