Example #1
0
    def login(email, password):
        """Tries to log in a user

        Args:
            email_or_username: obvi.
            password: plaintext plaintext password

        Returns:
            User object if login succeeded
            False if login failed
        """
        ret = False
        bcrypt = Bcrypt()
        user = User.find_by_email(email)
        if user and bcrypt.check_password_hash(user.password, password):
            ret = user
        return ret
Example #2
0
import os.path
import platform
import urllib2
import urlparse
from pprint import pprint

import cssmin
from jinja2 import Environment, FileSystemLoader
from fabric.colors import *
from fabric.api import *
from fabric.contrib.console import *
from fabric.contrib.files import *
from fabric.utils import *

from flaskext.bcrypt import Bcrypt
bcrypt = Bcrypt()
"""
    fabfile

    Heavily inspired by: https://github.com/samuelclay/NewsBlur/blob/master/fabfile.py
"""


# ==============
# Color Printing
# ==============
def pblue(s, bold=False):
    puts(blue(s, bold))


def pcyan(s, bold=False):
Example #3
0
from contextlib import closing
from random import shuffle
from flask import Flask, render_template, request, redirect, g, session, flash
from flaskext.bcrypt import Bcrypt
from access_db import *

#configs
DEBUG = True
SECRET_KEY = "placeholder"

database = 'quizgame.db'
schema = 'schema.sql'
csv = 'quiz_questions.csv'

app = Flask(__name__)
bcrypt = Bcrypt(app)
app.config.from_object(__name__)

def get_questions(n, ordered=False):
    question_nums = get_question_nums()
    if not ordered:
        shuffle(question_nums)
    questions = []
    for i in range(n):
        question = get_question(question_nums[i])
        questions.append(question)
    return questions

@app.before_request
def before_request():
    g.db = connect_db()
Example #4
0
def create_app(app_name, config_obj, with_api=True):
    """ Generates and configures the main shop application. All additional """
    # Launching application
    app = Flask(app_name)  # So the engine would recognize the root package

    # Load Configuration
    app.config.from_object(config_obj)

    # Loading assets
    assets = Environment(app)
    assets.from_yaml('assets.yaml')
    app.assets = assets

    # Initialize Mail
    app.mail = Mail(app)

    # Initializing login manager
    login_manager = LoginManager()
    login_manager.login_view = app.config.get('LOGIN_VIEW', 'main.index')
    # login_manager.login_message = 'You need to be logged in to access this page'
    login_manager.session_protection = 'strong'
    login_manager.setup_app(app)
    app.login_manager = login_manager

    # Initializing principal manager
    app.principal = Principal(app)

    # Initializing bcrypt password encryption
    bcrypt = Bcrypt(app)
    app.bcrypt = bcrypt

    # Initializing Database
    db = SQLAlchemy(app)
    app.db = db

    # Initializing Migrate
    migrate = Migrate(app, db, "from fitted.models import *")
    app.migrate = migrate

    photos = UploadSet('photos', IMAGES)
    archives = UploadSet('archives', ARCHIVES)

    configure_uploads(app, (photos, archives))

    patch_request_class(app,
                        2 * 1024 * 1024)  # Patches to 2MB file uploads max.

    app.photos = photos
    app.archives = archives

    # Integrate Elasticsearch

    es_config = app.config.get("ES_CONFIG", [])

    app.es = Elasticsearch(es_config)

    # Integrate sms with Twilio
    app.sms = TwilioRestClient(app.config.get("TWILIO_API_SID"),
                               app.config.get("TWILIO_API_TOKEN"))

    # Redis store for session management
    # The process running Flask needs write access to this directory:
    # store = RedisStore(redis.StrictRedis())

    # # this will replace the app's session handling
    # KVSessionExtension(store, app)

    # configure sentry
    # if not app.config.get("DEBUG", False):
    # 	sentry = Sentry(app)

    # 	app.sentry = sentry

    # inject celery into the app
    app.celery = make_celery(app)

    # injecting mongodb support
    # app.mongo = PyMongo(app)

    # flask s3 integration
    app.s3 = FlaskS3(app)

    # Facebook & Twitter Integration
    app.facebook = oauth.remote_app('facebook', app_key='FACEBOOK')

    oauth.init_app(app)

    # Initializing the restful API
    if with_api:
        api = restful.Api(app, prefix='/api/v1')
        app.api = api

    # Initialize Logging
    if not app.debug:
        import logging
        from logging.handlers import RotatingFileHandler
        file_handler = RotatingFileHandler(
            "/var/log/fitted/%s.log" %
            app.config.get("LOGFILE_NAME", app_name),
            maxBytes=500 * 1024)
        file_handler.setLevel(logging.WARNING)
        from logging import Formatter
        file_handler.setFormatter(
            Formatter('%(asctime)s %(levelname)s: %(message)s '
                      '[in %(pathname)s:%(lineno)d]'))
        app.logger.addHandler(file_handler)

    #include an api_registry to the application
    app.api_registry = []  #a simple list holding the values to be registered

    return app
Example #5
0
from flask.ext.login import (LoginManager, current_user, login_required,
                             login_user, logout_user, UserMixin, AnonymousUser,
                             confirm_login, fresh_login_required)

# Library
from flaskext.bcrypt import Bcrypt

#custom user library - maps User object to User model
from libs.user import *

app = Flask(__name__)
app.debug = True
app.secret_key = os.environ.get('SECRET_KEY')  # SECRET_KEY=...... inside .env

# Flask BCrypt will be used to salt the user password
flask_bcrypt = Bcrypt(app)

#mongolab connection
# uses .env file to get connection string
# using a remote db get connection string from heroku config
# 	using a local mongodb put this in .env
#   MONGOLAB_URI=mongodb://localhost:27017/dwdfall2012
mongoengine.connect('userdemo', host=os.environ.get('MONGOLAB_URI'))

# Login management defined
# reference http://packages.python.org/Flask-Login/#configuring-your-application
login_manager = LoginManager()
login_manager.anonymous_user = Anonymous
login_manager.login_view = "login"
login_manager.login_message = u"Please log in to access this page."
login_manager.refresh_view = "reauth"
Example #6
0
from flask import Flask, render_template, url_for, redirect

from flaskext.bcrypt import Bcrypt
from flask.ext.login import logout_user, login_required

from hat.views import LoginView, RegisterView, IndexView, TagView, APIView
from hat.objects import db, login_manager

app = Flask(__name__)
app.config.from_object('config.Config')

Bcrypt(app)

db.init_app(app)
login_manager.init_app(app)

IndexView.register(app)
LoginView.register(app)
RegisterView.register(app)
TagView.register(app)
APIView.register(app)


@app.route("/logout")
@login_required
def logout():
    logout_user()
    return redirect('/')


if __name__ == '__main__':
Example #7
0
 def passwd(self, value=None):
     bcrypt = Bcrypt()
     password = bcrypt.generate_password_hash(value)
     self.password = password