示例#1
0
def login_check(username=None, password=None):
    user = db_session.query(User).filter(User.username == username,
                                         User.status == 1)

    if user.count() == 1:
        pw_hash = user[0].password

        try:
            if Argon2().check_password_hash(pw_hash, password):
                return user[0]
            else:
                return False
        except Exception as e:
            return False
    else:
        return False
示例#2
0
def create_app(config_var=os.getenv('DEPLOY_ENV', 'Development')):
    # init application
    app = Flask(__name__)
    app.config.from_object('pxf.config.%sConfig' % config_var)

    # configure logger
    configure_logger(app)

    # configure argon2
    app.argon2 = Argon2(app)

    # init bootstrap
    bootstrap.init_app(app)

    # init database
    db.init_app(app)
    _module_dir = os.path.dirname(os.path.abspath(__file__))
    migrate.init_app(app,
                     db,
                     directory=os.path.join(_module_dir, '..',
                                            'migrations'))  # noqa

    # init flask principal
    Principal(app)

    # configure login manager
    login_manager.init_app(app)
    setup_login_manager()

    # register Blueprints
    from pxf.views.common import bp_common
    app.register_blueprint(bp_common)
    from pxf.views.websites import bp_websites
    app.register_blueprint(bp_websites)
    from pxf.views.site import bp_site, forbidden, internal_server_error, not_found  # noqa
    app.register_blueprint(bp_site)
    app.register_error_handler(Forbidden.code, forbidden)
    app.register_error_handler(InternalServerError.code, internal_server_error)
    app.register_error_handler(NotFound.code, not_found)

    return app
def create_app(config_var=os.getenv('DEPLOY_ENV', 'Development')):
    app = Flask(__name__)
    app.config.from_object('lem.config.%sConfig' % config_var)
    app.config['DEPLOY_ENV'] = config_var

    configure_logger(app)

    app.argon2 = Argon2(app)
    bootstrap.init_app(app)

    login_manager.init_app(app)
    setup_login_manager()

    Principal(app)

    db.init_app(app)

    _module_dir = os.path.dirname(os.path.abspath(__file__))
    migrate.init_app(app, db, directory=os.path.join(_module_dir, '..', 'migrations'))

    register_blueprints_and_error_handling(app)

    return app
示例#4
0
basedir = os.path.abspath(os.path.dirname(__file__))
"""
extension.py
Declares extension for Flask App, connects with already existing database
"""
# specifying engine according to existing db
load_dotenv(".flaskenv")
try:
    engine = create_engine(os.environ.get('DATABASE_URI'),
                           convert_unicode=True,
                           echo=False,
                           pool_size=20,
                           max_overflow=0,
                           pool_pre_ping=True)
    Base = declarative_base()
    Base.metadata.reflect(engine)
except sqlalchemy.exc.OperationalError:
    engine = create_engine('sqlite:///' + os.path.join(basedir, 'openml.db'),
                           echo=False,
                           convert_unicode=True)
    Config.SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(
        basedir, 'openml.db')
    Base = declarative_base()
    Base.metadata.reflect(engine)

argon2 = Argon2()
db = SQLAlchemy()
jwt = JWTManager()
bcrypt = Bcrypt()
示例#5
0
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
app.config.update(
    TESTING=True,
    SQLALCHEMY_DATABASE_URI='postgresql://cashreq@localhost/casreq',
    SECRET_KEY='g6DGM5y2bVhb0mxdCRELI5m7fnzzoJ2y',
    SQLALCHEMY_TRACK_MODIFICATIONS=False,
    SEND_FILE_MAX_AGE_DEFAULT=1296000,
)
app.jinja_env.lstrip_blocks = True
app.jinja_env.trim_blocks = True

COMPRESS_MIMETYPES = [
    'text/html', 'text/css', 'text/xml', 'application/json',
    'application/javascript'
]
COMPRESS_LEVEL = 6
COMPRESS_MIN_SIZE = 500
Compress(app)

db = SQLAlchemy(app)
migrate = Migrate(app, db)
argon2 = Argon2(app)

# Login
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = "login"
login_manager.login_message_category = "warning"
示例#6
0
from flask_sqlalchemy import SQLAlchemy
from flask_argon2 import Argon2
from flask_login import LoginManager
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
from flask_login import current_user
from config import Config
from flask_migrate import Migrate

app = Flask(__name__)

app.config.from_object(Config)

db = SQLAlchemy(app)
migrate = Migrate(app,db)
argon2 = Argon2(app,hash_len =20)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'


class BlogModelView(ModelView):

    def is_accessible(self):
        return current_user.is_authenticated
    
    def inaccessible_callback(self,name,**kwargs):
        return redirect(url_for('login',next=request.url))


from blog.models import User, Post
示例#7
0
from flask import Flask
from flask_argon2 import Argon2
from flask_mongoengine import MongoEngine

appAHQ = Flask(__name__, template_folder='templates')
argon2 = Argon2(appAHQ)

# test 是链接的数据库
appAHQ.config['MONGODB_SETTINGS'] = {'db': 'test'}
# app.config['MONGODB_DB'] = 'test'
# app.config['MONGODB_HOST'] = '127.0.0.1'
# app.config['MONGODB_PORT'] = 27017
# app.config['MONGODB_USERNAME'] = '******'
# app.config['MONGODB_PASSWORD'] = '******'

# 实例化
db = MongoEngine(appAHQ)

from app import routes
 def setUp(self):
     app = flask.Flask(__name__)
     self.argon2 = Argon2(app)
 def setUp(self):
     app = flask.Flask(__name__)
     self.argon2 = Argon2(app, parallelism=3)
示例#10
0
from Auth import auth_rest_endpoint, auth_socket, Auth
from User import User
from Text import Text
from ParsingRequest import ParsingRequest

from Database import init_db, db_session

import time
import json

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
app.config["SQLALCHEMY_DATABASE_URI"]="sqlite:////tmp/test.db"

sockets = Sockets(app)
Argon = Argon2(app)
init_db()

@app.route("/register", methods=['POST'])
def register():
    body = request.get_json()
    if body is None:
        return Response(status=400)
    user = body.get('username')
    passwd = body.get('password')
    if user is None or passwd is None:
        return Response(status=400)
    u = User(user,passwd)
    
    db_session.add(u)
    db_session.commit()
示例#11
0
import json
from bson.objectid import ObjectId
from .schema import validate_user_data


class JSONEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, ObjectId):
            return str(o)


main = Blueprint("main", __name__)

main.json_encoder = JSONEncoder

argon_two = Argon2(main)


# Home/Index
@main.route("/", methods=["GET"])
def index():
    return "<h1>We ouchea!</h1>"


# Check if user exists [EXCEPTION HANDLING]
@main.route("/check/<number>", methods=["GET"])
def check_user(number):
    # user_collection = mongo.db.users
    if mongo.db.users.find_one({"number": number}):
        return jsonify({"is_user": True}), 200
    else: