コード例 #1
0
ファイル: test_ctfd.py プロジェクト: tanner-g/CTFd
def test_register_user():
    """Tests whether a user can be registered"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        team_count = app.db.session.query(app.db.func.count(Teams.id)).first()[0]
        assert team_count == 2  # There's the admin user and the created user
コード例 #2
0
ファイル: application.py プロジェクト: nejomi/awit
def register():
    if request.method == "POST":

        username = request.form.get("username")
        password = request.form.get("password")
        passwordRepeat = request.form.get("passwordRepeat")

        if not username or not password:
            flash('Input valid username or password')
            return render_template("register.html")
        elif password != passwordRepeat:
            flash('Passwords do not match')
            return render_template("register.html")
        elif re.match("^[A-Za-z0-9]*$", username) == None:
            flash('Please use only numbers and letters for username')
            return render_template("register.html")
        elif count_user(username) > 0:
            flash('Username taken')
            return render_template("register.html")

        passwordHash = generate_password_hash(password)

        register_user(username, passwordHash)

        return redirect("/login")

    else:
        return render_template("register.html")
コード例 #3
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_get_scores():
    """Can a registered user can load /scores"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        r = client.get('/scores')
        assert r.status_code == 200
コード例 #4
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_bad_login():
    """A user should not be able to login with an incorrect password"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app, name="user", password="******")
        r = client.get('/profile')
        assert r.location.startswith("http://localhost/login")  # We got redirected to login
コード例 #5
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_register_duplicate_email():
    """A user shouldn't be able to use an already registered email address"""
    app = create_ctfd()
    with app.app_context():
        register_user(app, name="user1", email="*****@*****.**", password="******")
        register_user(app, name="user2", email="*****@*****.**", password="******")
        team_count = app.db.session.query(app.db.func.count(Teams.id)).first()[0]
        assert team_count == 2  # There's the admin user and the first created user
コード例 #6
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_get_reset_password():
    """Can an unregistered user load /reset_password"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = app.test_client()
        r = client.get('/reset_password')
        assert r.status_code == 200
コード例 #7
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_get_profile():
    """Can a registered user can load their private profile (/profile)"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        r = client.get('/profile')
        assert r.status_code == 200
コード例 #8
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_get_team_page():
    """Can a registered user can load their public profile (/team/2)"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        r = client.get('/team/2')
        assert r.status_code == 200
コード例 #9
0
ファイル: test_ctfd.py プロジェクト: tanner-g/CTFd
def test_user_isnt_admin():
    """Tests to see if a registered user cannot access admin pages"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        r = client.get('/admin/graphs')
        assert r.location == "http://localhost/login"
        assert r.status_code == 302
コード例 #10
0
ファイル: test_ctfd.py プロジェクト: tanner-g/CTFd
def test_user_login():
    """Tests to see if a registered user can login"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        r = client.get('/profile')
        assert r.location != "http://localhost/login"  # We didn't get redirected to login
        assert r.status_code == 200
コード例 #11
0
ファイル: test_user_facing.py プロジェクト: wisco24/CTFd
def test_user_get_logout():
    """Can a registered user load /logout"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        client = login_as_user(app)
        client.get('/logout', follow_redirects=True)
        r = client.get('/challenges')
        assert r.location == "http://localhost/login?next=challenges"
        assert r.status_code == 302
コード例 #12
0
ファイル: application.py プロジェクト: tossev/HarvardX-CS50W
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        if username_exist(db, form.username.data):
            return render_template("register.html",
                                   title="Register",
                                   form=form,
                                   username_exist="Username already exists.")

        register_user(db, form.username.data, form.password.data,
                      form.email.data, curr_time())

        flash(f'An account created for {form.username.data}', 'success')
        return redirect(url_for("login"))

    return render_template("register.html", title="Register", form=form)
コード例 #13
0
ファイル: application.py プロジェクト: amWRit/LostAndFound
def register():
    """Register user"""
    if request.method == "POST":
        # register
        username = request.form.get("username")
        pwd1 = request.form.get("password1")
        pwd2 = request.form.get("password2")
        email = request.form.get("email")
        phone = request.form.get("phone")

        # Ensure username was submitted
        if not username:
            flash('Must provide username.')
            return render_template("register.html")
            # return apology("must provide username", 403)

        # Ensure password was submitted
        elif not pwd1 or not pwd2:
            flash('Must provide password.')
            return render_template("register.html")
            # return apology("must provide password", 403)

        # Ensure two passwords match
        elif pwd1 != pwd2:
            flash('Passwords do not match.')
            return render_template("register.html")
            # return apology("Passwords do not match", 403)

        elif not is_positive_integer(phone) and len(phone) != 15:
            flash('Incorrect phone format.')
            return render_template("register.html")
            # return apology("Incorrect phone format", 403)

        elif check_username_exists(username):
            # check if username exists
            flash('Username already exists.')
            return render_template("register.html")
            # return apology("Username already exists.", 403)
        else:
            pwd_hash = generate_password_hash(pwd1,
                                              method='pbkdf2:sha256',
                                              salt_length=8)

            if register_user(username, pwd_hash, email, phone):
                flash('Registerd successfully. You can now log in.')
                return render_template("login.html")
            else:
                flash('Could not register. Please try again.')
                return render_template("register.html")
                # return apology("Could not register.", 403)

    else:
        return render_template("register.html")
コード例 #14
0
def main():
    # Load common drinks and data for calculations.
    txt_file = r"drinks.txt"
    database_file = r"database.db"
    drinks = load_drinks(txt_file)

    # Main Menu
    print("Welcome to Blood Alcohol Content Calculator")
    while True:
        option = main_menu()
        if option == 1:
            while True:
                drink, abv_pick = choose_drinks(drinks)
                volume = get_volume()
                male_result = average_male_calc(drink, abv_pick, volume)
                female_result = average_female_calc(drink, abv_pick, volume)
                plot_data_average(male_result, female_result)

                again = calculate_again()
                if again == 1:
                    continue
                elif again == 2:
                    break

        elif option == 2:
            person = get_person_data()
            while True:
                drink, abv_pick = choose_drinks(drinks)
                volume = get_volume()
                person_result = custom_person_calc(person, drink, abv_pick, volume)
                plot_data_custom(person_result)

                again = calculate_again()
                if again == 1:
                    continue
                elif again == 2:
                    break

        elif option == 3:
            conn = connect_database(database_file)
            cursor = conn.cursor()
            user_data = log_in(cursor)
            conn.close()
            if user_data:
                while True:
                    drink, abv_pick = choose_drinks(drinks)
                    volume = get_volume()
                    person_result = custom_person_calc(user_data, drink, abv_pick, volume)
                    plot_data_custom(person_result, user_data['username'])

                    again = calculate_again()
                    if again == 1:
                        continue
                    elif again == 2:
                        break

        elif option == 4:
            registering = True
            conn = connect_database(database_file)
            cursor = conn.cursor()
            while registering:
                username = input("Enter your username for registration or 'q' to exit to main menu: \n").lower()
                registered = check_if_registered(cursor, username)
                if username == 'q':
                    break
                else:
                    if registered:
                        print("Username already registered...")
                    else:
                        person = get_person_data()
                        register_user(username, person, cursor)
                        print(f"{username} Registered successfully!")
                        registering = False
            conn.commit()
            conn.close()

        elif option == 5:
            break