2022-06-10 11:52:54 +00:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.contrib.auth import authenticate, login, logout
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.views.decorators.csrf import csrf_protect
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
GREETINGS = {
|
|
|
|
"greeting": "Welcome to Hostea - Free Forge Ecosystem for Free Developers",
|
|
|
|
"features": [
|
|
|
|
"Fully managed",
|
|
|
|
"100% Free Software",
|
|
|
|
"Fully Self-Hostable",
|
|
|
|
"Observable and reliable",
|
|
|
|
"Federation when available",
|
|
|
|
"Radically transparent",
|
|
|
|
"Horizontal community",
|
|
|
|
"Run Hostea and become a service provider!",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGIN_CONTENT = {
|
|
|
|
"login_name": "Username or Email",
|
|
|
|
"action": "Login",
|
|
|
|
"password": "Password",
|
|
|
|
"forgot_password": "Forgot password?",
|
|
|
|
"register_prompt": "New to Hostea?",
|
|
|
|
"register_action_link_text": "Create an account",
|
|
|
|
"greetings": GREETINGS,
|
|
|
|
}
|
|
|
|
|
2022-06-10 12:02:29 +00:00
|
|
|
|
2022-06-10 11:52:54 +00:00
|
|
|
@csrf_protect
|
|
|
|
def login_view(request):
|
|
|
|
if request.method == "POST":
|
2022-06-10 12:02:29 +00:00
|
|
|
user = authenticate(
|
|
|
|
request,
|
|
|
|
username=request.POST["username"],
|
|
|
|
password=request.POST["password"],
|
|
|
|
)
|
2022-06-10 11:52:54 +00:00
|
|
|
if user is not None:
|
|
|
|
login(request, user)
|
|
|
|
print("user logged in")
|
|
|
|
if "next" in request.POST:
|
|
|
|
next_url = request.POST["next"]
|
|
|
|
if next_url:
|
|
|
|
return redirect(next_url)
|
2022-06-10 12:02:29 +00:00
|
|
|
return redirect(reverse("accounts.protected"))
|
2022-06-10 11:52:54 +00:00
|
|
|
else:
|
|
|
|
return HttpResponse("Login required")
|
|
|
|
|
|
|
|
ctx = LOGIN_CONTENT
|
|
|
|
if "next" in request.GET:
|
|
|
|
ctx["next"] = request.GET["next"]
|
|
|
|
|
|
|
|
return render(request, "accounts/auth/login.html", ctx)
|
|
|
|
|
2022-06-10 12:02:29 +00:00
|
|
|
|
2022-06-10 11:52:54 +00:00
|
|
|
@login_required
|
|
|
|
def protected_view(request):
|
|
|
|
return render(request, "accounts/protected.html")
|
|
|
|
|
2022-06-10 12:02:29 +00:00
|
|
|
|
2022-06-10 11:52:54 +00:00
|
|
|
@login_required
|
|
|
|
def logout_view(request):
|
|
|
|
logout(request)
|
2022-06-10 12:02:29 +00:00
|
|
|
return redirect(reverse("accounts.login"))
|
|
|
|
|
2022-06-10 11:52:54 +00:00
|
|
|
|
|
|
|
def public_view(request):
|
|
|
|
return render(request, "accounts/public.html")
|