auth.login_expiration_time = 3600 auth.password_complexity = {"entropy": 50} auth.block_previous_password_num = 3 auth.define_tables() if settings.SMTP_SERVER: auth.sender = Mailer( server=settings.SMTP_SERVER, sender=settings.SMTP_SENDER, login=settings.SMTP_LOGIN, tls=settings.SMTP_TLS, ssl=settings.SMTP_SSL, ) if auth.db: groups = Tags(db.auth_user, "groups") if settings.USE_PAM: from py4web.utils.auth_plugins.pam_plugin import PamPlugin auth.register_plugin(PamPlugin()) if settings.USE_LDAP: from py4web.utils.auth_plugins.ldap_plugin import LDAPPlugin auth.register_plugin( LDAPPlugin(db=db, groups=groups, **settings.LDAP_SETTINGS)) if settings.OAUTH2GOOGLE_CLIENT_ID: from py4web.utils.auth_plugins.oauth2google import OAuth2Google # TESTED
elif settings.SESSION_TYPE == 'memcache': import memcache, time conn = memcache.Client(settings.MEMCACHE_CLIENTS, debug=0) session = Session(secret=settings.SESSION_SECRET_KEY, storage=conn) elif settings.SESSION_TYPE == 'database': from py4web.utils.dbstore import DBStore session = Session(secret=settings.SESSION_SECRET_KEY, storage=DBStore(db)) auth = Auth(session, db, registration_requires_confirmation=False, password_complexity=False, use_username=False) if auth.db: groups = Tags(db.auth_user, 'groups') if settings.USE_PAM: from py4web.utils.auth_plugins.pam_plugin import PamPlugin auth.register_plugin(PamPlugin()) if settings.USE_LDAP: from py4web.utils.auth_plugins.ldap_plugin import LDAPPlugin auth.register_plugin(LDAPPlugin(**settings.LDAP_SETTINGS)) if settings.OAUTH2GOOGLE_CLIENT_ID: from py4web.utils.auth_plugins.oauth2google import OAuth2Google # TESTED auth.register_plugin( OAuth2Google(client_id=settings.OAUTH2GOOGLE_CLIENT_ID, client_secret=settings.OAUTH2GOOGLE_CLIENT_SECRET, callback_url='auth/plugin/oauth2google/callback'))
from py4web import action, request, response, abort, redirect, URL, Field, HTTP from py4web.utils.form import Form, FormStyleBulma from py4web.utils.url_signer import URLSigner from py4web.utils.tags import Tags from yatl.helpers import A from .common import db, session, T, cache, auth, signed_url from apps.identitea.fixtures import Admin_Check from .components.fileupload import FileUpload from gevent import monkey monkey.patch_all() import gevent from bottle import route, run url_signer = URLSigner(session) groups = Tags(db.auth_user) admin_check = Admin_Check(auth, db, groups) common_fixtures = [session, db, url_signer] admin_fixtures = common_fixtures + [auth.user, admin_check] user = None # The auth.user below forces login. @action('index') @action.uses('index.html', *common_fixtures) def index(): return dict(get_slides=URL("admin_getslides", signer=url_signer), )
def test_tags(self): db = DAL("sqlite:memory") db.define_table("thing", Field("name")) properties = Tags(db.thing) id1 = db.thing.insert(name="chair") id2 = db.thing.insert(name="table") properties.add(id1, "color/red") properties.add(id1, "style/modern") properties.add(id2, "color/green") properties.add(id2, "material/wood") self.assertTrue(properties.get(id1), ["color/red", "style/modern"]) self.assertTrue(properties.get(id2), ["color/green", "material/wood"]) rows = db(properties.find(["style/modern"])).select() self.assertTrue(rows.first().id, id1) rows = db(properties.find(["material/wood"])).select() self.assertTrue(rows.first().id, id1) rows = db(properties.find(["color"])).select() self.assertTrue(len(rows), 2)
def test_tags(self): db = DAL('sqlite:memory') db.define_table('thing', Field('name')) properties = Tags(db.thing) id1 = db.thing.insert(name='chair') id2 = db.thing.insert(name='table') properties.add(id1, 'color/red') properties.add(id1, 'style/modern') properties.add(id2, 'color/green') properties.add(id2, 'material/wood') self.assertTrue(properties.get(id1), ['color/red','style/modern']) self.assertTrue(properties.get(id2), ['color/green','material/wood']) rows = db(properties.find(['style/modern'])).select() self.assertTrue(rows.first().id, id1) rows = db(properties.find(['material/wood'])).select() self.assertTrue(rows.first().id, id1) rows = db(properties.find(['color'])).select() self.assertTrue(len(rows), 2)