bottle.TEMPLATES.clear() logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG) log = logging.getLogger(__name__) bottle.debug(True) # Use users.json and roles.json in the local example_conf directory #aaa = Cork('/home/cwags/cwagswebforms/example_conf', email_sender='*****@*****.**', smtp_url='startttls://[email protected]:[email protected]:587') #should make it use sqlite from cork.backends import SQLiteBackend sb = SQLiteBackend('cwags.sqlite') aaa = Cork(backend=sb) # alias the authorization decorator with defaults authorize = aaa.make_auth_decorator(fail_redirect="/login", role="user") import datetime app = bottle.app() 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, } app = SessionMiddleware(app, session_opts) # # Bottle methods # #
from beaker.middleware import SessionMiddleware from cork import Cork import logging logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG) log = logging.getLogger(__name__) bottle.debug(True) # Use users.json and roles.json in the local example_conf directory aaa = Cork('example_conf', email_sender='*****@*****.**', smtp_url='smtp://smtp.magnet.ie') # alias the authorization decorator with defaults authorize = aaa.make_auth_decorator(fail_redirect="/login", role="user") import datetime app = bottle.app() 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, } app = SessionMiddleware(app, session_opts) # # Bottle methods # #
Description: Authentication and Authorization for the Codebits digital signage system, modeled on the Cork sample app. """ import bottle, logging from cork import Cork from config import settings log = logging.getLogger() base_url = settings.http.base_url # Use users.json and roles.json in the local 'etc' directory aaa = Cork('etc', email_sender='*****@*****.**', smtp_server='127.0.0.1') authorize = aaa.make_auth_decorator(fail_redirect=base_url+'/auth/unauthorized') def auth(fail_redirect=base_url+'/auth/login'): """Decorator for wrapping a route into a simple authentication test""" def _auth(f): def _inner(*args, **kwargs): aaa.require(fail_redirect=fail_redirect) return f(*args, **kwargs) return _inner return _auth """ Authentication handlers """
from cork import Cork from beaker.middleware import SessionMiddleware file_path = './test' session_opts = { 'session.cookie_expires': False, 'session.encrypt_key': 'bpvSpCLaswxnSwmCifsEnnWIGXtqTiaUWhjIIkrNeplDqsaBIF', 'session.httponly': True, 'session.type': 'cookie', 'session.validate_key': True } cork = Cork('authconf') auth = cork.make_auth_decorator(fail_redirect='/login', role='admin') app = SessionMiddleware(make_app(), session_opts) file = Path(file_path) file.touch() with file.open(newline='') as f: text = f.read() filesep = ([sep for sep in ['\r\n', '\r', '\n'] if sep in text] + [linesep])[0] @get('/login') def login_form(): return template('login')
from bottle import request, post, get, HTTPError, HTTPResponse, hook from cork import Cork import eu.softfire.tub.exceptions.exceptions as exceptions from eu.softfire.tub.core import CoreManagers from eu.softfire.tub.core.CoreManagers import get_resources_dict, Experiment, \ get_experiment_dict, add_resource, get_other_resources from eu.softfire.tub.core.calendar import CalendarManager from eu.softfire.tub.core.certificate import CertificateGenerator, log_certificate_create from eu.softfire.tub.utils.static_config import CONFIGURATION_FOLDER from eu.softfire.tub.utils.utils import get_config, get_logger logger = get_logger('eu.softfire.tub.api') bottle.TEMPLATE_PATH = [get_config('api', 'view-path', '/etc/softfire/views')] aaa = Cork(get_config("api", "cork-files-path", "/etc/softfire/users")) authorize = aaa.make_auth_decorator(fail_redirect="/login") create_user_thread = None create_user_thread_pool = Pool(20) @hook('after_request') def maintenance(): try: if request.environ.get( 'bottle.raw_path' ) == '/login' or aaa.current_user.role == 'admin': return except: return if CoreManagers.maintenance: raise HTTPResponse(
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 dbe = init_db() aaa = Cork(backend=dbe) authorize = aaa.make_auth_decorator(fail_redirect='/login', role='admin') session_opts = { 'session.cookie_expires': True, 'session.encrypt_key': str(uuid.uuid4()), 'session.httponly': True, 'session.timeout': 86400, # 24 hours 'session.type': 'cookie', 'session.validate_key': False, } app = SessionMiddleware(bottle.app(), session_opts) def whoami(): try:
Description: Authentication and Authorization for the Codebits digital signage system, modeled on the Cork sample app. """ import bottle, logging from cork import Cork from config import settings log = logging.getLogger() base_url = settings.http.base_url # Use users.json and roles.json in the local 'etc' directory aaa = Cork('etc', email_sender='*****@*****.**', smtp_server='127.0.0.1') authorize = aaa.make_auth_decorator(fail_redirect=base_url + '/auth/unauthorized') def auth(fail_redirect=base_url + '/auth/login'): """Decorator for wrapping a route into a simple authentication test""" def _auth(f): def _inner(*args, **kwargs): aaa.require(fail_redirect=fail_redirect) return f(*args, **kwargs) return _inner return _auth