Ejemplo n.º 1
0
def verify_accounts():
    """Verifies the create accounts against the password file."""
    engine = engine_from_config(get_config(), 'sqlalchemy.')
    initialize_sql(engine, False)
    session = DBSession()

    if len(sys.argv) < 3:
        print "Usage: {0} <config> <data>".format(sys.argv[0])
        sys.exit(1)

    users = dict((user.username, user) for user in session.query(User).all())
    failed = 0

    print "Checking.."
    passwords = open(sys.argv[2]).readlines()
    for line in passwords:
        username, password = line.strip().split('|', 1)
        if username not in users:
            print "Unknown user:"******"Invalid password for user", username
            failed += 1

    print "Checked", len(passwords), "passwords against", len(users), "users."
    print "Failures", failed
    if failed == 0:
        print "All OK"
    else:
        print "Data inconsistency, please investigate!"
Ejemplo n.º 2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    config = Configurator(settings=settings)
    config.include(pyramid_zcml)
    config.load_zcml('configure.zcml')
    config.set_session_factory(session_factory_from_settings(settings))
    return config.make_wsgi_app()
Ejemplo n.º 3
0
def populate_accounts():
    """Populates the database with production data."""
    engine = engine_from_config(get_config(), 'sqlalchemy.')
    initialize_sql(engine, False)
    session = DBSession()

    if len(sys.argv) < 3:
        print "Usage: {0} <config> <data>".format(sys.argv[0])
        sys.exit(1)

    for line in open(sys.argv[2]).readlines():
        username, password = line.strip().split('|', 1)
        session.add(User(username.strip(), password.strip(), '*****@*****.**'))
        print username

    session.flush()
    transaction.commit()
Ejemplo n.º 4
0
def populate_demo():
    """Populates the database with 50 demo users."""
    engine = engine_from_config(get_config(), 'sqlalchemy.')
    initialize_sql(engine, False)

    session = DBSession()

    for count in range(1, 51):
        session.add(User('test.user{0:02}'.format(count), 'testi', '*****@*****.**'))

    session.add(User('test.pref01', 'testi', u'*****@*****.**'))
    session.add(User('test.pref02', 'testi', None))
    session.add(User('test.pref03', 'testi', u'*****@*****.**'))
    session.add(User('test.pref04', 'testi', u'*****@*****.**'))
    session.add(User('test.pref05', 'testi', None))

    session.flush()
    transaction.commit()
    print("Generated 50 demo users.")
Ejemplo n.º 5
0
def _initTestingDB(echo=False):
    from webidentity.models import initialize_sql
    engine = create_engine('sqlite:///', echo=echo)
    session = initialize_sql(engine, populate_db=False)
    return session