def user_page(user_id): # If this isn't a valid user, send a 404. if not db_func.check_if_user_exists(user_id): abort(404) user = FCMember(user_id) page = request.args.get(get_page_parameter(), type=int, default=1) per_page = current_app.config["POSTS_PER_PAGE"] offset = (page - 1) * per_page pagination = Pagination( page=page, per_page=per_page, search=False, total=len(user.beers), record_name="beers", css_framework="bootstrap3", ) return render_template( "users/profile.html", user=user.username, score=user.avg_score, beers=user.beers[offset:offset + per_page], win_total=user._win_count, wins=user.wins, avg_abv=user.avg_abv, pagination=pagination, page=page, per_page=per_page, )
def _validate_user(user: str, beer_name=None): if not db_func.check_if_user_exists(user): if not beer_name: return ValidatorResults("User does not exist", False) else: return ValidatorResults( "User does not exist for {}".format(beer_name), False) return ValidatorResults("", True)
def user_page(user_id): # If this isn't a valid user, send a 404. if not db_func.check_if_user_exists(user_id): abort(404) user = FCMember(user_id) return render_template( "users/profile.html", user=user.username, score=user.avg_score, beers=user.beers, win_total=user._win_count, wins=user.wins, avg_abv=user.avg_abv, )
def register(): """Function responsible for registration""" if request.method == "POST": username = request.form["username"] password = request.form["password"] error = None if not username: error = "Username is required." elif not password: error = "Password is required." elif db_func.check_if_user_exists(username): error = f"User {username} is already registered." if error is None: db.session.add( User(username=username, password=generate_password_hash(password))) db.session.commit() return redirect(url_for("auth.login")) flash(error) return render_template("auth/register.html")
def test_no_user_check(app, test_client): # This database should be empty at the start. with app.app_context(): assert db_func.check_if_user_exists("test") == False
def test_add_user(app, test_client): # Test adding a user with app.app_context(): db_func.add_user("test", "test") assert db_func.check_if_user_exists("test") == True