Role management, login logic, and debug improvements. MariaDB login now uses correct syntax.

This commit is contained in:
2025-09-11 22:30:52 +03:00
parent b37c8bb58f
commit 9fc32adb23
18 changed files with 442 additions and 78 deletions

View File

@@ -8,10 +8,10 @@
<h3>Manage Users</h3>
<ul class="user-list">
{% for user in users %}
<li data-user-id="{{ user.id }}">
<li data-user-id="{{ user.id }}" data-username="{{ user.username }}" data-email="{{ user.email if user.email else '' }}" data-role="{{ user.role }}">
<span class="user-name">{{ user.username }}</span>
<span class="user-role">Role: {{ user.role }}</span>
<button class="btn edit-btn">Edit Rights</button>
<button class="btn edit-user-btn" data-user-id="{{ user.id }}" data-username="{{ user.username }}" data-email="{{ user.email if user.email else '' }}" data-role="{{ user.role }}">Edit User</button>
<button class="btn delete-btn">Delete User</button>
</li>
{% endfor %}
@@ -35,51 +35,37 @@
<button type="submit" class="btn">Save/Update External Database Info Settings</button>
</form>
</div>
<div class="card" style="margin-top: 32px;">
<h3>Edit Access Roles</h3>
<p>Manage which roles can view or execute functions on each app page and feature.</p>
<a href="{{ url_for('main.edit_access_roles') }}" class="btn">Edit Access Roles</a>
</div>
</div>
<!-- Popup for creating a new user -->
<div id="create-user-popup" class="popup">
<div class="popup-content">
<h3>Create User</h3>
<form id="create-user-form" method="POST" action="{{ url_for('main.create_user') }}">
<!-- Popup for creating/editing a user -->
<div id="user-popup" class="popup" style="display:none; position:fixed; top:0; left:0; width:100vw; height:100vh; background:var(--app-overlay-bg, rgba(30,41,59,0.85)); z-index:9999; align-items:center; justify-content:center;">
<div class="popup-content" style="margin:auto; padding:32px; border-radius:8px; box-shadow:0 2px 8px #333; min-width:320px; max-width:400px; text-align:center;">
<h3 id="user-popup-title">Create/Edit User</h3>
<form id="user-form" method="POST" action="{{ url_for('main.create_user') }}">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<label for="role">Role:</label>
<select id="role" name="role" required>
<option value="superadmin">Superadmin</option>
<option value="administrator">Administrator</option>
<option value="quality">Quality</option>
<option value="warehouse">Warehouse</option>
<option value="scan">Scan</option>
<option value="admin">Admin</option>
<option value="manager">Manager</option>
<option value="warehouse_manager">Warehouse Manager</option>
<option value="warehouse_worker">Warehouse Worker</option>
<option value="quality_manager">Quality Manager</option>
<option value="quality_worker">Quality Worker</option>
</select>
<button type="submit" class="btn">Create</button>
<button type="button" id="close-popup-btn" class="btn cancel-btn">Cancel</button>
</form>
</div>
</div>
<!-- Popup for editing a user -->
<div id="edit-user-popup" class="popup">
<div class="popup-content">
<h3>Edit User</h3>
<form id="edit-user-form" method="POST" action="{{ url_for('main.edit_user') }}">
<input type="hidden" id="edit-user-id" name="user_id">
<label for="edit-username">Username:</label>
<input type="text" id="edit-username" name="username" readonly>
<label for="edit-password">New Password:</label>
<input type="password" id="edit-password" name="password">
<label for="edit-role">Role:</label>
<select id="edit-role" name="role" required>
<option value="superadmin">Superadmin</option>
<option value="administrator">Administrator</option>
<option value="quality">Quality</option>
<option value="warehouse">Warehouse</option>
<option value="scan">Scan</option>
</select>
<button type="submit" class="btn">Update</button>
<button type="button" id="close-edit-popup-btn" class="btn cancel-btn">Cancel</button>
<button type="submit" class="btn">Save</button>
<button type="button" id="close-user-popup-btn" class="btn cancel-btn">Cancel</button>
</form>
</div>
</div>
@@ -95,4 +81,27 @@
</form>
</div>
</div>
<script>
document.getElementById('create-user-btn').onclick = function() {
document.getElementById('user-popup').style.display = 'flex';
document.getElementById('user-popup-title').innerText = 'Create User';
document.getElementById('user-form').reset();
document.getElementById('user-form').setAttribute('action', '{{ url_for("main.create_user") }}');
};
document.getElementById('close-user-popup-btn').onclick = function() {
document.getElementById('user-popup').style.display = 'none';
};
// Edit User button logic
Array.from(document.getElementsByClassName('edit-user-btn')).forEach(function(btn) {
btn.onclick = function() {
document.getElementById('user-popup').style.display = 'flex';
document.getElementById('user-popup-title').innerText = 'Edit User';
document.getElementById('username').value = btn.getAttribute('data-username');
document.getElementById('email').value = btn.getAttribute('data-email');
document.getElementById('role').value = btn.getAttribute('data-role');
document.getElementById('password').value = '';
document.getElementById('user-form').setAttribute('action', '/edit_user/' + btn.getAttribute('data-user-id'));
};
});
</script>
{% endblock %}