add app user management allauth

This commit is contained in:
2025-02-01 19:16:33 +01:00
parent c13049a30f
commit e3ae8300f1
55 changed files with 1147 additions and 465 deletions

10
templates/404.html Normal file
View File

@@ -0,0 +1,10 @@
{% extends 'layouts/blank.html' %} {% block content %}
<div class="container text-center py-5">
<h1 class="display-1">Page not found</h1>
<p class="my-4 text-muted">
Error 404: This page doesn't exist or is unavailable
</p>
</div>
{% endblock %}

View File

@@ -0,0 +1,44 @@
{% extends "account/base_entrance.html" %}
{% load i18n %}
{% load allauth account %}
{% block head_title %}
{% trans "Sign In" %}
{% endblock head_title%}
{% block content %}
<h1 class="mb-4">{% trans "Sign In" %}</h1>
<p class="mb-4">
If you have not created an account yet, then please
<a
href="{% url 'account_signup' %}?next={% url 'profile-onboarding' %}"
class="text-decoration-none"
>sign up</a
>
first.
</p>
{% url 'account_login' as login_url %}
<form method="post" action="{{ login_url }}" class="mb-4">
{% csrf_token %}
<div class="mb-3">
{% for field in form %}
<div class="form-group">
{{ field }} {% if field.errors %}
<div class="text-danger">{{ field.errors }}</div>
{% endif %}
</div>
{% endfor %}
</div>
{% if redirect_field_value %}
<input
type="hidden"
name="{{ redirect_field_name }}"
value="{{ redirect_field_value }}"
/>
{% endif %}
<button type="submit" class="btn btn-primary">{% trans "Sign In" %}</button>
</form>
{% if SOCIALACCOUNT_ENABLED %}
{% include "socialaccount/snippets/login.html" with page_layout="entrance" %}
{% endif %}
{% endblock content %}

View File

View File

@@ -0,0 +1,12 @@
{% extends 'layouts/box.html' %} {% block class %}allauth{% endblock %}
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-md-8 col-lg-6">
<div class="bg-white rounded-3 p-4 p-md-5 shadow-lg">
{% block allauth_content %} {% endblock %}
</div>
</div>
</div>
</div>
{% endblock %}

35
templates/base.html Normal file
View File

@@ -0,0 +1,35 @@
{% load static %}
{% load django_htmx %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Django Template">
<title>Project Title</title>
<link rel="icon" type="image/x-icon" href="{% static 'favicon.ico' %}">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" defer></script>
<!-- HTMX -->
<script src="https://unpkg.com/htmx.org@2.0.4" defer></script>
{% django_htmx_script %}
<!-- Custom Styles -->
<style>
.dropdown-menu { min-width: 200px; }
</style>
</head>
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
{% include 'includes/messages.html' %}
{% include 'includes/header.html' %}
{% block layout %}
{% endblock %}
{% block javascript %}{% endblock %}
</body>
</html>

7
templates/home.html Normal file
View File

@@ -0,0 +1,7 @@
{% extends 'layouts/blank.html' %} {% block content %}
<div class="container py-5">
<h1>New Project</h1>
</div>
{% endblock %}

View File

@@ -0,0 +1,38 @@
{% load static %}
<header class="d-flex align-items-center justify-content-between bg-dark text-white py-3 px-4 sticky-top z-40">
<div>
<a class="d-flex align-items-center gap-2 text-decoration-none text-white" href="/">
<img class="h-6" src="{% static 'images/ase-logo.png' %}" alt="ASE" height="40"/>
<span class="text-lg fw-bold">MQTT User Management</span>
</a>
</div>
<nav class="position-relative">
<ul class="nav nav-pills align-items-center">
{% if request.user.is_authenticated %}
<li class="nav-item">
<a class="nav-link text-white" href="/">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle d-flex align-items-center gap-2 text-white" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img class="h-8 w-8 rounded-circle object-cover" src="{{ request.user.profile.avatar }}" alt="Avatar" height="40"/>
{{ request.user.profile.name }}
</a>
<ul class="dropdown-menu dropdown-menu-end shadow-lg" style="min-width: 200px;">
<li><a class="dropdown-item" href="{% url 'profile' %}">My Profile</a></li>
<li><a class="dropdown-item" href="{% url 'profile-edit' %}">Edit Profile</a></li>
<li><a class="dropdown-item" href="{% url 'profile-settings' %}">Settings</a></li>
<li><hr class="dropdown-divider" /></li>
<li><a class="dropdown-item" href="{% url 'account_logout' %}">Log Out</a></li>
</ul>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link text-white" href="{% url 'account_login' %}">Login</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="{% url 'account_signup' %}?next={% url 'profile-onboarding' %}">Signup</a>
</li>
{% endif %}
</ul>
</nav>
</header>

View File

@@ -0,0 +1,29 @@
<messages>
{% if messages %}
<div>
{% for message in messages %}
<div
class="position-fixed top-0 start-50 translate-middle-x mt-3 z-50"
style="width: 100%; max-width: 576px"
>
<div
class="alert alert-{{ message.tags }} alert-dismissible fade show"
role="alert"
>
<div class="d-flex align-items-center">
<div class="me-3">
<div class="text-lg">{{ message }}</div>
</div>
<button
type="button"
class="btn-close"
data-bs-dismiss="alert"
aria-label="Close"
></button>
</div>
</div>
</div>
{% endfor %}
</div>
{% endif %}
</messages>

View File

@@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% block layout %}
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-md-10 col-lg-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,11 @@
{% extends 'base.html' %} {% block layout %}
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-md-8 col-lg-6">
<div class="bg-white rounded-3 p-4 p-md-5 shadow-lg">
{% block content %} {% endblock %}
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,8 @@
<button
class="btn btn-warning btn-sm"
hx-post="/user/disable/{{user.slug}}"
hx-target="#user-status"
hx-swap="innerHTML"
>
Disable
</button>

View File

@@ -0,0 +1,18 @@
<form
action="{% url 'profile-emailchange' %}"
method="post"
class="d-flex gap-2"
autocomplete="off"
>
{% csrf_token %} {% for field in form %} {{ field }} {% endfor %}
<button class="btn btn-dark" type="submit">Submit</button>
</form>
<a
hx-swap-oob="true"
id="email-edit"
href="{% url 'profile-settings' %}"
class="text-primary text-decoration-none"
>
Cancel
</a>

View File

@@ -0,0 +1,8 @@
<button
class="btn btn-warning btn-sm"
hx-post="/user/enable/{{user.slug}}"
hx-target="#user-status"
hx-swap="innerHTML"
>
Enable
</button>

View File

@@ -0,0 +1,59 @@
{% extends 'layouts/blank.html' %} {% block content %}
<!-- Mostra i messaggi di errore o successo -->
{% if messages %}
<div>
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<!-- Form per la creazione dell'utente -->
<h1>Add User</h1>
<form method="post" hx-post="/create_user" hx-target="#content">
{% csrf_token %}
<div class="mb-3">
<label for="site" class="form-label">Site</label>
<input type="text" class="form-control" id="site" name="site" required />
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input
type="text"
class="form-control"
id="username"
name="username"
required
/>
</div>
<div class="mb-3">
<label for="clientId" class="form-label">Client ID</label>
<input
type="text"
class="form-control"
id="clientId"
name="clientId"
required
/>
</div>
<div class="mb-3">
<label for="topic" class="form-label">Topic</label>
<input type="text" class="form-control" id="topic" name="topic" required />
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input
type="password"
class="form-control"
id="password"
name="password"
required
/>
</div>
<button type="submit" class="btn btn-primary">Create</button>
</form>
{% endblock content %}

View File

@@ -0,0 +1,60 @@
{% extends 'layouts/blank.html' %} {% block content %}
<!-- Mostra i messaggi di errore o successo -->
{% if messages %}
<div>
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<h1>Add User</h1>
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label for="site" class="form-label">Site</label>
<input type="text" class="form-control" id="site" name="site" required />
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input
type="text"
class="form-control"
id="username"
name="username"
required
/>
</div>
<div class="mb-3">
<label for="clientId" class="form-label">Client ID</label>
<input
type="text"
class="form-control"
id="clientId"
name="clientId"
required
/>
</div>
<div class="mb-3">
<label for="topic" class="form-label">Topic</label>
<input type="text" class="form-control" id="topic" name="topic" required />
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input
type="password"
class="form-control"
id="password"
name="password"
required
/>
</div>
<button type="submit" class="btn btn-primary">Create</button>
</form>
<!-- Risultato della creazione -->
<div id="result"></div>
{% endblock content%}

View File

@@ -0,0 +1,52 @@
{% extends 'layouts/blank.html' %} {% block content %}
<h1>Edit User</h1>
<form method="post">
{% csrf_token %}
<input type="hidden" name="id" value="{{ user.id }}" />
<div class="mb-3">
<label for="site" class="form-label">Site</label>
<input
type="text"
class="form-control"
id="site"
name="site"
value="{{ user.site }}"
required
/>
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input
type="text"
class="form-control"
id="username"
name="username"
value="{{ user.username }}"
required
/>
</div>
<div class="mb-3">
<label for="clientId" class="form-label">Client ID</label>
<input
type="text"
class="form-control"
id="clientId"
name="clientId"
value="{{ user.client_id }}"
required
/>
</div>
<div class="mb-3">
<label for="topic" class="form-label">Topic</label>
<input
type="text"
class="form-control"
id="topic"
name="topic"
value="{{ user.topic }}"
required
/>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
{% endblock content %}

View File

@@ -0,0 +1,57 @@
{% extends 'layouts/blank.html' %} {% block content %}
<!-- Mostra i messaggi di errore o successo -->
{% if messages %}
<div>
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<h1>List Mosquitto Users</h1>
<a href="{% url 'create_user' %}">
<button class="btn btn-primary mb-3">Add User</button>
</a>
<table class="table table-striped">
<thead>
<tr>
<th>Site</th>
<th>Username</th>
<th>Client ID</th>
<th>Topic</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{user.site}}</td>
<td>
<a href="{% url 'edit_user' user.slug %}">{{user.username}}</a
>
</td>
<td>{{user.client_id}}</td>
<td>{{user.topic}}</td>
<td id="user-status">
{% if user.status == "enabled" %}
<a href="{% url 'disable_user' user.slug %}">
<button class="btn btn-danger btn-sm">Disable</button>
</a>
{% else %}
<a href="{% url 'enable_user' user.slug %}">
<button class="btn btn-warning btn-sm">Enable</button>
</a>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="5"><i> No users </i></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock content %}

View File

@@ -0,0 +1,20 @@
{% extends 'layouts/blank.html' %} {% block content %}
<h1>Role Permissions</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Permission</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<!-- Role permissions will be dynamically loaded here -->
{{#each permissions}}
<tr>
<td>{{ this.permission }}</td>
<td>{{ this.description }}</td>
</tr>
{{/each}}
</tbody>
</table>
{% endblock content %}