Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Keep Context After Login #8

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/project/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def get_account_by_summoner_name(request: WSGIRequest):


def recommend_ai(request: WSGIRequest):
return render(request, "recommend/ai.html")
return render(request, "recommend/ai.html", {"user": request.user})
27 changes: 20 additions & 7 deletions web/project/auth/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from django.contrib.auth import authenticate, login, logout
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, reverse
from .forms import SigninForm, SignupForm


def signin(request):
_next = request.GET.get("next")

if request.user.is_authenticated:
return redirect("home")
if _next:
return redirect(_next)
else:
return redirect("home")

if request.method == "POST":
form = SigninForm(request.POST)
Expand All @@ -15,11 +20,14 @@ def signin(request):
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect("home")
if _next:
return redirect(_next)
else:
return redirect("home")
else:
form.add_error(None, "Invalid username or password")

return render(request, "auth/signin.html")
return render(request, "auth/signin.html", {"next": _next})


def signout(request):
Expand All @@ -29,13 +37,18 @@ def signout(request):


def signup(request):
_next = request.GET.get("next")

if request.user.is_authenticated:
return redirect("home")
if _next:
return redirect(_next)
else:
return redirect("home")

if request.method == "POST":
form = SignupForm(request.POST)
if form.is_valid():
form.save()
return redirect("auth:signin")
return redirect(reverse("auth:signin") + f"?next={_next}")

return render(request, "auth/signup.html")
return render(request, "auth/signup.html", {"next": _next})
4 changes: 2 additions & 2 deletions web/project/templates/auth/signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 class="mx-auto text-center text-2xl font-bold leading-9 h-10 w-auto">LOGIN</
<h2 class="mt-10 text-center text-xl font-bold leading-9 tracking-tight text-gray-900">최고의 듀오를 추천드릴게요 🔥</h2>
</div>
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" action="{{ url('auth:signin') }}" method="post">
<form class="space-y-6" action="{{ url('auth:signin') }}?next={{ next }}" method="post">
{{ csrf_input }}
<div>
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">아이디</label>
Expand Down Expand Up @@ -46,7 +46,7 @@ <h2 class="mt-10 text-center text-xl font-bold leading-9 tracking-tight text-gra
</form>
<p class="mt-10 text-center text-sm text-gray-500">
회원이 아니신가요? 무료로 가입해보세요.
<a href="{{ url('auth:signup') }}"
<a href="{{ url('auth:signup') }}?next={{ next }}"
class="font-semibold leading-6 text-stone-600 hover:text-stone-500">회원가입</a>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/project/templates/auth/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 class="mx-auto text-center text-2xl font-bold leading-9 h-10 w-auto">REGISTE
<h2 class="mt-10 text-center text-xl font-bold leading-9 tracking-tight text-gray-900">반가워요 😊</h2>
</div>
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" action="{{ url('auth:signup') }}" method="post">
<form class="space-y-6" action="{{ url('auth:signup') }}?next={{ next }}" method="post">
{{ csrf_input }}
<div>
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">이메일</label>
Expand Down Expand Up @@ -66,7 +66,7 @@ <h2 class="mt-10 text-center text-xl font-bold leading-9 tracking-tight text-gra
</form>
<p class="mt-10 text-center text-sm text-gray-500">
이미 회원이신가요?
<a href="{{ url('auth:signin') }}"
<a href="{{ url('auth:signin') }}?next={{ next }}"
class="font-semibold leading-6 text-stone-600 hover:text-stone-500">로그인</a>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/project/templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@
}

function signin() {
location.href = "{{ url('auth:signin') }}";
location.href = "{{ url('auth:signin') }}?next={{ request.path }}";
}

function signup() {
location.href = "{{ url('auth:signup') }}";
location.href = "{{ url('auth:signup') }}?next={{ request.path }}";
}

function signout() {
Expand Down
20 changes: 18 additions & 2 deletions web/project/templates/recommend/ai.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
| AI Recommend
{% endblock title %}
{% block content %}
<div class="flex justify-center items-center mt-64">
Hello
<div class="flex justify-center items-center mt-64 flex-col">
{% if not user.is_authenticated %}
<h1 class="text-4xl font-bold">안녕하세요, 방문자님</h1>
<p class="mt-8">
<a href="{{ url('auth:signin') }}" class="text-stone-500">로그인</a>을
하시면 AI 추천을 받아보실 수 있습니다.
</p>
{% elif not user.summoner_info %}
<h1 class="text-4xl font-bold">안녕하세요, {{ user.username }}님</h1>
<p class="mt-8">
라이엇 계정 연동을 통해 AI 추천을 받아보실 수 있습니다.
</p>
{% else %}
<h1 class="text-4xl font-bold">안녕하세요, {{ user.username }}님</h1>
<button class="mt-8 bg-stone-500 hover:bg-stone-700 text-white py-2 px-4 rounded">
AI 추천 시작하기
</button>
{% endif %}
</div>
{% endblock content %}
Loading