0

I would like to ask for your help please with an error I keep getting on my code for the week 9 Finance. I have been receiving :| logging in as registered user succceeds can't check until a frown turns upside down I don't understand where to be fixed... Here is my login function below

def login():
    """Log user in"""

    # Forget any user_id
    session.clear()

    # User reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        # Ensure username and password were submitted
        result_checks = is_provided("username") or is_provided("password")
        if result_checks is not None:
            return result_checks
        # Query database for username
        rows = db.execute("SELECT * FROM users WHERE username = :username",
                          username=request.form.get("username"))

        # Ensure username exists and password is correct
        if len(rows) != 1 or not check_password_hash(rows[0]["hash"], request.form.get("password")):
            return apology("invalid username and/or password", 403)

        # Remember which user has logged in
        session["user_id"] = rows[0]["id"]

        # Redirect user to home page
        return redirect("/")

    else:
        return render_template("login.html")```

Also, register function below.

@app.route("/register", methods=["GET", "POST"]) def register(): if request.method == "POST": result_checks = is_provided("username") or is_provided("password") or is_provided("confirmation") if result_checks != None: return result_checks if request.form.get("password") != request.form.get("confirmation"): return apology("passwords must match") try: prim_key = db.execute("INSERT INTO users (username, hash) VALUES (:usernane, :hash)", username=request.form.get("username"), hash=generate_password_hash(request.form.get("password"))) except: return apology("username already exists", 403) if prim_key is None: return apology("registration error", 403) session["user_id"] = prim_key return redirect("/")

else:
    return render_template("register.html")

Please help me guys :")

You must log in to answer this question.

Browse other questions tagged .