@app.route("/quote", methods=["GET", "POST"]) @login_required def quote(): if request =="POST": rows = lookup(request.form.get("quote"))
if not rows:
return apology("Invalid Symbol")
return render_template("quote.html", stock=rows)
else:
return render_template("quote.html")
return render_template("quote.html")
@app.route("/register", methods=["GET","POST"]) def register(): if request.method == "POST":
if request.form.get("username")=='null':
return render_template("Provide a username")
elif request.form.get("password")=='null':
return render_template("Provide a password")
elif request.form.get("confirmation")=='null':
return render_template("checking for password")
elif request.form.get("password") != request.form.get("confirmation"):
return apology("password and confirmation don't match!")
result = db.execute("INSERT INTO users (username, hash) \
VALUES(:username, :hash)", \
username=request.form.get("username"), \
hash=pwd_context.encrypt(request.form.get("password")))
if not result:
return apology("Username already exists! Please try another one")
rows = db.execute("SELECT * from users WHERE username = :username", username = request.form.get("username"))
session["user_id"] = rows[0]["id"]
return redirect(url_for("index"))
else:
return render_template("register.html")