示例#1
0
def listuserinfo():
    arguments = listuserparser.parse_args()
    if not arguments.config or not arguments.username:
        listuserparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        users = session.query(User).filter_by(
            username=arguments.username).all()
        if len(users) > 0:
            user = users[0]
            print('username:%s, secret: %s' % (user.username, user.secret))
            print(
                'bar code url:',
                get_barcode_image(user.username, user.secret,
                                  settings['appname']))
        else:
            print('"%s" user not found' % arguments.username)
示例#2
0
 def setUp(self):
     self.config = testing.setUp()
     self.settings = {
         'sqlalchemy.url': 'sqlite://',
         'em.subject': 'Authentication Request',
         'em.sender': '*****@*****.**',
         'em.body': """
 You have requested authentication.
 Your temporary access code is: {code}""",
         'auth_tkt.secret': 'secret',
         'auth_tkt.cookie_name': 'pnutbtr',
         'supported_auth_schemes': [
             'Google Auth',
             'Email'
         ]
     }
     self.app = Authenticator(test_application, {}, **self.settings)
     from webtest import TestApp
     self.testapp = TestApp(self.app)
     self.mailer = FakeMailer()
     self.testapp.app.pyramid.registry['mailer'] = self.mailer
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from factored.models import Base
     DBSession.configure(bind=engine)
     self.session = DBSession()
     Base.metadata.create_all(engine)
示例#3
0
def listuserinfo():
    arguments = listuserparser.parse_args()
    if not arguments.config or not arguments.username:
        listuserparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        users = session.query(User).filter_by(
            username=arguments.username).all()
        if len(users) > 0:
            user = users[0]
            print 'username:%s, secret: %s' % (
                user.username, user.secret)
            print 'bar code url:', get_barcode_image(user.username,
                                                     user.secret,
                                                     settings['appname'])
        else:
            print '"%s" user not found' % arguments.username
示例#4
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
示例#5
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    try:
        settings = get_appsettings(config_uri, 'factored')
    except LookupError:
        settings = get_appsettings(config_uri, 'main')
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
示例#6
0
def listusers():
    arguments = removeparser.parse_args()
    if not arguments.config:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        settings = get_appsettings(config_uri)
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        with transaction.manager:
            for user in DBSession.query(User).all():
                print user.username
示例#7
0
def factory(settings, app):
    engine = engine_from_config(settings, 'sqlalchemy.')
    configure_db = settings.pop('configure_db', 'true').lower() == 'true'

    if configure_db:
        DBSession.configure(bind=engine)
        db_session_id = 'f'
    else:
        # why would you do this?
        # well... if you have multiple factored wsgi instances running
        # this allows you to change between the connection objects
        db_session_id = settings.pop('db_session_id')
    return db_session_id, DB()
示例#8
0
def factory(settings, app):
    engine = engine_from_config(settings, 'sqlalchemy.')
    configure_db = settings.pop('configure_db', 'true').lower() == 'true'

    if configure_db:
        DBSession.configure(bind=engine)
        db_session_id = 'f'
    else:
        # why would you do this?
        # well... if you have multiple factored wsgi instances running
        # this allows you to change between the connection objects
        db_session_id = settings.pop('db_session_id')
    return db_session_id, DB()
示例#9
0
文件: app.py 项目: zombified/factored
    def __init__(self, *args, **settings):
        if len(args) == 1:
            # regular app
            app = None
        else:
            app = args[0]
        self.initialize_settings(app, settings)

        # db configuration
        engine = engine_from_config(settings, 'sqlalchemy.')
        configure_db = settings.pop('configure_db', 'true').lower() == 'true'

        if configure_db:
            DBSession.configure(bind=engine)
            self.db_session_id = 'f'
        else:
            self.db_session_id = settings.pop('db_session_id')

        self.setup_autouserfinder(settings)

        # start pyramid application configuration
        config = Configurator(settings=settings, request_factory=Request)

        self.setup_plugins(config, settings)

        from factored.views import auth_chooser, notfound
        config.add_route('auth', self.base_auth_url)
        config.add_view(auth_chooser, route_name='auth',
                        renderer='templates/layout.pt')

        # setup template customization registration
        if TEMPLATE_CUSTOMIZATIONS not in config.registry:
            config.registry[TEMPLATE_CUSTOMIZATIONS] = {}

        # static paths for resources
        self.static_path = os.path.join(self.base_auth_url, 'authstatic')
        config.add_static_view(name=self.static_path,
                               path='factored:static')
        config.add_notfound_view(notfound, append_slash=True)

        # add some things to registry
        config.registry['mailer'] = Mailer.from_settings(settings)
        config.registry['settings'] = self.__dict__
        config.registry['formtext'] = nested_settings(
            get_settings(settings, 'formtext.'))
        config.registry['app'] = self

        config.scan()
        self.pyramid = config.make_wsgi_app()
示例#10
0
def listusers():
    arguments = removeparser.parse_args()
    if not arguments.config:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        for user in session.query(User).all():
            print user.username
示例#11
0
def listusers():
    arguments = removeparser.parse_args()
    if not arguments.config:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        for user in session.query(User).all():
            print(user.username)
示例#12
0
def add():
    arguments = addparser.parse_args()
    if not arguments.config or not arguments.username:
        addparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        settings = get_appsettings(config_uri)
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        with transaction.manager:
            username = arguments.username
            user = create_user(username)
            print 'barcode url:', get_barcode_image(username, user.secret,
                settings['appname'])
            print 'secret:', user.secret
示例#13
0
def remove():
    arguments = removeparser.parse_args()
    if not arguments.config or not arguments.username:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        settings = get_appsettings(config_uri)
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        with transaction.manager:
            user = DBSession.query(User).filter_by(
                username=arguments.username).all()
            if len(user) > 0:
                DBSession.delete(user[0])
            else:
                print '"%s" user not found' % arguments.username
示例#14
0
def add():
    arguments = addparser.parse_args()
    if not arguments.config or not arguments.username:
        addparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        username = arguments.username
        user = create_user(username, session)
        print('barcode url:',
              get_barcode_image(username, user.secret, settings['appname']))
        print('secret:', user.secret)
        session.commit()
        session.close()
示例#15
0
def add():
    arguments = addparser.parse_args()
    if not arguments.config or not arguments.username:
        addparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        username = arguments.username
        user = create_user(username, session)
        print 'barcode url:', get_barcode_image(username, user.secret,
                                                settings['appname'])
        print 'secret:', user.secret
        session.commit()
        session.close()
示例#16
0
def remove():
    arguments = removeparser.parse_args()
    if not arguments.config or not arguments.username:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        user = session.query(User).filter_by(username=arguments.username).all()
        if len(user) > 0:
            session.delete(user[0])
        else:
            print('"%s" user not found' % arguments.username)
        session.commit()
        session.close()
示例#17
0
def remove():
    arguments = removeparser.parse_args()
    if not arguments.config or not arguments.username:
        removeparser.print_usage()
    else:
        config_uri = arguments.config
        setup_logging(config_uri)
        try:
            settings = get_appsettings(config_uri, 'factored')
        except LookupError:
            settings = get_appsettings(config_uri, 'main')
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)
        session = DBSession()
        user = session.query(User).filter_by(
            username=arguments.username).all()
        if len(user) > 0:
            session.delete(user[0])
        else:
            print '"%s" user not found' % arguments.username
        session.commit()
        session.close()
示例#18
0
 def setUp(self):
     self.config = testing.setUp()
     self.settings = {
         'sqlalchemy.url': 'sqlite://',
         'em.subject': 'Authentication Request',
         'em.sender': '*****@*****.**',
         'em.body': """
 You have requested authentication.
 Your temporary access code is: {code}""",
         'auth_tkt.secret': 'secret',
         'auth_tkt.cookie_name': 'pnutbtr',
         'supported_auth_schemes': ['Google Auth', 'Email']
     }
     self.app = Authenticator(test_application, {}, **self.settings)
     from webtest import TestApp
     self.testapp = TestApp(self.app)
     self.mailer = FakeMailer()
     self.testapp.app.pyramid.registry['mailer'] = self.mailer
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from factored.models import Base
     DBSession.configure(bind=engine)
     self.session = DBSession()
     Base.metadata.create_all(engine)