forked from enviPath/enviPy
minor
This commit is contained in:
@ -90,6 +90,7 @@ def login(request):
|
|||||||
if username != request.POST.get("username"):
|
if username != request.POST.get("username"):
|
||||||
context["message"] = "Login failed!"
|
context["message"] = "Login failed!"
|
||||||
return render(request, "static/login.html", context)
|
return render(request, "static/login.html", context)
|
||||||
|
|
||||||
password = request.POST.get("password")
|
password = request.POST.get("password")
|
||||||
|
|
||||||
# Get email for username and check if the account is active
|
# Get email for username and check if the account is active
|
||||||
@ -104,6 +105,7 @@ def login(request):
|
|||||||
except get_user_model().DoesNotExist:
|
except get_user_model().DoesNotExist:
|
||||||
context["message"] = "Login failed!"
|
context["message"] = "Login failed!"
|
||||||
return render(request, "static/login.html", context)
|
return render(request, "static/login.html", context)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = authenticate(username=email, password=password)
|
user = authenticate(username=email, password=password)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -144,8 +146,10 @@ def register(request):
|
|||||||
# Redirect to unified login page with signup tab
|
# Redirect to unified login page with signup tab
|
||||||
next_url = request.GET.get("next", "")
|
next_url = request.GET.get("next", "")
|
||||||
redirect_url = reverse("login") + "#signup"
|
redirect_url = reverse("login") + "#signup"
|
||||||
|
|
||||||
if next_url:
|
if next_url:
|
||||||
redirect_url += f"?next={next_url}"
|
redirect_url += f"?next={next_url}"
|
||||||
|
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
context["title"] = "enviPath"
|
context["title"] = "enviPath"
|
||||||
@ -159,18 +163,18 @@ def register(request):
|
|||||||
|
|
||||||
if not (username and email and password):
|
if not (username and email and password):
|
||||||
context["message"] = "Invalid username/email/password"
|
context["message"] = "Invalid username/email/password"
|
||||||
return render(request, "static/register.html", context)
|
return render(request, "static/login.html", context)
|
||||||
|
|
||||||
if password != rpassword or password == "":
|
if password != rpassword or password == "":
|
||||||
context["message"] = "Registration failed, provided passwords differ!"
|
context["message"] = "Registration failed, provided passwords differ!"
|
||||||
return render(request, "static/register.html", context)
|
return render(request, "static/login.html", context)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u = UserManager.create_user(username, email, password)
|
u = UserManager.create_user(username, email, password)
|
||||||
logger.info(f"Created user {u.username} ({u.pk})")
|
logger.info(f"Created user {u.username} ({u.pk})")
|
||||||
except Exception:
|
except Exception:
|
||||||
context["message"] = "Registration failed! Couldn't create User Account."
|
context["message"] = "Registration failed! Couldn't create User Account."
|
||||||
return render(request, "static/register.html", context)
|
return render(request, "static/login.html", context)
|
||||||
|
|
||||||
if s.ADMIN_APPROVAL_REQUIRED:
|
if s.ADMIN_APPROVAL_REQUIRED:
|
||||||
context["success_message"] = (
|
context["success_message"] = (
|
||||||
|
|||||||
@ -3,44 +3,28 @@
|
|||||||
{% block title %}enviPath - Sign In{% endblock %}
|
{% block title %}enviPath - Sign In{% endblock %}
|
||||||
|
|
||||||
{% block extra_styles %}
|
{% block extra_styles %}
|
||||||
/* Tab styling */
|
/* Tab styling */ .tab-content { display: none; } .tab-content.active {
|
||||||
.tab-content {
|
display: block; } input[type="radio"].tab-radio { display: none; } .tab-label
|
||||||
display: none;
|
{ cursor: pointer; padding: 0.75rem 1.5rem; border-bottom: 2px solid
|
||||||
}
|
transparent; transition: all 0.3s ease; } .tab-label:hover { background-color:
|
||||||
|
rgba(0, 0, 0, 0.05); } input[type="radio"].tab-radio:checked + .tab-label {
|
||||||
.tab-content.active {
|
border-bottom-color: #3b82f6; font-weight: 600; }
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type="radio"].tab-radio {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tab-label {
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 0.75rem 1.5rem;
|
|
||||||
border-bottom: 2px solid transparent;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tab-label:hover {
|
|
||||||
background-color: rgba(0, 0, 0, 0.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type="radio"].tab-radio:checked + .tab-label {
|
|
||||||
border-bottom-color: #3b82f6;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<!-- Tab Navigation -->
|
<!-- Tab Navigation -->
|
||||||
<div class="border-b border-base-300 mb-6">
|
<div class="border-b border-base-300 mb-6">
|
||||||
<div class="flex justify-start">
|
<div class="flex justify-start">
|
||||||
<input type="radio" name="auth-tab" id="tab-signin" class="tab-radio" checked>
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="auth-tab"
|
||||||
|
id="tab-signin"
|
||||||
|
class="tab-radio"
|
||||||
|
checked
|
||||||
|
/>
|
||||||
<label for="tab-signin" class="tab-label">Sign In</label>
|
<label for="tab-signin" class="tab-label">Sign In</label>
|
||||||
|
|
||||||
<input type="radio" name="auth-tab" id="tab-signup" class="tab-radio">
|
<input type="radio" name="auth-tab" id="tab-signup" class="tab-radio" />
|
||||||
<label for="tab-signup" class="tab-label">Register</label>
|
<label for="tab-signup" class="tab-label">Register</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -55,45 +39,73 @@ input[type="radio"].tab-radio:checked + .tab-label {
|
|||||||
<label class="label" for="username">
|
<label class="label" for="username">
|
||||||
<span class="label-text">Username</span>
|
<span class="label-text">Username</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="username" name="username" placeholder="username"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="username">
|
type="text"
|
||||||
|
id="username"
|
||||||
|
name="username"
|
||||||
|
placeholder="username"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="username"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label class="label" for="passwordinput">
|
<label class="label" for="passwordinput">
|
||||||
<span class="label-text">Password</span>
|
<span class="label-text">Password</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="passwordinput" name="password" placeholder="••••••••"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="current-password">
|
type="password"
|
||||||
|
id="passwordinput"
|
||||||
|
name="password"
|
||||||
|
placeholder="••••••••"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="current-password"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<a href="{% url 'password_reset' %}" class="link link-primary text-sm">Forgot password?</a>
|
<a href="{% url 'password_reset' %}" class="link link-primary text-sm"
|
||||||
|
>Forgot password?</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="next" value="{{ next }}" />
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
|
||||||
<button type="submit" name="signin" class="btn btn-primary w-full">Sign In</button>
|
<button type="submit" name="signin" class="btn btn-primary w-full">
|
||||||
|
Sign In
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Register Tab -->
|
<!-- Register Tab -->
|
||||||
<div id="content-signup" class="tab-content">
|
<div id="content-signup" class="tab-content">
|
||||||
<div class="alert alert-info mb-4 text-sm">
|
<div class="alert alert-info mb-4 text-sm">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="h-6 w-6 shrink-0 stroke-current">
|
<svg
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
class="h-6 w-6 shrink-0 stroke-current"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
<div>
|
<div>
|
||||||
<div class="font-bold">Password Requirements</div>
|
<div class="font-bold">Password Requirements</div>
|
||||||
<div class="text-xs mt-1">
|
<div class="text-xs mt-1">
|
||||||
• 8 to 30 characters<br>
|
• 8 to 30 characters<br />
|
||||||
• Upper and lower case letters<br>
|
• Upper and lower case letters<br />
|
||||||
• Digits and special characters (_, -, +)
|
• Digits and special characters (_, -, +)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post" action="{% url 'login' %}" class="space-y-4">
|
<form method="post" action="{% url 'register' %}" class="space-y-4">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="register" value="true" />
|
<input type="hidden" name="register" value="true" />
|
||||||
|
|
||||||
@ -101,45 +113,93 @@ input[type="radio"].tab-radio:checked + .tab-label {
|
|||||||
<label class="label" for="userid">
|
<label class="label" for="userid">
|
||||||
<span class="label-text">Username</span>
|
<span class="label-text">Username</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="userid" name="username" placeholder="username"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="username">
|
type="text"
|
||||||
|
id="userid"
|
||||||
|
name="username"
|
||||||
|
placeholder="username"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="username"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label class="label" for="email">
|
<label class="label" for="email">
|
||||||
<span class="label-text">Email</span>
|
<span class="label-text">Email</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="email" id="email" name="email" placeholder="user@envipath.org"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="email">
|
type="email"
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
placeholder="user@envipath.org"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="email"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label class="label" for="password">
|
<label class="label" for="password">
|
||||||
<span class="label-text">Password</span>
|
<span class="label-text">Password</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="password" name="password" placeholder="••••••••"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="new-password">
|
type="password"
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
placeholder="••••••••"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label class="label" for="rpassword">
|
<label class="label" for="rpassword">
|
||||||
<span class="label-text">Repeat Password</span>
|
<span class="label-text">Repeat Password</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="rpassword" name="rpassword" placeholder="••••••••"
|
<input
|
||||||
class="input input-bordered w-full" required autocomplete="new-password">
|
type="password"
|
||||||
|
id="rpassword"
|
||||||
|
name="rpassword"
|
||||||
|
placeholder="••••••••"
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
required
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="next" value="{{ next }}" />
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
|
||||||
<button type="submit" name="confirmsignup" class="btn btn-success w-full">Sign Up</button>
|
<button type="submit" name="confirmsignup" class="btn btn-success w-full">
|
||||||
|
Sign Up
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Why Register Section -->
|
<!-- Why Register Section -->
|
||||||
<div class="mt-6 p-4 bg-base-200 rounded-lg">
|
<div class="mt-6 p-4 bg-base-200 rounded-lg">
|
||||||
<h3 class="font-semibold mb-2">Why register?</h3>
|
<h3 class="font-semibold mb-2">Why register?</h3>
|
||||||
<p class="text-sm mb-2"> enviPath is free for academic research and educational purposes. However, we require registration to ensure the security of the platform and to prevent abuse.</p>
|
<p class="text-sm mb-2">
|
||||||
|
enviPath is free for academic research and educational purposes.
|
||||||
|
However, we require registration to ensure the security of the platform
|
||||||
|
and to prevent abuse.
|
||||||
|
</p>
|
||||||
<p class="text-sm mt-3">
|
<p class="text-sm mt-3">
|
||||||
Questions? Check our <a href="https://wiki.envipath.org/" target="_blank" class="link link-primary">documentation</a> or the <a href="https://community.envipath.org/" target="_blank" class="link link-primary">community forums</a>.
|
Questions? Check our
|
||||||
|
<a
|
||||||
|
href="https://wiki.envipath.org/"
|
||||||
|
target="_blank"
|
||||||
|
class="link link-primary"
|
||||||
|
>documentation</a
|
||||||
|
>
|
||||||
|
or the
|
||||||
|
<a
|
||||||
|
href="https://community.envipath.org/"
|
||||||
|
target="_blank"
|
||||||
|
class="link link-primary"
|
||||||
|
>community forums</a
|
||||||
|
>.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -147,28 +207,28 @@ input[type="radio"].tab-radio:checked + .tab-label {
|
|||||||
{% block extra_scripts %}
|
{% block extra_scripts %}
|
||||||
<script>
|
<script>
|
||||||
// Tab switching functionality
|
// Tab switching functionality
|
||||||
document.querySelectorAll('input[name="auth-tab"]').forEach(radio => {
|
document.querySelectorAll('input[name="auth-tab"]').forEach((radio) => {
|
||||||
radio.addEventListener('change', function() {
|
radio.addEventListener("change", function () {
|
||||||
// Hide all content
|
// Hide all content
|
||||||
document.querySelectorAll('.tab-content').forEach(content => {
|
document.querySelectorAll(".tab-content").forEach((content) => {
|
||||||
content.classList.remove('active');
|
content.classList.remove("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show selected content
|
// Show selected content
|
||||||
const contentId = 'content-' + this.id.replace('tab-', '');
|
const contentId = "content-" + this.id.replace("tab-", "");
|
||||||
document.getElementById(contentId).classList.add('active');
|
document.getElementById(contentId).classList.add("active");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for hash in URL to auto-select tab
|
// Check for hash in URL to auto-select tab
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener("DOMContentLoaded", function () {
|
||||||
const hash = window.location.hash.substring(1); // Remove the # symbol
|
const hash = window.location.hash.substring(1); // Remove the # symbol
|
||||||
if (hash === 'signup' || hash === 'signin') {
|
if (hash === "signup" || hash === "signin") {
|
||||||
const tabRadio = document.getElementById('tab-' + hash);
|
const tabRadio = document.getElementById("tab-" + hash);
|
||||||
if (tabRadio) {
|
if (tabRadio) {
|
||||||
tabRadio.checked = true;
|
tabRadio.checked = true;
|
||||||
// Trigger change event to show correct content
|
// Trigger change event to show correct content
|
||||||
tabRadio.dispatchEvent(new Event('change'));
|
tabRadio.dispatchEvent(new Event("change"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user