finished login openid button form
All checks were successful
Django Backend Validation / build (debian-latest, 3.11) (push) Successful in 19s
Django Backend Validation / build (debian-latest, 3.12) (push) Successful in 16s
Django Backend Validation / build (ubuntu-latest, 3.10) (push) Successful in 13s
Django Backend Validation / build (ubuntu-latest, 3.11) (push) Successful in 14s
Django Backend Validation / build (ubuntu-latest, 3.12) (push) Successful in 15s
Django Backend Validation / build (debian-latest, 3.10) (push) Successful in 14s

Signed-off-by: Jochen Mehlich <coding@jochenmehlich.de>
This commit is contained in:
Jochen Mehlich 2024-08-28 15:14:21 +02:00
parent 01300ba54a
commit 04d6cd0351
2 changed files with 32 additions and 15 deletions

View File

@ -9,8 +9,8 @@
Sign in to your account
</h1>
<form class="space-y-4 md:space-y-6" method="post">
<input type="hidden" name="auth_type" value="form">
{% csrf_token %}
<div>
<label for="username" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your username</label>
<input type="text" name="username" id="username" class="bg-gray-50 border border-gray-300 text-gray-900 rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="fooboar" required="">
@ -19,10 +19,24 @@
<label for="password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Password</label>
<input type="password" name="password" id="password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
</div>
<button type="submit" class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">Sign in</button>
<p class="text-sm font-light text-gray-500 dark:text-gray-400">
Dont have an account yet? <a href="#" class="font-medium text-primary-600 hover:underline dark:text-primary-500">Login</a>
</p>
<button type="submit" class="w-full inline-flex items-center justify-center p-0.5 me-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800">
<span class="w-full px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0">
Login
</span>
</button>
</form>
<form class="md:space-y-6" method="post">
<input type="hidden" name="auth_type" value="openid">
{% csrf_token %}
<div class="inline-flex items-center justify-center w-full">
<hr class="w-64 h-px my-8 bg-gray-200 border-0 dark:bg-gray-700">
<span class="absolute px-3 font-medium text-gray-900 -translate-x-1/2 bg-white left-1/2 dark:text-white dark:bg-gray-800">or</span>
</div>
<button class="w-full inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800">
<span class="w-full px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0">
Login with StuVe SSO
</span>
</button>
</form>
</div>
</div>

View File

@ -10,13 +10,16 @@ def login(request):
return render(request, "login.html")
elif request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = dauth.authenticate(request, username=username, password=password)
if user is not None:
dauth.login(request, user)
return redirect("/")
else:
form = LoginForm()
return render(request, "login.html", {"form": form})
auth_type = request.POST.get("auth_type")
if auth_type == "form":
if form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
user = dauth.authenticate(request, username=username, password=password)
if user is not None:
dauth.login(request, user)
return redirect("/")
else:
return render(request, "login.html", {"userError": True})
elif auth_type == "openid":
return render(request, "login.html")