-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
4,674 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "web", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"tailwindcss": "^3.4.1" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AppConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "app" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from .views import index, get_account_by_summoner_name, recommend_ai, riot_txt | ||
|
||
urlpatterns = [ | ||
path("riot.txt", riot_txt), | ||
path("", index, name="home"), | ||
path("summoner/", get_account_by_summoner_name, name="summoner"), | ||
path("recommend-ai/", recommend_ai, name="recommend-ai"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
from django.shortcuts import redirect, render | ||
from django.core.handlers.wsgi import WSGIRequest | ||
import requests | ||
|
||
from users.models import SummonerInfo | ||
|
||
|
||
def riot_txt(request: WSGIRequest): | ||
return render(request, "riot.txt") | ||
|
||
|
||
def index(request: WSGIRequest): | ||
return render( | ||
request, | ||
"index.html", | ||
{"user": request.user, "login_url": "http://localhost:8000/accounts/login"}, | ||
) | ||
|
||
|
||
def authorize(request: WSGIRequest): | ||
provider = "https://auth.riotgames.com" | ||
|
||
redirect_uri = "http://localhost:8000/oauth2-callback" | ||
client_id = "" | ||
response_type = "code" | ||
scope = "openid" | ||
|
||
url = f"{provider}/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type={response_type}&scope={scope}" | ||
|
||
return redirect(url) | ||
|
||
|
||
def get_account_by_summoner_name(request: WSGIRequest): | ||
summoner_name = request.GET.get("summoner_name") | ||
if SummonerInfo.objects.filter(name=summoner_name).exists(): | ||
summoner_info = SummonerInfo.objects.get(name=summoner_name) | ||
|
||
return render(request, "summoner/index.html", {"summoner": summoner_info}) | ||
|
||
url = f"https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/{summoner_name}" | ||
api_key = os.environ.get("RIOT_API_KEY") | ||
|
||
response = requests.get(url, headers={"X-Riot-Token": api_key}) | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
|
||
summoner_info = SummonerInfo( | ||
id=data["id"], | ||
account_id=data["accountId"], | ||
profile_icon_id=data["profileIconId"], | ||
revision_date=data["revisionDate"], | ||
name=data["name"], | ||
puuid=data["puuid"], | ||
summoner_level=data["summonerLevel"], | ||
) | ||
|
||
summoner_info.save() | ||
|
||
return render(request, "summoner/index.html", {"summoner": summoner_info}) | ||
|
||
return render(request, "summoner/index.html", {"error": response.json()}) | ||
|
||
|
||
def recommend_ai(request: WSGIRequest): | ||
return render(request, "recommend/ai.html") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "auth" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django import forms | ||
from django.contrib.auth.forms import UserCreationForm | ||
from users.models import AppUser | ||
|
||
|
||
class SignupForm(UserCreationForm): | ||
email = forms.EmailField(max_length=200, help_text="Required") | ||
|
||
class Meta: | ||
model = AppUser | ||
fields = ("username", "email", "password1", "password2") | ||
|
||
|
||
class SigninForm(forms.Form): | ||
username = forms.CharField(max_length=200) | ||
password = forms.CharField(widget=forms.PasswordInput) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from .views import signin, signout, signup | ||
|
||
app_name = "auth" | ||
urlpatterns = [ | ||
path("signin/", signin, name="signin"), | ||
path("signup/", signup, name="signup"), | ||
path("signout/", signout, name="signout"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.contrib.auth import authenticate, login, logout | ||
from django.shortcuts import render, redirect | ||
from .forms import SigninForm, SignupForm | ||
|
||
|
||
def signin(request): | ||
if request.user.is_authenticated: | ||
return redirect("home") | ||
|
||
if request.method == "POST": | ||
form = SigninForm(request.POST) | ||
if form.is_valid(): | ||
username = form.cleaned_data["username"] | ||
password = form.cleaned_data["password"] | ||
user = authenticate(request, username=username, password=password) | ||
if user is not None: | ||
login(request, user) | ||
return redirect("home") | ||
else: | ||
form.add_error(None, "Invalid username or password") | ||
|
||
return render(request, "auth/signin.html") | ||
|
||
|
||
def signout(request): | ||
logout(request) | ||
|
||
return redirect("home") | ||
|
||
|
||
def signup(request): | ||
if request.user.is_authenticated: | ||
return redirect("home") | ||
|
||
if request.method == "POST": | ||
form = SignupForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect("auth:signin") | ||
|
||
return render(request, "auth/signup.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.middleware.csrf import get_token | ||
from django.template.backends.jinja2 import jinja2 | ||
from jinja2 import Environment | ||
from django.urls import reverse | ||
|
||
STATIC_PREFIX = "/static/" | ||
|
||
|
||
def environment(**options): | ||
env = Environment(**options) | ||
env.globals.update( | ||
{ | ||
"static": STATIC_PREFIX, | ||
"csrf_input": csrf_input, | ||
"url": reverse, | ||
} | ||
) | ||
return env | ||
|
||
|
||
def csrf_input(request): | ||
return jinja2.Markup( | ||
f'<input type="hidden" name="csrfmiddlewaretoken" value="{get_token(request)}">' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for project project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.