Exemplo n.º 1
0
 def by_username(cls, username, request):
     """Return user instance by username"""
     root = user_root_factory(request)
     if username not in root:
         return None
     else:
         return root[username]
Exemplo n.º 2
0
 def by_username(cls, username, request):
     """Return user instance by username"""
     root = user_root_factory(request)
     if username not in root:
         return None
     else:
         return root[username]
Exemplo n.º 3
0
def create_admin_user(dbconn):
    username = input('username for administrator (default="admin"): ')
    username = '******' if not username or username == '' else username
    password = getpass.getpass()
    admin = User(username, password, groups=['group:admin'])
    root = user_root_factory(dbconn)
    root[username] = admin
    transaction.commit()
Exemplo n.º 4
0
def check_database_config(config):
    from papaye.models import get_manager
    manager = get_manager(config)
    if manager.get_db_version() < manager.get_sw_version():
        raise ConfigurationError('Your database need to be updated! Run '
                                 '"papaye_evolve path_to_your_config_file.ini" command first')
    conn = config.registry._zodb_databases[''].open()
    if user_root_factory(conn) is None or repository_root_factory(conn) is None:
        raise ConfigurationError('Database does not exist! Run "papaye_init '
                                 'path_to_your_config_file.ini command first')
    return True
Exemplo n.º 5
0
    def test_by_username(self):
        from papaye.models import User
        from papaye.factories import user_root_factory

        root = user_root_factory(self.request)
        root['a_user'] = User('a_user', 'password')

        result = User.by_username('a_user', self.request)

        self.assertIsInstance(result, User)
        self.assertEqual(result.username, 'a_user')
Exemplo n.º 6
0
    def test_by_username(self):
        from papaye.models import User
        from papaye.factories import user_root_factory

        root = user_root_factory(self.request)
        root['a_user'] = User('a_user', 'password')

        result = User.by_username('a_user', self.request)

        self.assertIsInstance(result, User)
        self.assertEqual(result.username, 'a_user')
Exemplo n.º 7
0
def check_database_config(config):
    from papaye.models import get_manager
    manager = get_manager(config)
    if manager.get_db_version() < manager.get_sw_version():
        raise ConfigurationError('Your database need to be updated! Run '
                                 '"papaye_evolve path_to_your_config_file.ini" command first')
    conn = config.registry._zodb_databases[''].open()
    if user_root_factory(conn) is None or repository_root_factory(conn) is None:
        raise ConfigurationError('Database does not exist! Run "papaye_init '
                                 'path_to_your_config_file.ini command first')
    return True
Exemplo n.º 8
0
def setup(env):
    env['user_root'] = user_root_factory(env['request'])
    env['repo_root'] = repository_root_factory(env['request'])
    env['set_db_version'] = functools.partial(set_database_version,
                                              env['request'])
Exemplo n.º 9
0
 def by_username(cls, username, request):
     """Return user instance by username"""
     root = user_root_factory(request)
     if username in [user.username for user in root]:
         return root[username]
     return None
Exemplo n.º 10
0
def setup(env):
    env['user_root'] = user_root_factory(env['request'])
    env['repo_root'] = repository_root_factory(env['request'])
    env['default_root'] = default_root_factory(env['request'])
    env['set_db_version'] = functools.partial(set_database_version, env['request'])
Exemplo n.º 11
0
def create_admin_user(dbconn, username, password):
    admin = User(username, password, groups=["group:admin"])
    root = user_root_factory(dbconn)
    root[username] = admin
    transaction.commit()