Arcader7171 commited on
Commit
dc3dd03
·
verified ·
1 Parent(s): 0fb308b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -16,11 +16,21 @@ jwtKey: str = os.environ.get("JWTKey")
16
  # Function Config
17
  allow_signups: bool = False # Set to true when allowing a new user
18
 
 
 
 
 
 
 
19
 
20
  @app.route("/")
21
  def index():
22
  return render_template("index.html")
23
 
 
 
 
 
24
  @app.route("/signup")
25
  def signupPage():
26
  if not allow_signups:
@@ -30,6 +40,7 @@ def signupPage():
30
  @app.route("/login")
31
  def loginPage():
32
  return "<h1>WIP</h1>"
 
33
 
34
  @app.post("/api/signup")
35
  def signupAPI():
@@ -48,6 +59,34 @@ def signupAPI():
48
  response = dbResponse["data"][0]
49
  return make_response(response), 200
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  @app.errorhandler(404)
52
  def not_found(e):
53
  return render_template("404.html")
 
16
  # Function Config
17
  allow_signups: bool = False # Set to true when allowing a new user
18
 
19
+ def jwtDecode(token):
20
+ try:
21
+ return "good", jwt.decode(token, jwtKey, algorithm="HS256")
22
+ except jwt.exceptions.InvalidTokenError:
23
+ return "bad", "Username/Password does not match"
24
+
25
 
26
  @app.route("/")
27
  def index():
28
  return render_template("index.html")
29
 
30
+ @app.route("/app")
31
+ def interApp():
32
+ return "<h1>WIP</h1>"
33
+
34
  @app.route("/signup")
35
  def signupPage():
36
  if not allow_signups:
 
40
  @app.route("/login")
41
  def loginPage():
42
  return "<h1>WIP</h1>"
43
+
44
 
45
  @app.post("/api/signup")
46
  def signupAPI():
 
59
  response = dbResponse["data"][0]
60
  return make_response(response), 200
61
 
62
+ @app.post("/api/login")
63
+ def loginAPI():
64
+ error = None
65
+ if request.method == 'POST':
66
+ inData = json.loads(request.data) # input data, to seperate from the real, valid data
67
+ inUser = str(data["username"])
68
+ inPass = str(data["password"])
69
+ response = (
70
+ supabase.table("users")
71
+ .select("username, password")
72
+ .eq("username", inUser)
73
+ .single()
74
+ .execute()
75
+ )
76
+ data = response["data"]
77
+ try:
78
+ user = data["username"]
79
+ except Exception:
80
+ return "Username does not exist", 401
81
+ jwtPass = jwtDecode(data["password"])
82
+ if jwtPass[0] == "good":
83
+ if jwtPass[1]["password"] == inPass:
84
+ session["username"] = user
85
+ session["password"] = jwtPass[1]["password"]
86
+ return redirect(url_for("interApp"))
87
+ return jwtPass[1], 401
88
+
89
+
90
  @app.errorhandler(404)
91
  def not_found(e):
92
  return render_template("404.html")