I don't understand why this feature in my flask/html webapp doesn't work

Issue:


Right now when I go to this page, it properly redirects, me, and I can log in properly, and it can properly authenticate me, but when it redirects to /home, it gives me the not logged in page. When I remove this, it doesn’t get the username and leaves it blank. I set the variables to global and there are no errors, but I want to know what’s going on and to fix it, because this took me forever to make lol


Repl link:
https://replit.com/@cheez6784/home?v=1


The Code:
(Note, site with scrambled letters and numbers has a different link now)

from flask import Flask, redirect, request, render_template
import requests, random

app = Flask('app')
fullyloggedin = 0

username = ''

@app.route('/')
def home():
  return redirect(
    "https://Webage-Signup-With-Accounts.cheez6784.repl.co/?oauth=1&authuser=homepage&v=1"
  )


@app.route("/loggedin")
def loggedin():
  if "loggedin" in request.args:
    if request.args.get("loggedin") == 1:
      isloggedin = 1
    else:
      isloggedin = 0
  else:
    return "This is oauth :/"
  if "username" in request.args:
    username = str(request.args.get("username"))
    fullyloggedin = 1
  elif isloggedin == 1:
    fullyloggedin = 0
    return "Please give username"

  else:
    fullyloggedin = 0
    return "Please enter in the correct information"
  if "authkey" in request.args:
    inputtedauthkey = request.args.get("authkey")
    realauthkey = requests.get(
      "https://n48fy34fhu749270hf3u8fh3fhre0q34fh87034.cheez6784.repl.co"
    ).json()
    if int(inputtedauthkey) == int(realauthkey):
      fullyloggedin = 1
      requests.get(
        "https://n48fy34fhu749270hf3u8fh3fhre0q34fh87034.cheez6784.repl.co/?keychange="
        + str(random.randint(0, 99999999999999999999))).json()

    else:
      fullyloggedin = 0
      return "Unauthorized Key!"
  else:
    fullyloggedin = 0
  if fullyloggedin == 1:

    return redirect("/home")


@app.route("/home")
def homepage():
  global username, fullyloggedin
  
  if fullyloggedin == 1:
    return render_template("homepage.html", username=username)
  else:
    return "Not Logged In :("
  

  


@app.errorhandler(404)
def not_found_error(error):
  return "We Couldn't Find That Page :("


app.run(host='0.0.0.0', port=8080)

I think the problem is that the request is for each URL. Try logging the information in a db or file instead.

3 Likes

@CoderElijah What do you mean the request is for each url? Just to clarify :slight_smile:

You can’t send requested info from /home to /loggedin or vise versa AFAIK. You can however, send it to a file or db and then get it from there.

1 Like

Oh, alright, good to know! Ill try that and let you know.

Thank you so much it worked!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.