Skip to content

Commit

Permalink
improve comments in app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akrakman committed Dec 6, 2022
1 parent b89f164 commit 225264d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
def googlelogin():
"""Handles google oauth login"""
google_client = oauth.create_client("google")
redirect_uri = url_for("authorize", _external=True)
redirect_uri = url_for("authorize", _external=True) # move to /authorize route
return google_client.authorize_redirect(redirect_uri)


Expand All @@ -46,13 +46,13 @@ def authorize():
"""Authorization with google"""
google_client = oauth.create_client("google")
token = google_client.authorize_access_token()
resp = google_client.get("userinfo", token=token)
resp.raise_for_status()
user_info = resp.json()
# Note: you're not supposed to use user google data in session...
resp = google_client.get("userinfo", token=token) # userinfo contains email
resp.raise_for_status() # check status code
user_info = resp.json() # convert to json
# query database for username
page = UserPage(user_info["email"])
session["username"] = page.get_user(user_info["email"]).username
return redirect("http://localhost:3000"), 301
return redirect("http://localhost:3000"), 301 # necessary status code


@app.route("/login", methods=["GET", "POST"])
Expand Down Expand Up @@ -101,7 +101,7 @@ def userpage():
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
# see which field is True and should be changed
is_password = json_form.get("is_password", False)
is_email = json_form.get("is_email", False)
is_phone = json_form.get("is_phone", False)
Expand All @@ -128,7 +128,7 @@ def userpage():
@app.route("/logout")
def logout():
"""Removes session object"""
session.pop("username", None) # remove session object
session.pop("username", None)
return "logout success", 201


Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export default function Login() {
<Typography style={{ marginTop: '10px' }}>
<Link href="/">Access without logging in</Link>
</Typography>
{/* Moves to the server-side to do the authorization.
I'm not sure if it's good practice.
*/}
<Link href="http://127.0.0.1:5000/googlelogin">
<GoogleButton style={{ marginTop: '10px' }} />
</Link>
Expand Down

3 comments on commit 225264d

@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.py171895%47–55
auth.py90100% 
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py160100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1200100% 
   userpage.py530100% 
TOTAL450898% 

Tests Skipped Failures Errors Time
54 0 💤 0 ❌ 0 🔥 1.392s ⏱️

@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.py171895%47–55
auth.py90100% 
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py160100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1200100% 
   userpage.py530100% 
TOTAL450898% 

Tests Skipped Failures Errors Time
54 0 💤 0 ❌ 0 🔥 1.355s ⏱️

@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.py171895%47–55
auth.py90100% 
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py160100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1200100% 
   userpage.py530100% 
TOTAL450898% 

Tests Skipped Failures Errors Time
54 0 💤 0 ❌ 0 🔥 1.418s ⏱️

Please sign in to comment.