Пример #1
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')
Пример #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': 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')
Пример #3
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)
Пример #4
0
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)