Skip to content

Commit 07cacfa

Browse files
committed
Here is all the code from the twitch stream today exactly as typed.
1 parent f359e65 commit 07cacfa

File tree

14 files changed

+184
-13
lines changed

14 files changed

+184
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,6 @@ app/ch13-validation/starter/.idea/inspectionProfiles/Project_Default.xml
175175
app/ch14_testing/final/.idea/inspectionProfiles/Project_Default.xml
176176
app/ch14_testing/starter/.idea/inspectionProfiles/Project_Default.xml
177177
app/ch15_deploy/final/.idea/inspectionProfiles/Project_Default.xml
178+
app/ch15_deploy/final/pypi_org/flask_session
179+
d43be29f-e2f2-41e5-8dde-ed049a1776b6.xml
180+
dataSources.local.xml

app/ch15_deploy/final/.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ch15_deploy/final/.idea/dataSources.xml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ch15_deploy/final/.idea/dictionaries/mkennedy.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ch15_deploy/final/.idea/flask-deploy.iml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ch15_deploy/final/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ch15_deploy/final/pypi_org/app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
import sys
33

44
import flask
5+
from flask_session import Session
6+
7+
from pypi_org.configs import app_config
58

69
folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
710
sys.path.insert(0, folder)
811
import pypi_org.data.db_session as db_session
912

1013
app = flask.Flask(__name__)
14+
app.config.from_object(app_config)
1115

1216

1317
def main():
1418
configure()
15-
app.run(debug=True, port=5006)
19+
app.run(debug=True, port=5006, host='localhost')
1620

1721

1822
def configure():
@@ -23,9 +27,15 @@ def configure():
2327

2428
setup_db()
2529
print("DB setup completed.")
30+
31+
setup_session_server()
2632
print("", flush=True)
2733

2834

35+
def setup_session_server():
36+
Session(app)
37+
38+
2939
def setup_db():
3040
db_file = os.path.join(
3141
os.path.dirname(__file__),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
b2c_tenant = "talkpythondemos"
2+
signupsignin_user_flow = "B2C_1_susi"
3+
editprofile_user_flow = "B2C_1_profileediting1"
4+
resetpassword_user_flow = "B2C_1_passwordreset1"
5+
authority_template = "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{user_flow}"
6+
7+
CLIENT_ID = "115c67cd-3558-4bc4-9180-51c6d2d4fa45" # Application (client) ID of app registration
8+
9+
CLIENT_SECRET = "s.4i3ff~139.58~3DMuE42KvZ8-X4ytAS9" # Placeholder - for use ONLY during testing.
10+
# In a production app, we recommend you use a more secure method of storing your secret,
11+
# like Azure Key Vault. Or, use an environment variable as described in Flask's documentation:
12+
# https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables
13+
# CLIENT_SECRET = os.getenv("CLIENT_SECRET")
14+
# if not CLIENT_SECRET:
15+
# raise ValueError("Need to define CLIENT_SECRET environment variable")
16+
17+
AUTHORITY = authority_template.format(
18+
tenant=b2c_tenant, user_flow=signupsignin_user_flow)
19+
20+
REDIRECT_PATH = "/account/auth" # Used for forming an absolute URL to your redirect URI.
21+
# The absolute URL must match the redirect URI you set
22+
# in the app's registration in the Azure portal.
23+
24+
# This is the API resource endpoint
25+
ENDPOINT = '' # Application ID URI of app registration in Azure portal
26+
27+
# These are the scopes you've exposed in the web API app registration in the Azure portal
28+
SCOPE = [] # Example with two exposed scopes: ["demo.read", "demo.write"]
29+
30+
SESSION_TYPE = "filesystem" # Specifies the token cache should be stored in server-side session
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import msal
2+
from flask import session
3+
4+
5+
def load_cache():
6+
cache = msal.SerializableTokenCache()
7+
if session.get("token_cache"):
8+
cache.deserialize(session["token_cache"])
9+
return cache
10+
11+
12+
def save_cache(cache):
13+
if cache.has_state_changed:
14+
session["token_cache"] = cache.serialize()

app/ch15_deploy/final/pypi_org/services/user_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_user(name: str, email: str, password: str) -> Optional[User]:
4141

4242

4343
def hash_text(text: str) -> str:
44-
hashed_text = crypto.encrypt(text, rounds=171204)
44+
hashed_text = crypto.encrypt(text, rounds=171_204)
4545
return hashed_text
4646

4747

0 commit comments

Comments
 (0)