Пример #1
0
def init_db():
    try:
        b = SQLiteBackend('djparrot.db', initialize=True)
        sql = '''INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES \
('nsavelyeva-admin', 'admin@localhost', 'Administrator', 'admin', \
'cD+Njm6BgJsTVAlSQ3qC4loRBnSUnY5qj6W6h5yzTELk4/qMiaCtg1GFoS9EKDCxrArjwt2AmB7Lh6ds7flfWDY=', \
'2017-12-10 21:20:55.352142');
INSERT INTO roles (role, level) VALUES ('admin', 100);
INSERT INTO roles (role, level) VALUES ('user', 50);'''
        b.connection.executescript(sql)
        b.connection.executescript(get_init_sql())
    except OperationalError:  # e.g. if table users/roles/register already exists
        b = SQLiteBackend('djparrot.db', initialize=False)
    return b
Пример #2
0
def populate_backend():
    b = SQLiteBackend('example.db', initialize=True)
    b.connection.executescript("""
        INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES
        (
            'admin',
            '*****@*****.**',
            'admin test user',
            'admin',
            'cLzRnzbEwehP6ZzTREh3A4MXJyNo+TV8Hs4//EEbPbiDoo+dmNg22f2RJC282aSwgyWv/O6s3h42qrA6iHx8yfw=',
            '2012-10-28 20:50:26.286723'
        );
        INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES
        (
            'user',
            '*****@*****.**',
            'user',
            'user',
            'cLzRnzbEwehP6ZzTREh3A4MXJyNo+TV8Hs4//EEbPbiDoo+dmNg22f2RJC282aSwgyWv/O6s3h42qrA6iHx8yfw=',
            '2012-10-28 20:50:26.286723'
        );
        INSERT INTO roles (role, level) VALUES ('special', 200);
        INSERT INTO roles (role, level) VALUES ('admin', 100);
        INSERT INTO roles (role, level) VALUES ('editor', 60);
        INSERT INTO roles (role, level) VALUES ('user', 50);
    """)
    return b
Пример #3
0
def populate_backend():
    b = SQLiteBackend(os.environ['DBNAME'], initialize=True)
    b.connection.executescript("""
        INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES
        (
            'admin',
            '*****@*****.**',
            '{"key1": "f64ef282-4410-47bb-9ebf-b8719d2a8a19", "key0": "4504dd6b-50ba-11e4-be6f-3c15c2e8aac8", "id": "45033d33-50ba-11e4-8e60-3c15c2e8aac8"}',
            'admin',
            'cLzRnzbEwehP6ZzTREh3A4MXJyNo+TV8Hs4//EEbPbiDoo+dmNg22f2RJC282aSwgyWv/O6s3h42qrA6iHx8yfw=',
            '2012-10-28 20:50:26.286723'
        );
        INSERT INTO roles (role, level) VALUES ('special', 200);
        INSERT INTO roles (role, level) VALUES ('admin', 100);
        INSERT INTO roles (role, level) VALUES ('editor', 60);
        INSERT INTO roles (role, level) VALUES ('user', 50);
    """)
    return b
Пример #4
0
def setup_sqlite_db(request):
    # in-memory SQLite DB using the SQLiteBackend backend module.
    b = SQLiteBackend(':memory:', initialize=True)
    b.connection.executescript("""
        INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES
        (
            'admin',
            '*****@*****.**',
            'admin test user',
            'admin',
            'cLzRnzbEwehP6ZzTREh3A4MXJyNo+TV8Hs4//EEbPbiDoo+dmNg22f2RJC282aSwgyWv/O6s3h42qrA6iHx8yfw=',
            '2012-10-28 20:50:26.286723'
        );
        INSERT INTO roles (role, level) VALUES ('special', 200);
        INSERT INTO roles (role, level) VALUES ('admin', 100);
        INSERT INTO roles (role, level) VALUES ('editor', 60);
        INSERT INTO roles (role, level) VALUES ('user', 50);
    """)
    return b
Пример #5
0
# #  Insert session middleware  # #
def get_session_middleware():
    from beaker.middleware import SessionMiddleware
    session_opts = {
        'session.cookie_expires': True,
        'session.encrypt_key': 'please use a random key and keep it secret!',
        'session.httponly': True,
        'session.timeout': 3600 * 24,  # 1 day
        'session.type': 'cookie',
        'session.validate_key': True,
        }
    return SessionMiddleware(bottle.app(), session_opts)

from cork import Cork
from cork.backends import SQLiteBackend
b = SQLiteBackend(os.environ['DBNAME'])

# not really a monkey patch, more like a kludge.
# just to get auto connect mode.
# ideally the backend driver would do its own transations.
b._connection.isolation_level = None

backend = Cork(backend=b,
               email_sender=os.environ['EMAIL_SENDER'],
               smtp_url=os.environ['SMTP_URL'])

def get_app():
    return get_session_middleware()

Пример #6
0
"""
Routes (Controller) packages.
"""
import os
from cork import Cork
from cork.backends import SQLiteBackend
from utils import make_auth_decorator



__all__ = ['admin', 'account', 'api', 'core']
_base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
_aucf_dir = os.path.join(_base_dir, 'auth_conf')
_audb_dir = os.path.join(_base_dir, 'centrak-uam.db')   # user-authn-mgmt


# authnz
try: backend = SQLiteBackend(_audb_dir, initialize='True')
except: backend = SQLiteBackend(_audb_dir)
    
authnz = Cork(backend=backend)
authorize = make_auth_decorator(
                authnz, role='user',
                fail_unauth_redirect='/login',
                fail_auth_redirect="/restricted")
Пример #7
0
Base = declarative_base()
engine = create_engine('sqlite:///database.db', echo=False)
#engine = create_engine('postgresql://*****:*****@localhost:5432/alisson')
engineWMS = create_engine('oracle://*****:*****@192.168.104.4', echo=False)

###############################################################################
# CONFIGURAÇÔES DO CORK #######################################################
###############################################################################
logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s',
                    level=logging.DEBUG)
log = logging.getLogger(__name__)

app = bottle.app()

b = SQLiteBackend('database.db', initialize=False)


def populate_backend():
    b.connection.executescript("""
        INSERT INTO users (username, email_addr, desc, role, hash, creation_date) VALUES
        (
            'admin',
            '*****@*****.**',
            'admin test user',
            'admin',
            'cLzRnzbEwehP6ZzTREh3A4MXJyNo+TV8Hs4//EEbPbiDoo+dmNg22f2RJC282aSwgyWv/O6s3h42qrA6iHx8yfw=',
            '2012-10-28 20:50:26.286723'
        );
        INSERT INTO roles (role, level) VALUES ('special', 200);
        INSERT INTO roles (role, level) VALUES ('admin', 100);
Пример #8
0
import time
''' Init Path and Python version'''
os.chdir(os.path.dirname(__file__))
appPath = dirname(__file__)
version = platform.python_version()
''' Initialize config'''
if os.path.exists("config/config.py"):
    import config.config as config
else:
    import config.startup as config
''' Initialize translation'''
with open('translations/{lang}.json'.format(lang=config.LANG),
          'r') as read_file:
    translation = json.load(read_file)
''' Initialize authentication'''
aaa = Cork(backend=SQLiteBackend('baby.db'))
authorize = aaa.make_auth_decorator(fail_redirect="/login", role="user")
''' Functions'''


def show_current_user_role():
    session = bottle.request.environ.get('beaker.session')
    if aaa.user_is_anonymous:
        return "anonymous"
    else:
        return aaa.current_user.role


def connect():
    return sqlite3.connect('baby.db')