Ejemplo n.º 1
0
def register_with_oauth_authorized():
    '''
    This endpoint should be called after authorizing with oauth, by the user.
    '''
    email = request.form.get('email')
    username = request.form.get('username')
    provider = request.form.get('provider')
    remote_user = request.form.get('remote_user')

    good = True
    if check_username_for_registration(username):
        good = False
    if check_email_for_registration(email):
        good = False

    if good:
        password = binascii.b2a_hex(os.urandom(99))
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.flush()  # to get an ID.
        auth = UserAuth(user.id, remote_user, provider)
        db.add(auth)
        db.commit()  # Commit before trying to email

        send_confirmation(user)
        return redirect("/account-pending")

    return render_register_with_oauth(provider, remote_user, username, email)
Ejemplo n.º 2
0
def register_with_oauth_authorized():
    '''
    This endpoint should be called after authorizing with oauth, by the user.
    '''
    email = request.form.get('email')
    username = request.form.get('username')
    provider = request.form.get('provider')
    remote_user = request.form.get('remote_user')

    good = True
    if check_username_for_registration(username):
        good = False
    if check_email_for_registration(email):
        good = False

    if good:
        password = binascii.b2a_hex(os.urandom(99))
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.flush()  # to get an ID.
        auth = UserAuth(user.id, remote_user, provider)
        db.add(auth)
        db.commit()  # Commit before trying to email

        send_confirmation(user)
        return redirect("/account-pending")

    return render_register_with_oauth(provider, remote_user, username, email)
Ejemplo n.º 3
0
def register():
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')
        if not email:
            kwargs['emailError'] = 'Email is required.'
        else:
            if not re.match(r"^[^@]+@[^@]+\.[^@]+$", email):
                kwargs['emailError'] = 'Please specify a valid email address.'
            elif db.query(User).filter(User.email == email).first():
                kwargs['emailError'] = 'A user with this email already exists.'
        if not username:
            kwargs['usernameError'] = 'Username is required.'
        else:
            if not re.match(r"^[A-Za-z0-9_]+$", username):
                kwargs[
                    'usernameError'] = 'Please only use letters, numbers, and underscores.'
            if len(username) < 3 or len(username) > 24:
                kwargs[
                    'usernameError'] = 'Usernames must be between 3 and 24 characters.'
            if db.query(User).filter(User.username.ilike(username)).first():
                kwargs['usernameError'] = 'A user by this name already exists.'
        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs[
                    'passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs[
                    'passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit(
        )  # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html")
Ejemplo n.º 4
0
def register():
    if not _cfgb('registration'):
        return redirect("/")
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')



        error = check_email_for_registration(email)
        if error:
            kwargs['emailError'] = error

        error = check_username_for_registration(username)
        if error:
            kwargs['usernameError'] = error

        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs['passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            # Fill in config values
            kwargs['site_name'] = _cfg('site-name')
            kwargs['support_mail'] = _cfg('support-mail')
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            kwargs['registration'] = registration = _cfgb('registration')
            print("test")
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit() # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html", **{ "site_name": _cfg('site-name'), "support_mail": _cfg('support-mail'), "registration": _cfgb('registration') })
Ejemplo n.º 5
0
def register():
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')
        if not email:
            kwargs['emailError'] = 'Email is required.'
        else:
            if not re.match(r"^[^@]+@[^@]+\.[^@]+$", email):
                kwargs['emailError'] = 'Please specify a valid email address.'
            elif db.query(User).filter(User.email == email).first():
                kwargs['emailError'] = 'A user with this email already exists.'
            elif _mailbans.isMailBanned(email):
                kwargs['emailError'] = 'This email host is banned, please use an alternative, this is to prevent botting, sorry.'
        if not username:
            kwargs['usernameError'] = 'Username is required.'
        else:
            if not re.match(r"^[A-Za-z0-9_]+$", username):
                kwargs['usernameError'] = 'Please only use letters, numbers, and underscores.'
            if len(username) < 3 or len(username) > 24:
                kwargs['usernameError'] = 'Usernames must be between 3 and 24 characters.'
            if db.query(User).filter(User.username.ilike(username)).first():
                kwargs['usernameError'] = 'A user by this name already exists.'
        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs['passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit() # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html")
Ejemplo n.º 6
0
def register():
    if not _cfgb('registration'):
        return redirect("/")
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')

        error = check_email_for_registration(email)
        if error:
            kwargs['emailError'] = error

        error = check_username_for_registration(username)
        if error:
            kwargs['usernameError'] = error

        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs[
                    'passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs[
                    'passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            kwargs['registration'] = registration = _cfgb('registration')
            print("test")
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit(
        )  # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html",
                               registration=_cfgb('registration'))
Ejemplo n.º 7
0
def register():
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')
        if not email:
            kwargs['emailError'] = 'Email is required.'
        else:
            if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
                kwargs['emailError'] = 'Please specify a valid email address.'
            elif db.query(User).filter(User.email == email).first():
                kwargs['emailError'] = 'A user with this email already exists.'
        if not username:
            kwargs['usernameError'] = 'Username is required.'
        else:
            if not re.match(r"[A-Za-z0-9_]+", username):
                kwargs['usernameError'] = 'Please only use letters, numbers, and underscores.'
            if len(username) < 3 or len(username) > 12:
                kwargs['usernameError'] = 'Usernames must be between 3 and 12 characters.'
            if db.query(User).filter(User.username == username).first():
                kwargs['usernameError'] = 'A user by this name already exists.'
        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs['passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit()
        send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html")
Ejemplo n.º 8
0
def test_api_mod(client: 'FlaskClient[Response]') -> None:
    # Arrange
    game = Game(
        name='Kerbal Space Program',
        publisher=Publisher(name='SQUAD', ),
        short='kerbal-space-program',
        active=True,
    )
    mod = Mod(
        name='Test Mod',
        short_description='A mod for testing',
        description='A mod that we will use to test the API',
        user=User(
            username='******',
            description='Test author of a test mod',
            email='*****@*****.**',
            forumUsername='******',
            public=True,
        ),
        license='MIT',
        game=game,
        ckan=False,
        default_version=ModVersion(
            friendly_version="1.0.0.0",
            gameversion=GameVersion(
                friendly_version='1.2.3',
                game=game,
            ),
            download_path='/tmp/blah.zip',
            created=datetime.now(),
        ),
        published=True,
    )
    mod.default_version.mod = mod
    db.add(game)
    db.add(mod)
    db.commit()

    # Act
    publishers_resp = client.get('/api/publishers')
    games_resp = client.get('/api/games')
    kspversions_resp = client.get('/api/kspversions')
    gameversions_resp = client.get('/api/1/versions')
    mod_resp = client.get('/api/mod/1')
    mod_version_resp = client.get('/api/mod/1/latest')
    user_resp = client.get('/api/user/TestModAuthor')
    typeahead_resp = client.get('/api/typeahead/mod?game_id=1&query=Test')
    search_mod_resp = client.get('/api/search/mod?query=Test&page=1')
    search_user_resp = client.get('/api/search/user?query=Test&page=0')

    # Assert
    assert mod_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_mod(mod_resp.json)
    # Not returned by all APIs
    assert mod_resp.json[
        'description'] == 'A mod that we will use to test the API', 'Short description should match'

    assert kspversions_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_game_version(kspversions_resp.json[0])

    assert gameversions_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_game_version(gameversions_resp.json[0])

    assert games_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_game(games_resp.json[0])

    assert publishers_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_publisher(publishers_resp.json[0])

    assert mod_version_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_mod_version(mod_version_resp.json)

    assert user_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_user(user_resp.json)

    assert typeahead_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_mod(typeahead_resp.json[0])

    assert search_mod_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_mod(search_mod_resp.json[0])

    assert search_user_resp.status_code == status.HTTP_200_OK, 'Request should succeed'
    check_user(search_user_resp.json[0])