Exemple #1
0
 def set_password(self, password):
     """
     Save password to user.
     :param password: string of new password
     :return: None
     """
     self.password = self.encode_password(password, get_random_string())
Exemple #2
0
def reset_password():
    """
    Final password reset form POST endpoint.
    """
    code = request.forms.get('code')
    password = request.forms.get('password')
    confirm_password = request.forms.get('confirm_password')

    # Validate password
    if confirm_password != password:
        return redirect_with_query(
            '/account/reset/verified',
            {'code_valid': True, 'code': code, 'error': "Passwords do not match."},
        )
    try:
        User.validate_password(password)
    except UsageError as e:
        return redirect_with_query(
            '/account/reset/verified', {'code_valid': True, 'code': code, 'error': str(e)}
        )

    # Verify reset code again and get user_id
    user_id = local.model.get_reset_code_user_id(code, delete=True)
    if user_id is None:
        return redirect_with_query('/account/reset/verified', {'code_valid': False})

    # Update user password
    user_info = local.model.get_user_info(user_id)
    user_info['password'] = (User.encode_password(password, crypt_util.get_random_string()),)
    local.model.update_user_info(user_info)

    return redirect('/account/reset/complete')
Exemple #3
0
 def set_password(self, password):
     """
     Save password to user.
     :param password: string of new password
     :return: None
     """
     self.password = self.encode_password(password, get_random_string())
Exemple #4
0
def reset_password():
    """
    Final password reset form POST endpoint.
    """
    code = request.forms.get('code')
    password = request.forms.get('password')
    confirm_password = request.forms.get('confirm_password')

    # Validate password
    if confirm_password != password:
        return redirect_with_query(
            '/account/reset/verified',
            {'code_valid': True, 'code': code, 'error': "Passwords do not match."},
        )
    try:
        User.validate_password(password)
    except UsageError as e:
        return redirect_with_query(
            '/account/reset/verified', {'code_valid': True, 'code': code, 'error': e.message}
        )

    # Verify reset code again and get user_id
    user_id = local.model.get_reset_code_user_id(code, delete=True)
    if user_id is None:
        return redirect_with_query('/account/reset/verified', {'code_valid': False})

    # Update user password
    user_info = local.model.get_user_info(user_id)
    user_info['password'] = (User.encode_password(password, crypt_util.get_random_string()),)
    local.model.update_user_info(user_info)

    return redirect('/account/reset/complete')
    def init_config(self, dry_run=False):
        '''
        Initialize configuration for a simple client.
        For the server, see config_gen in the codalab-worksheets repo.
        '''
        print_block(r"""
           ____          _       _            _
         / ____|___   __| | __ _| |     T T  | |__
        | |    / _ \ / _` |/ _` | |     |o|  | '_ \
        | |___| (_) | (_| | (_| | |___ /__o\ | |_) |
         \_____\___/ \__,_|\__,_|_____/_____\|_.__/

        Welcome to the CodaLab CLI!

        Your CodaLab configuration and state will be stored in: {0.codalab_home}
        """.format(self))

        main_bundle_service = 'https://worksheets.codalab.org/bundleservice'

        config = {
            'cli': {
                'default_address': main_bundle_service,
                'verbose': 1,
            },
            'server': {
                'host': 'localhost',
                'port': 2800,
                'rest_host': 'localhost',
                'rest_port': 2900,
                'class': 'MySQLModel',
                'engine_url': 'mysql://codalab@localhost:3306/codalab_bundles',
                'auth': {
                    'class': 'RestOAuthHandler'
                },
                'verbose': 1,
            },
            'aliases': {
                'main': main_bundle_service,
                'localhost': 'http://localhost:2800',
            },
            'workers': {
                'default_docker_image': 'codalab/ubuntu:1.9',
            }
        }

        # Generate secret key
        config['server']['secret_key'] = get_random_string(
            48, "=+/abcdefghijklmnopqrstuvwxyz"
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

        if not dry_run:
            write_pretty_json(config, self.config_path)

        return config
    def _simplify_directory(self, path, child_path=None):
        """
        Modifies |path| in place: If the |path| directory contains exactly
        one file / directory, then replace |path| with that file / directory.
        """
        if child_path is None:
            child_path = os.listdir(path)[0]

        temp_path = path + crypt_util.get_random_string()
        path_util.rename(path, temp_path)
        child_path = os.path.join(temp_path, child_path)
        path_util.rename(child_path, path)
        path_util.remove(temp_path)
Exemple #7
0
    def _simplify_directory(self, path, child_path=None):
        """
        Modifies |path| in place: If the |path| directory contains exactly
        one file / directory, then replace |path| with that file / directory.
        """
        if child_path is None:
            child_path = os.listdir(path)[0]

        temp_path = path + crypt_util.get_random_string()
        path_util.rename(path, temp_path)
        child_path = os.path.join(temp_path, child_path)
        path_util.rename(child_path, path)
        path_util.remove(temp_path)
Exemple #8
0
    def init_config(self, dry_run=False):
        '''
        Initialize configuration for a simple client.
        For the server, see config_gen in the codalab-worksheets repo.
        '''
        print_block(r"""
           ____          _       _            _
         / ____|___   __| | __ _| |     T T  | |__
        | |    / _ \ / _` |/ _` | |     |o|  | '_ \
        | |___| (_) | (_| | (_| | |___ /__o\ | |_) |
         \_____\___/ \__,_|\__,_|_____/_____\|_.__/

        Welcome to the CodaLab CLI!

        Your CodaLab configuration and state will be stored in: {0.codalab_home}
        """.format(self))

        config = {
            'cli': {
                'default_address': MAIN_BUNDLE_SERVICE,
                'verbose': 1
            },
            'server': {
                'rest_host': 'localhost',
                'rest_port': 2900,
                'class': 'MySQLModel',
                'engine_url': 'mysql://codalab@localhost:3306/codalab_bundles',
                'auth': {
                    'class': 'RestOAuthHandler'
                },
                'verbose': 1,
            },
            'aliases': {
                'main': MAIN_BUNDLE_SERVICE,
                'localhost': 'http://localhost'
            },
            'workers': {
                'default_cpu_image': 'codalab/default-cpu:latest',
                'default_gpu_image': 'codalab/default-gpu:latest',
            },
        }

        # Generate secret key
        config['server']['secret_key'] = get_random_string(
            48, "=+/abcdefghijklmnopqrstuvwxyz"
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

        if not dry_run:
            write_pretty_json(config, self.config_path)

        return config
Exemple #9
0
from codalab.objects.user import User

manager = CodaLabManager()
model = manager.model()

username = manager.root_user_name()
user_id = manager.root_user_id()

if len(sys.argv) == 2:
    password = sys.argv[1]
else:
    while True:
        password = getpass.getpass()
        if getpass.getpass('Config password: '******'Passwords don\'t match. Try again.'
        print

if model.get_user(user_id=user_id, check_active=False):
    update = {
        "user_id": user_id,
        "user_name": username,
        "password": User.encode_password(password, crypt_util.get_random_string()),\
        "is_active": True,
        "is_verified": True,
    }
    model.update_user_info(update)
else:
    model.add_user(username, '', password, user_id, is_verified=True)
from codalab.lib import crypt_util
from codalab.lib.codalab_manager import CodaLabManager
from codalab.objects.user import User

manager = CodaLabManager()
model = manager.model()

username = manager.root_user_name()
user_id = manager.root_user_id()

if len(sys.argv) == 2:
    password = sys.argv[1]
else:
    while True:
        password = getpass.getpass('Password for %s(%s): ' % (username, user_id))
        if getpass.getpass('Confirm password: '******'Passwords don\'t match. Try again.')

if model.get_user(user_id=user_id, check_active=False):
    update = {
        "user_id": user_id,
        "user_name": username,
        "password": User.encode_password(password, crypt_util.get_random_string()),
        "is_active": True,
        "is_verified": True,
    }
    model.update_user_info(update)
else:
    model.add_user(username, '', '', '', password, '', user_id=user_id, is_verified=True)
Exemple #11
0
if len(sys.argv) == 2:
    password = sys.argv[1]
else:
    while True:
        password = getpass.getpass('Password for %s(%s): ' %
                                   (username, user_id))
        if getpass.getpass('Confirm password: '******'Passwords don\'t match. Try again.')

if model.get_user(user_id=user_id, check_active=False):
    update = {
        "user_id": user_id,
        "user_name": username,
        "password": User.encode_password(password,
                                         crypt_util.get_random_string()),
        "has_access": True,
        "is_active": True,
        "is_verified": True,
    }
    model.update_user_info(update)
else:
    model.add_user(username,
                   '',
                   '',
                   '',
                   password,
                   '',
                   user_id=user_id,
                   is_verified=True,
                   has_access=True)
    def init_config(self, dry_run=False):
        '''
        Initialize configurations.
        TODO: create nice separate abstraction for building/modifying config
        '''
        print_block(r"""
           ____          _       _            _
         / ____|___   __| | __ _| |     T T  | |__
        | |    / _ \ / _` |/ _` | |     |o|  | '_ \
        | |___| (_) | (_| | (_| | |___ /__o\ | |_) |
         \_____\___/ \__,_|\__,_|_____/_____\|_.__/

        Welcome to the CodaLab CLI!

        Your CodaLab data will be stored in: {0.codalab_home}

        Initializing your configurations at: {0.config_path}

        """.format(self))

        config = {
            'cli': {
                'verbose': 1,
            },
            'server': {
                'host': 'localhost',
                'port': 2800,
                'rest_host': 'localhost',
                'rest_port': 2900,
                'auth': {
                    'class': 'MockAuthHandler'
                },
                'verbose': 1,
            },
            'aliases': {
                'main': 'https://worksheets.codalab.org/bundleservice',
                'localhost': 'http://*****:*****@{host}/{database}".format(
                    **{
                        'host':
                        prompt_str("Host:"),
                        'database':
                        prompt_str("Database:", default='codalab_bundles'),
                        'username':
                        prompt_str("Username:"******"sqlite:///{}".format(
                sqlite_db_path)
            print "Using SQLite database at: {}".format(sqlite_db_path)

        # Generate secret key
        config['server']['secret_key'] = get_random_string(
            48, "=+/abcdefghijklmnopqrstuvwxyz"
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

        # Rest of instructions
        print_block(r"""
        Please follow the instructions here to finish the setup (e.g., installing docker, OAuth):
        https://github.com/codalab/codalab-worksheets/wiki/Setup-Local-Worksheets
        """)

        if not dry_run:
            write_pretty_json(config, self.config_path)

        return config
Exemple #13
0
    def init_config(self, dry_run=False):
        '''
        Initialize configurations.
        TODO: create nice separate abstraction for building/modifying config
        '''
        print_block(r"""
           ____          _       _            _
         / ____|___   __| | __ _| |     T T  | |__
        | |    / _ \ / _` |/ _` | |     |o|  | '_ \
        | |___| (_) | (_| | (_| | |___ /__o\ | |_) |
         \_____\___/ \__,_|\__,_|_____/_____\|_.__/

        Welcome to the CodaLab CLI!

        Your CodaLab data will be stored in: {0.codalab_home}

        Initializing your configurations at: {0.config_path}

        """.format(self))

        config = {
            'cli': {
                'verbose': 1,
            },
            'server': {
                'host': 'localhost',
                'port': 2800,
                'rest_host': 'localhost',
                'rest_port': 2900,
                'auth': {
                    'class': 'RestOAuthHandler'
                },
                'verbose': 1,
            },
            'aliases': {
                'main': 'https://worksheets.codalab.org/bundleservice',
                'localhost': 'http://*****:*****@{host}/{database}".format(**{
                'host': prompt_str("Host:"),
                'database': prompt_str("Database:", default='codalab_bundles'),
                'username': prompt_str("Username:"******"sqlite:///{}".format(sqlite_db_path)
            print "Using SQLite database at: {}".format(sqlite_db_path)

        # Generate secret key
        config['server']['secret_key'] = get_random_string(
            48, "=+/abcdefghijklmnopqrstuvwxyz"
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

        # Rest of instructions
        print_block(r"""
        Please follow the instructions here to finish the setup (e.g., installing docker, OAuth):
        https://github.com/codalab/codalab-worksheets/wiki/Setup-Local-Worksheets
        """)

        if not dry_run:
            write_pretty_json(config, self.config_path)

        return config