Skip to content

Commit

Permalink
init frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
kwanok committed Mar 5, 2024
1 parent f7b3440 commit b79ff40
Show file tree
Hide file tree
Showing 55 changed files with 4,674 additions and 0 deletions.
2,318 changes: 2,318 additions & 0 deletions web/package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions web/package.json
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"
}
}
525 changes: 525 additions & 0 deletions web/poetry.lock

Large diffs are not rendered by default.

Empty file added web/project/__init__.py
Empty file.
Empty file added web/project/app/__init__.py
Empty file.
1 change: 1 addition & 0 deletions web/project/app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
6 changes: 6 additions & 0 deletions web/project/app/apps.py
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.
1 change: 1 addition & 0 deletions web/project/app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your models here.
1 change: 1 addition & 0 deletions web/project/app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
9 changes: 9 additions & 0 deletions web/project/app/urls.py
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"),
]
67 changes: 67 additions & 0 deletions web/project/app/views.py
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 added web/project/auth/__init__.py
Empty file.
1 change: 1 addition & 0 deletions web/project/auth/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
6 changes: 6 additions & 0 deletions web/project/auth/apps.py
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"
16 changes: 16 additions & 0 deletions web/project/auth/forms.py
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.
1 change: 1 addition & 0 deletions web/project/auth/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your models here.
1 change: 1 addition & 0 deletions web/project/auth/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
9 changes: 9 additions & 0 deletions web/project/auth/urls.py
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"),
]
41 changes: 41 additions & 0 deletions web/project/auth/views.py
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")
24 changes: 24 additions & 0 deletions web/project/jinja2conf.py
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)}">'
)
22 changes: 22 additions & 0 deletions web/project/manage.py
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 added web/project/project/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions web/project/project/asgi.py
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()
Loading

0 comments on commit b79ff40

Please sign in to comment.