Пример #1
0
def get_app(config):
    app = Flask(__name__)

    app.config.from_object(config)
    mail.init_app(app)
    RQ(app)
    csrf = CsrfProtect(app)
    csrf.exempt(api_1_0_blueprint)

    stream_handler = logging.StreamHandler()
    app.logger.setLevel(logging.DEBUG)
    app.logger.addHandler(stream_handler)

    db.init_app(app)
    Migrate(app, db)
    bootstrap = Bootstrap(app)
    security = Security(app, user_datastore)
    user_registered.connect(user_registered_sighandler)

    app.register_blueprint(ratings_blueprint)
    app.register_blueprint(api_1_0_blueprint, url_prefix="/api/v1")
    app.register_blueprint(verify_blueprint, url_prefix="/v")
    app.register_blueprint(tournament_blueprint, url_prefix="/tournament")
    app.register_error_handler(500, email_exception)

    return app
Пример #2
0
def get_app(config):
    app = Flask(__name__)

    app.config.from_object(config)
    mail.init_app(app)
    RQ(app)
    csrf = CsrfProtect(app)
    csrf.exempt(api_1_0_blueprint)

    stream_handler = logging.StreamHandler()
    app.logger.setLevel(logging.DEBUG)
    app.logger.addHandler(stream_handler)

    db.init_app(app)
    Migrate(app, db)
    bootstrap = Bootstrap(app)
    security = Security(app, user_datastore)
    user_registered.connect(user_registered_sighandler)

    app.register_blueprint(ratings_blueprint)
    app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1')
    app.register_blueprint(verify_blueprint, url_prefix='/v')
    app.register_blueprint(tournament_blueprint, url_prefix='/tournament')
    app.register_error_handler(500, email_exception)

    return app
Пример #3
0
def get_app(config):
    app = Flask(__name__)

    app.config.from_object(config)
    mail.init_app(app)
    RQ(app)
    csrf = CsrfProtect(app)
    csrf.exempt(api_1_0_blueprint)

    stream_handler = logging.StreamHandler()
    if app.debug:
        stream_handler.setLevel(logging.INFO)
    else:
        stream_handler.setLevel(logging.WARN)
    app.logger.addHandler(stream_handler)

    db.init_app(app)
    bootstrap = Bootstrap(app)
    security = Security(app, user_datastore)
    user_registered.connect(user_registered_sighandler)


    app.register_blueprint(ratings_blueprint)
    app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1')
    app.register_blueprint(verify_blueprint, url_prefix='/v')

    return app
Пример #4
0
def register_with_app(app):
    add_config(app)

    security, blueprint = create_security(app)

    register_principal(app, security)

    login_provider.add_views(app, blueprint)

    # TODO: move the 'site_url' value to config file
    security.mail_context_processor(lambda: dict(site_url='https://slide-atlas.org/'))

    # TODO: make logins timeout
    #   may use the 'flask.ext.login.user_loaded_from_*' signals for this, to update the timeout
    #   furthermore, see the documentation 'flask.ext.login.needs_refresh', and implement re-login
    #   redirection directly to the user's corresponding login provider if a user's session becomes stale

    user_registered.connect(on_user_registered, app)
Пример #5
0
    add_default_role,
    check_dates,
    safe_send_mail,
)
from art17.auth.forms import DatasetForm, LoginForm
from art17.auth.security import (Art17LocalRegisterForm, Art17LDAPRegisterForm,
                                 Art17AdminEditUserForm, AnonymousUser,
                                 encrypt_password, verify)
from art17.common import HOMEPAGE_VIEW_NAME, get_config


def user_registered_sighandler(app, user, confirm_token):
    add_default_role(user)


user_registered.connect(user_registered_sighandler)


@auth.app_errorhandler(PermissionDenied)
def handle_permission_denied(error):
    html = render_template('auth/permission_denied.html')
    return Response(html, status=403)


@auth.route('/auth/register/local', methods=['GET', 'POST'])
def register_local():
    form = Art17LocalRegisterForm(request.form)

    if form.validate_on_submit():
        register_user(**form.to_dict())
        return render_template('message.html', message="")
Пример #6
0
app = Flask(__name__)
app.config.from_object('config.DebugConfiguration')
mail = Mail(app)

if app.debug:
    import logging
    import sys
    logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO,stream=sys.stderr) 
    app.logger.addHandler(logging.StreamHandler())
    logging.info("set up logging")

db.init_app(app)
bootstrap = Bootstrap(app)

security = Security(app, user_datastore)
user_registered.connect(user_registered_sighandler)

app.register_blueprint(ratings)
app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0')
app.register_blueprint(verify_blueprint, url_prefix='/v')

#TODO: remove the following init function, which destroys any existing app
#database and replaces it with default data
@app.before_first_request
def init_db():
    from .models import create_test_data
    db.drop_all()
    db.create_all()
    create_test_data()
Пример #7
0
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'favicon.ico', mimetype='image/vnd.microsoft.icon')

@app.context_processor
def inject_user():
    return dict(user=current_user)


# noinspection PyUnusedLocal
def new_user_registered(sender, **extra):
    user = extra["user"]
    role = user_datastore.find_role("user")
    user_datastore.add_role_to_user(user, role)


user_registered.connect(new_user_registered, app)


def is_safe_url(target):
    ref_url = urlparse(request.host_url)
    test_url = urlparse(urljoin(request.host_url, target))
    return test_url.scheme in ('http', 'https') and \
           ref_url.netloc == test_url.netloc


def refresh_heads():
    repo.hg_sync()
    Head.query.delete()
    for repo_head in get_heads(repo):
        head = Head(repo_head)
        logger.debug("Adding head: %s", head.title)
Пример #8
0
# Setup MixPanel
from mixpanel import Mixpanel
mp = Mixpanel(app.config["MIXPANEL_TOKEN"])


def mixpanel_register_new_user(sender, user, confirm_token, **extra):
    mp.people_set(
        user.id, {
            '$first_name': user.first_name,
            '$last_name': user.last_name,
            '$email': user.email
        })


user_registered.connect(mixpanel_register_new_user, app)

# @app.context_processor
# def navbar_context_processor():
#     categories = db.session.query(Category).all()
#     return dict(categories=categories)

manager.add_command(
    "runserver",
    Server(use_debugger=True,
           use_reloader=True,
           host=os.getenv('IP', '0.0.0.0'),
           port=int(os.getenv('PORT', 5000))))


@app.route("/")
Пример #9
0
# Setup Stripe
import stripe
stripe.api_key = app.config["STRIPE_API_KEY"]

# Setup MixPanel
from mixpanel import Mixpanel
mp = Mixpanel(app.config["MIXPANEL_TOKEN"])

def mixpanel_register_new_user(sender, user, confirm_token, **extra):
    mp.people_set(user.id, {
        '$first_name': user.first_name,
        '$last_name': user.last_name,
        '$email': user.email
    })

user_registered.connect(mixpanel_register_new_user, app)

# @app.context_processor
# def navbar_context_processor():
#     categories = db.session.query(Category).all()
#     return dict(categories=categories)

manager.add_command("runserver", Server(
    use_debugger = True,
    use_reloader = True,
    host = os.getenv('IP', '0.0.0.0'),
    port = int(os.getenv('PORT',5000))
    )
)

@app.route("/")
Пример #10
0
            for feedback in anonymous_user.feedbacks:
                user.feedbacks.append(feedback)
            # transfer notifications
            for notification in anonymous_user.notifications:
                user.notifications.append(notification)
            # transfer the gcm token
            for gcm_token in anonymous_user.gcm_tokens:
                user.gcm_tokens.append(gcm_token)
            db.session.delete(anonymous_user)
        db.session.commit()

    def __repr__(self):
        return '<User %r>' % self.id


user_registered.connect(User.post_registration_handler)


class GCMToken(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    token = db.Column(db.String)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship("User", backref=db.backref("gcm_tokens"))


class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    message = db.Column(db.String)  # TODO: Deprecated