diff options
author | Jannick <[email protected]> | 2024-04-30 14:54:22 +0200 |
---|---|---|
committer | Jannick <[email protected]> | 2024-04-30 14:54:22 +0200 |
commit | 46ed2f9e09d0425a6cb0cb29fd300006fd96adc3 (patch) | |
tree | 64293c3fa6f77ed5535a8be00ef1a48cbc5036f2 | |
parent | 22b0b52f8f98a68b08111802c4edcb30b692bcb0 (diff) |
Fetches all characters and added dropdown menu
The login shit now works, and we successfully fetch all the
users characters. There is also a dropdown menu on the join page,
featuring all chars.
-rw-r--r-- | app.py | 24 | ||||
-rw-r--r-- | views/join_form.html | 6 |
2 files changed, 26 insertions, 4 deletions
@@ -11,6 +11,9 @@ from bottle.ext import sqlite load_dotenv() +REGION = "eu" + +# OAuth2 variable declarations CLIENT_ID = os.environ.get("CLIENT_ID") # DOTENV ligger paa discorden, repoet er publkic saa det CLIENT_SECRET = os.environ.get("CLIENT_SECRET") # DOTENV PAHAHAH REDIRECT_URI = "https://localhost:8080/callback" @@ -50,7 +53,7 @@ def join_intro(): def battle(): state = secrets.token_urlsafe(16) response.set_cookie('oauth_state', state) - authorization_url = client.prepare_request_uri(AUTH_BASE_URL, redirect_uri=REDIRECT_URI, state=state) + authorization_url = client.prepare_request_uri(AUTH_BASE_URL, redirect_uri=REDIRECT_URI, state=state, scope="wow.profile") return redirect(authorization_url) @app.route('/callback') @@ -64,15 +67,30 @@ def join_form(): # # See: https://develop.battle.net/documentation/guides/regionality-and-apis#:~:text=Developers%20should%20use%20an%20accountId query_parameters = { - "region": "eu", + "region": REGION, } response = oauth2_session.get("https://oauth.battle.net/oauth/userinfo", params=query_parameters) response.raise_for_status() user_info = response.json() user_id = user_info["id"] + # do we have it? yes + query_parameters = { + "region": REGION, + "namespace": f"profile-{REGION}", + "locale": "en_US", + } + response = oauth2_session.get(f"https://{REGION}.api.blizzard.com/profile/user/wow", params=query_parameters) + response.raise_for_status() + data = response.json() + print(response.text) + characters = [] + for account in data["wow_accounts"]: + for character in account["characters"]: + characters.append(character) + # We pass the token retrieved here so it can be submitted with the rest of the application. - return template("join_form", user_id=user_id) + return template("join_form", user_id=user_id, characters=characters) @app.route("/callback", method="POST") def join_submission(db: sqlite3.Connection): diff --git a/views/join_form.html b/views/join_form.html index 440c993..c5b9352 100644 --- a/views/join_form.html +++ b/views/join_form.html @@ -27,7 +27,11 @@ If your application is accepted, we will accept your in-game guild application. Please make sure you have supmitted such an application in the game's UI. </p> - <input class="signup__input" type="text" id="name" name="name" required placeholder="PoopenFarten43" minlength="2" maxlength="12"> + <select class="signup__input" id="name" name="name" required> + {% for character in characters %} + <option value="{{ character['id'] | e }}">{{ character['name'] | e }}</option> + {% endfor %} + </select> </div> <div class="signup__box"> <label class="signup__label" for="preferredRole">Preferred role</label> |