Ejemplo n.º 1
0
    def __init__(self, app):
        self.app = app
        self.login_manager = flask_login.LoginManager()
        self.login_manager.init_app(app)

        self.guard = flask_praetorian.Praetorian()
        self.guard.init_app(app, User)
Ejemplo n.º 2
0
 def test_basic(self, app, db, mixin_user_class, user_class, default_guard):
     mixin_guard = flask_praetorian.Praetorian(app, mixin_user_class)
     the_dude = mixin_user_class(
         username="******",
         password=mixin_guard.hash_password("abides"),
     )
     db.session.add(the_dude)
     db.session.commit()
     assert mixin_guard.authenticate("TheDude", "abides") == the_dude
     with pytest.raises(flask_praetorian.exceptions.AuthenticationError):
         mixin_guard.authenticate("TheBro", "abides")
     with pytest.raises(flask_praetorian.exceptions.AuthenticationError):
         mixin_guard.authenticate("TheDude", "is_undudelike")
     db.session.delete(the_dude)
     db.session.commit()
     default_guard.init_app(app, user_class)
Ejemplo n.º 3
0
import os
import flask
import flask_sqlalchemy
import flask_praetorian
import flask_cors

db = flask_sqlalchemy.SQLAlchemy()
guard = flask_praetorian.Praetorian()
cors = flask_cors.CORS()


# A generic user model that might be used by an app powered by flask-praetorian
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text, unique=True)
    password = db.Column(db.Text)
    roles = db.Column(db.Text)
    is_active = db.Column(db.Boolean, default=True, server_default='true')

    @property
    def rolenames(self):
        try:
            return self.roles.split(',')
        except Exception:
            return []

    @classmethod
    def lookup(cls, username):
        return cls.query.filter_by(username=username).one_or_none()

    @classmethod
Ejemplo n.º 4
0
from sqlalchemy import desc, asc

from app.models import *
from flask_rest_api import Blueprint, abort, Page
from app.schemes import *
from app.config import Config
from flask import Flask, jsonify

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

db.init_app(app)
db.create_all(app=app)
api.init_app(app)

guard = flask_praetorian.Praetorian(app, User)

category_blp = Blueprint(
    'categories',
    'categories',
    url_prefix='/categories',
    description='Get categories list or create category(subcategory)')
product_blp = Blueprint('products',
                        'products',
                        url_prefix='/products',
                        description='Get products list or create product')
user_blp = Blueprint('users',
                     'users',
                     url_prefix='',
                     description='Register user or auth(get token)')
Ejemplo n.º 5
0
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail

from flask_sqlalchemy.model import DefaultMeta, Model
from sqlalchemy.ext.declarative import declarative_base, declared_attr

import flask_praetorian
import logging

db = SQLAlchemy(model_class=Model)
mail = Mail()
auth = flask_praetorian.Praetorian()
logger = logging.getLogger()
Ejemplo n.º 6
0
file_path = op.join(op.dirname(__file__), "static/images")

try:
    os.mkdir(file_path)
except OSError:
    pass

app = Flask(__name__, static_folder="static")
app.config.from_pyfile("../instance/config.py")

cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
csrf = CSRFProtect(app)
csrf.init_app(app)
api = Api(app, decorators=[csrf.exempt])
guard = fprae.Praetorian()
db = SQLAlchemy(app)
migrate = Migrate(app, db, compare_type=True)
ma = Marshmallow(app)
login_manager = LoginManager(app)
login_manager.init_app(app)
photos = UploadSet("photos", IMAGES)
configure_uploads(app, photos)
patch_request_class(app)

from app import admin_views

admin = Admin(app,
              name="Flask Web",
              template_mode="bootstrap3",
              index_view=admin_views.MyAdminIndexView(name='Resumen'),