Skip to content

Commit

Permalink
add new route to get session object
Browse files Browse the repository at this point in the history
  • Loading branch information
akrakman committed Nov 28, 2022
1 parent 5b15da6 commit 85419da
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def userpage():
"""Handles userpage requests"""
if session.get("username", None) is None:
return "user does not exist", 404
diff = session.get("username") or ""
page = UserPage(diff)
name = session.get("username") or ""
page = UserPage(name)
if request.method == "POST":
json_form = request.get_json(force=True) or {} # deserialize data
# see which field was True and therefore should be changed
Expand All @@ -76,7 +76,7 @@ def userpage():
if not result:
return "invalid request", 400
return "success", 201
user = page.get_user(diff) # request.method == "GET"
user = page.get_user(name) # request.method == "GET"
data_dict = dataclasses.asdict(user)
return json.dumps(data_dict), 201

Expand All @@ -87,6 +87,13 @@ def logout():
session.pop("username", None) # remove session object
return "", 201

@app.route("/api/whoami")
def whoami():
"""Shows whether a user is logged in, returns session username"""
if session.get("username", None) is None:
return "user logged out", 404
username = session.get("username")
return {"username": username}, 201

@app.route("/", methods=["GET", "POST"])
@app.route("/main", methods=["GET", "POST"])
Expand Down

3 comments on commit 85419da

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py138497%93–96
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL388499% 

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 0.798s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py138497%93–96
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL388499% 

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 0.905s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py138497%93–96
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL388499% 

Tests Skipped Failures Errors Time
48 0 💤 0 ❌ 0 🔥 1.186s ⏱️

Please sign in to comment.