def create_app():
    app = Flask(__name__,
        static_folder=os.path.join(PROJECT_ROOT, 'public'),
        static_url_path='/public')

    app.config.update(os.environ)

    #TODO: read in right hand side from HT config vars
    app.config['SECRET_KEY'] = 'secret'
    app.config['SECURITY_PASSWORD_HASH'] = 'bcrypt'
    app.config['MONGODB_DB'] = 'flask_security_test'
    app.config['MONGODB_HOST'] = 'localhost'
    app.config['MONGODB_PORT'] = 27017

    app.debug = app.config['X_HT_DEBUG'] == "True"

    app.wsgi_app = SharedDataMiddleware(app.wsgi_app, 
        {'/': os.path.join(os.path.dirname(__file__), 'public') })

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.html'), 404

    SecuritySetup(app)

    # import & register blueprints here:
    #===================================
    from hero_tmpl.views.security import security
    app.register_blueprint(security)

    from hero_tmpl.views.misc import misc
    app.register_blueprint(misc)

    return app
def create_app():
    # Create a sample application and go from there
    app = Flask(__name__)
    app.debug = True
    app.secret_key = '1234'
    app.config['MONGODB_DB'] = 'test_mongoutils' 
    app.config['MONGODB_HOST'] = 'localhost' 
    app.config['MONGODB_PORT'] = '27017' 
    db.init_app(app)
    return app
Example #3
0
def create_app(config=None):
    app = Flask("tweet_wall")
    app.config['MONGODB_DB'] = os.getenv('TW_MONGODB_DB')
    app.config['MONGODB_HOST'] = os.getenv('TW_MONGODB_HOST')

    db.init_app(app)

    app.jinja_env.filters['twitter_normal_to_bigger'] = twitter_normal_to_bigger

    token = read_bearer_token_file(".oauth2_bearer_token")
    twitter = Twitter(auth=OAuth2(bearer_token=token))

    @app.route("/approved")
    @app.route("/index")
    @app.route("/")
    def approved_tweets():
        tweets = model.Tweet.objects(approved=True).order_by("-id_str").all()
        return render_template('public.html', tweets=tweets)

    @app.route("/approve", methods=["GET"])
    @requires_auth
    def approve_tweet_get():
        hash_tag = _get_hash_tag_query_param()
        tweets_twitter = twitter.search.tweets(q=hash_tag)["statuses"]

        tweets_local = model.Tweet.objects(approved=True).all()
        tweets_local_ids = [tweet.id_str for tweet in tweets_local]

        tweets_not_approved = [tweet for tweet in tweets_twitter
                               if tweet["id_str"] not in tweets_local_ids]

        return render_template('approve_tweets.html',
                               tweets=tweets_not_approved)

    @app.route("/approve/<string:id_str>", methods=["POST"])
    @requires_auth
    def approve_tweet_post(id_str):
        tweet = twitter.statuses.show(id=id_str)
        tweet["approved"] = True
        tweet.pop("id")
        model.Tweet.objects(id_str=tweet["id_str"]).update_one(upsert=True,
                                                               **tweet)
        return redirect(url_for('approve_tweet_get'))

    @app.route("/twitter")
    def tweets():
        hash_tag = _get_hash_tag_query_param()
        tweet_search = twitter.search.tweets(q=hash_tag)["statuses"]
        return render_template('public.html', tweets=tweet_search)

    return app
def create_app(db_interface, app_name='testapp', db_name='__test-db__'):
    app = Flask(app_name)
    app.config['SERVER_NAME'] = 'localhost:5000'

    if db_interface == 'pymongo':
        app.config['MONGO_DBNAME'] = db_name
        mongo = PyMongo(app)
        with app.app_context():
            app.session_interface = MongoDBSessionInterface(
                app, mongo.db, 'sessions')
    elif db_interface == 'mongoengine':
        app.config['MONGODB_DB'] = db_name
        mongo = MongoEngine(app)
        app.session_interface = MongoDBSessionInterface(
            app, mongo.connection[app.config['MONGODB_DB']], 'sessions')

    @app.route("/set")
    def set_session():
        session['data'] = request.args['d']
        return 'data'

    @app.route("/setpermanent")
    def set_permanent_session():
        session.permanent = True
        session['data'] = request.args['d']
        return 'data'

    @app.route("/get")
    def get_session():
        return session.get('data', '')

    @app.route("/unicode/set")
    def unicode_set():
        session['foo'] = u'Alpenerstra\xdfe'
        return 'done'

    @app.route("/unicode/get")
    def unicode_get():
        return session['foo']

    return app
Example #5
0
def create_app(config_name):
    app = Flask(__name__)
    app.config['MONGODB_DB'] = os.environ.get('DB_NAME', 'semcomp')
    app.config['MONGODB_HOST'] = os.environ.get('DB_HOST', 'localhost')
    app.config['MONGODB_PORT'] = int(os.environ.get('DB_PORT', 27017))
    app.config['MONGODB_USERNAME'] = os.environ.get('DB_USER', '')
    app.config['MONGODB_PASSWORD'] = os.environ.get('DB_PASS', '')

    db.init_app(app)

    app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

    from .main import main as main_blueprint
    from .api import api as api_blueprint
    app.register_blueprint(main_blueprint)
    app.register_blueprint(api_blueprint)

    api_rest = Api(app, prefix='/api')

    # adicionar rotas
    from .api import routes
    routes.route_all_resources(api_rest)

    return app
from flask import Flask, request, render_template
from flask_mongoengine import MongoEngine
from flask_mongoengine import Document

from mongoengine.fields import StringField, IntField

chars = string.digits + string.ascii_letters
iter_thing = itertools.combinations_with_replacement(chars, r=32)

# Determining the project root.
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))

# Creating the Flask app object
app = Flask(__name__, static_folder=os.path.join(PROJECT_ROOT, 'static'), static_url_path='/max_sucks')
app.config['DEBUG'] = True
app.config['MONGODB_DB'] = 'hashes'


db = MongoEngine(app)

def jump_to_next_block():
    num_to_jump = 50000000
    return next(itertools.islice(iter_thing, num_to_jump, num_to_jump), None)

class Submission(Document):
    original = StringField(max_length=1024, required=True)
    diff_bits = IntField(required=True)
    submitted_by = StringField(max_length=2048, required=False, default='')


@app.route('/')
Example #7
0
from flask import Flask, render_template, request, flash, redirect, jsonify
from mongoengine import *
import random
import os

app = Flask(__name__)

connect_string = os.environ['MONGODB_CONNECT_STRING']
db_name = os.environ['db']
secret_key = os.environ['secret']

connect(host=connect_string)
app.config['MONGODB_DB'] = db_name
app.config['SECRET_KEY'] = secret_key

class Users(Document):
    name = StringField(unique=True)
    date = StringField()
    aadhar_number = IntField()
    voter_id = IntField(unique=True)


@app.route("/", methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return render_template("index.html")
    elif request.method == 'POST':
        form = request.json
        user = Users()
        user.name = request.form['name']
        user.aadhar_number = request.form['aadhar']
Example #8
0
from flask import Flask
from flask.ext.admin import Admin
from flask.ext.principal import Principal
from flask_admin_material import setup_templates
from flask.ext.mongoengine import MongoEngine

app = Flask(__name__)
try:
    app.config.from_pyfile('../instance/config.py')
except:
    print 'Unable to load ../instance/config.py'
    print 'Searching for OpenShift environment variables...'
    if os.environ.has_key('OPENSHIFT_APP_NAME'):
        print 'Detected app: %s. Loading configuration variables...' % os.environ.get('OPENSHIFT_APP_NAME')
        app.config['SECRET_KEY'] = 'abcdef'
    
        app.config['MONGODB_DB'] = os.environ.get('OPENSHIFT_APP_NAME')
        app.config['MONGODB_HOST'] = os.environ.get('OPENSHIFT_MONGODB_DB_HOST')
        app.config['MONGODB_PORT'] = os.environ.get('OPENSHIFT_MONGODB_DB_PORT', 0)
        app.config['MONGODB_USERNAME'] = os.environ.get('OPENSHIFT_MONGODB_DB_USERNAME')
        app.config['MONGODB_PASSWORD'] = os.environ.get('OPENSHIFT_MONGODB_DB_PASSWORD')
        
        app.config['DEBUG'] = False
    else:
        print 'No OpenShift app detected. Attempt to run with default config.'

db = MongoEngine()
db.init_app(app)

app = setup_templates(app)
Example #9
0
import glob
from datetime import datetime, timedelta
from flask import Flask, json, abort, render_template, request
from flask.ext.mongoengine import MongoEngine
from flask.ext.security import Security, MongoEngineUserDatastore, \
    UserMixin, RoleMixin, login_required, core
from flask.ext.script import Manager, Server, prompt, prompt_pass

app = Flask(__name__, static_folder='frontend/app', static_url_path='/static')
app.debug = os.getenv('DEBUG')
app.config["MONGODB_SETTINGS"] = {'DB': "proj", 'HOST': '10.254.1.122'}
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'

# MongoDB Config
app.config['MONGODB_DB'] = 'proj'
app.config['MONGODB_HOST'] = '10.254.1.122'
app.config['MONGODB_PORT'] = 27017

# Flask-Security
app.config['SECURITY_REGISTERABLE'] = True

db = MongoEngine(app)

class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)

class User(db.Document, UserMixin):
    email = db.StringField(max_length=255)
    password = db.StringField(max_length=255)
Example #10
0
from flask import Flask
from flask.ext.mongoengine import MongoEngine
import os

app = Flask(__name__)

app.config['MONGODB_DB'] = os.getenv('MONGODB_DB', "openzhhk1")
app.config['MONGODB_HOST'] = os.getenv('MONGODB_HOST', "localhost")
app.config['MONGODB_PORT'] = int(os.getenv('MONGODB_PORT', "27017"))
app.config['MONGODB_USERNAME'] = os.getenv('MONGODB_USERNAME', "")
app.config['MONGODB_PASSWORD'] = os.getenv('MONGODB_PASSWORD', "")
app.config["SECRET_KEY"] = os.getenv('SECRET_KEY', "KeepThisS3cr3t")

db = MongoEngine(app)

true_values = ["true", "True", "1", "on", "On"]


def register_blueprints(app):
    # Prevents circular imports
    from openzhhk.views import views
    from openzhhk.api import api_bp
    app.register_blueprint(views)
    app.register_blueprint(api_bp)

register_blueprints(app)

if __name__ == '__main__':
    app.run()
Example #11
0
# import all modules
import datetime
from flask import Flask, jsonify, abort, \
        make_response, request, url_for, render_template
from flask.ext.httpauth import HTTPBasicAuth
from flask.ext.mongoengine import MongoEngine

#create app
app = Flask(__name__)

#create verification
auth = HTTPBasicAuth()

#mongodb config
app.config['MONGODB_DB'] = 'tasks'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017
#replcase with your own secretkey
#os.urandom(24)
app.config['SECRET_KEY'] = '\xfb\xf7\x00T'

#create database connection object
db = MongoEngine(app)

#create models
class Task(db.Document):
    title = db.StringField(required=True, unique=True)
    description = db.StringField(required=True)
    done = db.BooleanField(default=False)
import os

from flask import Flask
app = Flask(__name__)
app.config.from_object('config')

from mongoengine import connect
from flask.ext.mongoengine import MongoEngine

#Connect to the DB
app.config['MONGODB_DB'] = os.environ.get('DB_NAME') or app.config['DB_NAME']

#For Heroku MongoHQ Add-On
if os.environ.get('MONGOHQ_URL'):
    connect(app.config['DB_NAME'], host=os.environ.get('MONGOHQ_URL'))
else:
    connect(app.config['DB_NAME'], host='mongodb://' + app.config['DB_USERNAME'] + ':' + app.config['DB_PASSWORD'] + '@' + app.config['DB_HOST_ADDRESS'])
db = MongoEngine(app)

#login/openid
from flask.ext.login import LoginManager
from flask.ext.openid import OpenID
from config import basedir

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
oid = OpenID(app, os.path.join(basedir, 'tmp'))

#email support
from flask.ext.mail import Mail
Example #13
0
# CONFIG
#------------------------------------------------

app = Flask(__name__)
app.config['SECRET_KEY'] = '\x1a\xc7\xdf\x92\xf7~\xe5u\xf0\xa7_\xf0\xbf")\xc9\xb8K\xd5,\x88\xef\x8f\xb4'


#------------------------------------------------
# DB
#------------------------------------------------

DB_NAME = '4dgres'
DB_USERNAME = 'cpdugenio'
DB_PASSWORD = 'asian1'
DB_HOST_ADDRESS = 'ds035280.mongolab.com:35280/4dgres'
app.config['MONGODB_DB'] = DB_NAME
connect(DB_NAME, host='mongodb://' + DB_USERNAME + ':' + DB_PASSWORD + '@' + DB_HOST_ADDRESS)
db = MongoEngine(app)


#------------------------------------------------
# MODELS
#------------------------------------------------
from models.word import Word


#------------------------------------------------
# CONTROLLS
#------------------------------------------------

Example #14
0
import auth
from auth import urls as auth_urls

from base import urls as base_urls
from base.templatetags import ttags

from feud import urls as feud_urls

# Determining the project root.
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))

app = Flask(__name__, static_folder=os.path.join(PROJECT_ROOT, 'static'), static_url_path='/static')

auth.initialize(app)

app.config['MONGODB_DB'] = 'wfeud'
app.config['SECRET_KEY'] = 'my_super_secret_key'

# Setting up the connection to the MongoDB backend.
db = MongoEngine(app)

#Define URLs
base_urls.setup_urls(app)
auth_urls.setup_urls(app)
feud_urls.setup_urls(app)

#Setup other things
ttags.setup_jinja2_environment(app)


from socketio import socketio_manage
Example #15
0
def create_app(object_name, env="prod"):
    """
    A flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Inputs:  ::\n
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['ENV'] = env
    
    # Init the cache
    cache.init_app(app)

    # Init debug toolbar
    debug_toolbar.init_app(app)

    # Init Mongo engine
    # mongoengine.connect(config.MONGODB_FRONTEND_DB_NAME, host=config.MONGODB_HOST, port=config.MONGODB_PORT)
    app.config['MONGODB_DB'] = config.MONGODB_FRONTEND_DB_NAME
    app.config['MONGODB_HOST'] = config.MONGODB_HOST
    app.config['MONGODB_PORT'] = config.MONGODB_PORT
    db.init_app(app)

    # Init login_manager
    login_manager.init_app(app)
    login_manager.login_view = "main.login"
    login_manager.refresh_view = "main.login"
    # Init current to track current project/experiment
    current.init_app(app)
    
    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register all the  blueprints
    from controllers import (
        main,
        error,
        dashboard,
        new_experiment,
        new_project,
        account_settings,
        project,
        experiment,
        targets,
        setup,
    )
    
    app.register_blueprint(main)
    app.register_blueprint(error,url_prefix="/error")
    app.register_blueprint(dashboard,url_prefix="/dashboard")
    app.register_blueprint(new_experiment,url_prefix="/new_experiment")
    app.register_blueprint(new_project,url_prefix="/new_project")
    app.register_blueprint(account_settings,url_prefix="/account_settings")
    app.register_blueprint(project,url_prefix="/project")
    app.register_blueprint(experiment,url_prefix="/experiment")
    app.register_blueprint(targets,url_prefix="/targets")
    app.register_blueprint(setup,url_prefix="/setup")


    return app
Example #16
0
def create_app(testing=False, live=False):
    from bhs_api.models import User, Role
    from bhs_api.forms import LoginForm

    app = Flask(__name__)
    app.testing = testing

    # load the config file
    conf = get_conf()
    app.conf = conf
    # Our config - need to move everything here
    app.config['VIDEO_BUCKET_URL'] = "https://storage.googleapis.com/bhs-movies"
    app.config['IMAGE_BUCKET_URL'] = "https://storage.googleapis.com/bhs-flat-pics"

    # Set app config
    app.config['DEBUG'] = True
    app.config['FRONTEND_SERVER'] = conf.frontend_server
    app.config['DEFAULT_NEXT'] = '/mjs'
    # Security Config
    app.config['SECRET_KEY'] = conf.secret_key
    app.config['WTF_CSRF_ENABLED'] = False
    app.config['SECURITY_PASSWORDLESS'] = True
    app.config['SECURITY_EMAIL_SENDER'] = 'BH Databases<support@bh.org.il>'
    app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = 'email'
    app.config['SECURITY_EMAIL_SUBJECT_PASSWORDLESS'] = 'Login link for Your Jewish Story'
    app.config['SECURITY_POST_LOGIN_VIEW'] = '/mjs'
    app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = ('email', 'username', 'hash')
    # Mail Config
    app.config['MAIL_SERVER'] = conf.mail_server
    app.config['MAIL_PORT'] = conf.mail_port
    # Mail optional username and password
    try:
        app.config['MAIL_USERNAME'] = conf.mail_username
        app.config['MAIL_PASSWORD'] = conf.mail_password
    except AttributeError:
        pass

    # DB Config
    app.config['MONGODB_DB'] = conf.user_db_name
    app.config['MONGODB_HOST'] = conf.user_db_host
    app.config['MONGODB_PORT'] = conf.user_db_port
    # Redis
    app.config['REDIS_HOST'] = conf.redis_host
    app.config['REDIS_PORT'] = conf.redis_port
    app.config['REDIS_PASSWORD'] = getattr(conf, 'redis_password', None)

    # CACHING
    app.config['CACHING_TTL'] = conf.caching_ttl

    app.mail = Mail(app)
    app.db = MongoEngine(app)
    app.user_datastore = MongoEngineUserDatastore(app.db, User, Role)
    app.security = Security(app, app.user_datastore,
                            passwordless_login_form=LoginForm)
    # Create database connection object
    app.client_data_db = pymongo.MongoClient(conf.data_db_host, conf.data_db_port,
                    read_preference=pymongo.ReadPreference.SECONDARY_PREFERRED)
    app.data_db = app.client_data_db[conf.data_db_name]

    # Create the elasticsearch connection
    app.es = elasticsearch.Elasticsearch(conf.elasticsearch_host)
    app.es_data_db_index_name = getattr(conf, "elasticsearch_data_index", app.data_db.name)

    # Add the user's endpoints
    from bhs_api.user import user_endpoints
    app.register_blueprint(user_endpoints)
    # Add the v1 endpoint
    from bhs_api.v1_endpoints import v1_endpoints
    app.register_blueprint(v1_endpoints, url_prefix='/v1')
    # Initialize autodoc - https://github.com/acoomans/flask-autodoc
    #allow CORS
    cors = CORS(app, origins=['*'], headers=['content-type', 'accept',
                                            'authentication-token', 'Authorization'])
    # logging
    if live:
        app.config['PROPAGATE_EXCEPTIONS'] = True
        try:
            fh = logging.FileHandler(conf.log_file)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            fh.setFormatter(formatter)
            app.logger.addHandler(fh)
        except AttributeError:
            pass

    # redis
    try:
        app.redis = redis.StrictRedis(host=conf.redis_host,
                                      port=conf.redis_port,
                                      password = app.config['REDIS_PASSWORD'],
                                      db=0)
    except AttributeError:
        app.redis = None

    return app, conf
Example #17
0
from flask import Flask, render_template, request, redirect, flash, \
     url_for, session, escape
from yahoo_finance import Share
from mongoengine import connect
import models, time
from forms import LoginForm, RegisterForm
from flask.ext.mail import Message, Mail

mail = Mail()

app = Flask(__name__);

# secret key is needed for forms(csrf)
app.config['SECRET_KEY'] = 's3cr3t'
# Database to use for mongoDB
app.config['MONGODB_DB'] = 'finance'
app.debug = False
connect(''' Removed for security reasons ''')
app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = #removed for security reasons
app.config["MAIL_PASSWORD"] = #removed for security reasons

mail.init_app(app)


@app.route("/")
def index():
    if 'username' in session:
        return redirect('portfolio')
Example #18
0
from flask import Flask
from flask.ext.mongoengine import MongoEngine

# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'My_bl0g_keY'

# MongoDB Config
app.config['MONGODB_DB'] = 'blog'
app.config['MONGODB_HOST'] = 'localhost'
#app.config['MONGODB_PORT'] = 27017

db = MongoEngine(app)

def add_views():
    # Avoid cyclic include
    from blog import views

def add_api():
    from blog import api

add_views()
add_api()
Example #19
0
# -*- coding: utf-8 -*-

from flask import Flask
from flask.ext.mongoengine import MongoEngine
from micawber import bootstrap_basic

# Create app
app = Flask(__name__)

# MongoDB Config
app.config['MONGODB_DB'] = 'notes'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017
app.config['SECRET_KEY'] = 'Ny\xf23`\xeaY\xd8gk\xc6\xa7\xbc\xa8\x14L-\xed\xa3\xc0\x84#\xc0\x80`'

# Create database connection object
db = MongoEngine(app)

oembed = bootstrap_basic()

if __name__ == '__main__':
    app.run()
Example #20
0
import redis
from collections import defaultdict
import os
from forms import LoginForm
from flask.ext.mongoengine import MongoEngine
from flask.ext.security import Security, MongoEngineUserDatastore, \
    UserMixin, RoleMixin, login_required

app = Flask(__name__)
app.debug = True
app.config.from_object('config')
redis_url = os.getenv('REDISTOGO_URL', 'localhost')
r_server = redis.from_url(redis_url)

# MongoDB Config
app.config['MONGODB_DB'] = 'default'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017

# Create database connection object
db = MongoEngine(app)

class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)

class User(db.Document, UserMixin):
    email = db.StringField(max_length=255)
    password = db.StringField(max_length=255)
    active = db.BooleanField(default=True)
    confirmed_at = db.DateTimeField()
Example #21
0
from flask import Flask, render_template
from flask.ext.mongoengine import MongoEngine
from flask.ext.security import Security, MongoEngineUserDatastore, \
    UserMixin, RoleMixin, login_required

# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret-1pocosegura'

# MongoDB Config
app.config['MONGODB_DB']       = 'evepytest'
app.config['MONGODB_HOST']     = 'ds051615.mlab.com'
app.config['MONGODB_PORT']     =  51615
app.config['MONGODB_USERNAME'] = 'usertest'
app.config['MONGODB_PASSWORD'] = 'evepytest'


# Create database connection object
db = MongoEngine(app)

class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)

class User(db.Document, UserMixin):
    email = db.StringField(max_length=255)
    password = db.StringField(max_length=255)
    active = db.BooleanField(default=True)
    confirmed_at = db.DateTimeField()
    roles = db.ListField(db.ReferenceField(Role), default=[])
Example #22
0
from mongoengine import *
from flask.ext.mongoengine import MongoEngine
from flask.ext.security import Security, MongoEngineUserDatastore, \
    UserMixin, RoleMixin, login_required , AnonymousUser

from flask.ext.login import *
from flask_mail import Mail

app = Flask(__name__,template_folder=template_folder,static_folder=static_folder)

app.app_context().push()

app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.config["MONGODB_HOST"] = MONGODB_HOST
app.config['MONGODB_DB'] = MONGODB_DB
app.config['MONGODB_PORT'] = MONGODB_PORT


"""
The following section sets the overall configuration for flask-security
"""
app.config['SECURITY_PASSWORD_HASH'] = SECURITY_PASSWORD_HASH
app.config['SECURITY_PASSWORD_SALT'] = SECURITY_PASSWORD_SALT
app.config['SECURITY_CONFIRM_SALT'] = SECURITY_CONFIRM_SALT
app.config['SECURITY_RESET_SALT'] = SECURITY_RESET_SALT
app.config['SECURITY_CONFIRMABLE'] = True
app.config['SECURITY_RECOVERABLE'] = True
app.config['SECURITY_CHANGEABLE']  = SECURITY_CHANGEABLE

Example #23
0
    )

# overriding default jinja template tags, to avoid conflicts with angularjs
app.jinja_env.variable_start_string = '{['
app.jinja_env.variable_end_string = ']}'

app.config['SECRET_KEY'] = os.environ['SECRET_KEY']

#allow debugging heroku code
if os.environ.get('DEBUG'):
    app.config['DEBUG'] = True

#create the db connection, username and password only set if it exists
if os.environ.get('ENV', 'dev') == 'pro':
    app.config['MONGODB_HOST'] = os.environ.get('MONGOLAB_URI')
    app.config['MONGODB_DB'] = 'final'
else:
    app.config['MONGODB_USERNAME'] = os.environ.get('MONGO_DB_USERNAME')
    app.config['MONGODB_PASSWORD'] = os.environ.get('MONGO_DB_PASSWORD')
    app.config['MONGODB_DB'] = 'test'

db = MongoEngine(app)

app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

#set up login manager
login_manager = LoginManager()
login_manager.init_app(app)

#set url to redirect to for login
login_manager.login_view = 'signin'
Example #24
0
@babel.localeselector
def get_locale():
    return 'ru'

app.config['MAIL_SERVER'] = dotenv.get(
    'KNOTMARKER_MAIL_SERVER', 'smtp.gmail.com')
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = dotenv.get(
    'KNOTMARKER_MAIL_USERNAME', 'knotmarker@gmail.com')
app.config['MAIL_PASSWORD'] = dotenv.get('KNOTMARKER_MAIL_PASSWORD')

mail = Mail(app)

app.config['MONGODB_DB'] = dotenv.get('KNOTMARKER_MONGODB_DB', 'knotmarker')
app.config['MONGODB_HOST'] = dotenv.get('KNOTMARKER_MONGODB_HOST', 'localhost')
app.config['MONGODB_PORT'] = dotenv.get('KNOTMARKER_MONGODB_PORT', 27017)
app.config["SECRET_KEY"] = bytes(dotenv.get('KNOTMARKER_SECRET_KEY'), 'utf8')
app.config["SECURITY_REGISTERABLE"] = True
app.config["SECURITY_CONFIRMABLE"] = True
app.config["SECURITY_RECOVERABLE"] = True
app.config["SECURITY_CHANGEABLE"] = True
app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512'
app.config['SECURITY_PASSWORD_SALT'] = bytes(dotenv.get('KNOTMARKER_PASSWORD_SALT'), 'utf8')

SENTRY_DSN = dotenv.get('KNOTMARKER_SENTRY_DSN', None)

if SENTRY_DSN:
    from raven.contrib.flask import Sentry
    app.config['SENTRY_USER_ATTRS'] = ['email']
Example #25
0
from datetime import datetime
import hashlib
import random
import uuid

__author__ = "Prahlad Yeri"
__version__ = "1.2"

app = Flask(__name__, static_url_path='', static_folder='static')
#app = Flask(__name__)


app.config['UPLOAD_FOLDER'] = 'upload'
app.config['ALLOWED_EXTENSIONS'] = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app.config['MONGODB_DB'] = 'valchemist'
app.config['MONGODB_HOST'] = 'localhost'

app.config['SECRET_KEY'] = 'l33tN3rdz'

db.init_app(app)

user_datastore = MongoEngineUserDatastore(db, User, Role)
security = Security(app, user_datastore)



@app.route("/")
def home():

    return render_template('index.html')
Example #26
0
from DmpWorkflow.config.defaults import cfg
from DmpWorkflow import version
from socket import getfqdn
kind = cfg.get("global", "installation")

if kind == 'server':    
    
    from flask import Flask
    from flask.ext.mongoengine import MongoEngine
    app = Flask(__name__)
    app.config.update(LOGGER_NAME="core")
    app.config['MONGODB_DB'] = cfg.get("database", "name")
    app.config['MONGODB_USERNAME'] = cfg.get("database", "user")
    app.config['MONGODB_PASSWORD'] = cfg.get("database", "password")
    app.config['MONGODB_HOST'] = cfg.get("database", "host")
    app.config['MONGODB_PORT'] = int(cfg.get("database", "port"))
    app.config["SECRET_KEY"] = "KeepThisS3cr3t"
    db = MongoEngine(app)
    
    def register_blueprints(app):
        # Prevents circular imports
        from DmpWorkflow.core.views import jobs
        from DmpWorkflow.core.admin import admin
        app.register_blueprint(jobs)
        app.register_blueprint(admin)
    

    register_blueprints(app)
    
    def main():
        app.logger.info("started DmpWorkflow Server Version: %s on %s",version,getfqdn())
Example #27
0
from flask import Flask
from flask_mongoengine import MongoEngine
from mongoengine import StringField, IntField

from flask_potion import Api, ModelResource, fields
from flask.ext.potion.contrib.mongoengine.manager import MongoEngineManager

app = Flask(__name__)
app.debug = True
app.config['MONGODB_DB'] = 'potion-example'

me = MongoEngine(app)

class Book(me.Document):
    title = StringField(null=False, unique=True)
    year_published = IntField(null=True)


class BookResource(ModelResource):
    class Meta:
        name = 'book'
        model = Book

    class Schema:
        year_published = fields.Integer(minimum=1400)


api = Api(app, default_manager=MongoEngineManager)
api.add_resource(BookResource)

if __name__ == '__main__':
Example #28
0
else:
	host = 'localhost'

if "MONGODB_PORT" in os.environ:
	app.config['MONGODB_PORT'] = os.environ['MONGODB_PORT']
else:
	port = 27017

if "MONGODB_USERNAME" in os.environ:
	app.config['MONGODB_USERNAME'] = os.environ['MONGODB_USERNAME']


if "MONGODB_PASSWORD" in os.environ:
	app.config['MONGODB_PASSWORD'] = os.environ['MONGODB_PASSWORD']

app.config['MONGODB_DB'] = 'lculpa'



# Create database connection object
db = MongoEngine(app)

# Review Object
class Review(db.Document):
    name = db.StringField(required=True)
    department = db.StringField(required=True)
    classes = db.StringField(required=True)
    summary = db.StringField(required=True)
    workload = db.StringField(required=True)
    date = db.StringField(required=True)
Example #29
0
MONGO_URL = os.environ.get("MONGOHQ_URL")

if MONGO_URL:
    credentials = re.sub(r"(.*?)//(.*?)(@hatch)", r"\2",MONGO_URL)
    username = credentials.split(":")[0]
    password = credentials.split(":")[1]
    app.config["MONGODB_DB"] = MONGO_URL.split("/")[-1]
    connect(
        MONGO_URL.split("/")[-1],
        host=MONGO_URL,
        port=1043,
        username=username,
        password=password
    )
else:
    app.config['MONGODB_DB'] = os.environ['DB_NAME']
    app.config['MONGODB_HOST'] = os.environ['DB_HOST']
    app.config['MONGODB_PORT'] = os.environ['DB_PORT']  # 27017

app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_SEND_REGISTER_EMAIL'] = False
app.config['SECURITY_PASSWORD_HASH'] = 'sha512_crypt'
app.config['SECURITY_PASSWORD_SALT'] = os.environ['SALT']

db = MongoEngine(app)

class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)

class User(db.Document, UserMixin):
Example #30
0
import json

from flask.ext.security.decorators import _get_unauthorized_response
from functools import wraps
from hashlib import sha256
from os import urandom

from mongoengine import *

# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'

# MongoDB Config
app.config['MONGODB_DB'] = 'ff_ui'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017
app.config['WTF_CSRF_ENABLED'] = False

sslify = SSLify(app)


API_PATHS = {
  'routines' : 'http://localhost:6001/API/views/routine',
  'mode' : 'http://localhost:6001/API/mode',
  'device_vews' : 'http://localhost:6001/API/views/devices',
  'all_device_status' : 'http://localhost:6001/API/status/devices/all'
}