- Add tech user management (JSON-backed CRUD with PIN auth) - Dual login: tabbed Tech Login (username+PIN) / Admin Login (NC credentials) - Admin panel: tappable user list with detail modal (enable/disable, reset PIN, reset NC password, delete) - Auto-provision Nextcloud accounts for tech users - Admin guard: tech users redirected away from admin panel - New data volume for persistent tech_users.json storage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
457 lines
11 KiB
HTML
457 lines
11 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Admin - NextSnap{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container">
|
|
<div class="admin-header">
|
|
<h2>Admin Panel</h2>
|
|
</div>
|
|
|
|
<!-- Add Tech User Form -->
|
|
<div class="admin-section">
|
|
<h3>Add Tech User</h3>
|
|
<form id="add-tech-user-form" class="user-form">
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="new-tech-username">Username *</label>
|
|
<input type="text" id="new-tech-username" required placeholder="jsmith" autocapitalize="none" autocorrect="off">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="new-tech-displayname">Display Name</label>
|
|
<input type="text" id="new-tech-displayname" placeholder="John Smith">
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="new-tech-pin">PIN * (min 4 digits)</label>
|
|
<input type="text" id="new-tech-pin" required placeholder="••••" inputmode="numeric">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="new-tech-pin-confirm">Confirm PIN *</label>
|
|
<input type="text" id="new-tech-pin-confirm" required placeholder="••••" inputmode="numeric">
|
|
</div>
|
|
</div>
|
|
<div class="form-error" id="tech-form-error" style="display: none;"></div>
|
|
<div class="form-success" id="tech-form-success" style="display: none;"></div>
|
|
<button type="submit" class="btn btn-primary" id="tech-submit-btn">Create Tech User</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Tech User List -->
|
|
<div class="admin-section">
|
|
<h3>Tech Users</h3>
|
|
<div class="loading-msg" id="tech-loading-msg" style="display: none;">Loading tech users...</div>
|
|
<div class="error-msg" id="tech-error-msg" style="display: none;"></div>
|
|
<div id="tech-user-list" class="user-list"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- User Detail Modal -->
|
|
<div class="modal" id="user-modal" style="display: none;">
|
|
<div class="modal-content">
|
|
<h3 id="user-modal-title"></h3>
|
|
<p id="user-modal-displayname" class="modal-subtitle"></p>
|
|
|
|
<div class="modal-detail">
|
|
<label>NC Password</label>
|
|
<div class="nc-password-row">
|
|
<span class="pw-text" id="user-modal-pw" data-masked="true"></span>
|
|
<button class="btn-small-action" id="user-modal-pw-toggle">Show</button>
|
|
<button class="btn-small-action" id="user-modal-pw-copy">Copy</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal-detail">
|
|
<label>Status</label>
|
|
<span id="user-modal-status" class="badge"></span>
|
|
</div>
|
|
|
|
<div class="modal-action-list">
|
|
<button class="btn btn-block" id="user-modal-toggle-btn"></button>
|
|
<button class="btn btn-block btn-secondary" id="user-modal-pin-btn">Reset PIN</button>
|
|
<button class="btn btn-block btn-secondary" id="user-modal-resetpw-btn">Reset NC Password</button>
|
|
<button class="btn btn-block btn-danger" id="user-modal-delete-btn">Delete User</button>
|
|
</div>
|
|
|
|
<button class="btn btn-block btn-tertiary" id="user-modal-close">Close</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Reset PIN Modal -->
|
|
<div class="modal" id="pin-modal" style="display: none;">
|
|
<div class="modal-content">
|
|
<h3>Reset PIN for <span id="pin-modal-username"></span></h3>
|
|
<div class="form-group" style="margin-top: 1rem;">
|
|
<label for="reset-pin">New PIN (min 4 digits)</label>
|
|
<input type="text" id="reset-pin" placeholder="••••" inputmode="numeric" class="form-group-input">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="reset-pin-confirm">Confirm PIN</label>
|
|
<input type="text" id="reset-pin-confirm" placeholder="••••" inputmode="numeric" class="form-group-input">
|
|
</div>
|
|
<div class="form-error" id="pin-modal-error" style="display: none;"></div>
|
|
<div class="modal-actions">
|
|
<button class="btn btn-secondary" id="pin-modal-cancel">Cancel</button>
|
|
<button class="btn btn-primary" id="confirm-pin-reset">Reset PIN</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirm Modal (generic) -->
|
|
<div class="modal" id="confirm-modal" style="display: none;">
|
|
<div class="modal-content">
|
|
<h3 id="confirm-modal-title"></h3>
|
|
<p id="confirm-modal-msg"></p>
|
|
<div class="form-error" id="confirm-modal-error" style="display: none;"></div>
|
|
<div class="modal-actions">
|
|
<button class="btn btn-secondary" id="confirm-modal-cancel">Cancel</button>
|
|
<button class="btn btn-danger" id="confirm-modal-ok">Confirm</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Toast Notification -->
|
|
<div id="toast" class="toast" style="display: none;"></div>
|
|
{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
.admin-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem 0;
|
|
border-bottom: 1px solid var(--bg-tertiary);
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.admin-header h2 {
|
|
margin: 0;
|
|
}
|
|
|
|
.admin-section {
|
|
background: var(--bg-secondary);
|
|
padding: 1.5rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.admin-section h3 {
|
|
margin-top: 0;
|
|
margin-bottom: 1.5rem;
|
|
font-size: 1.2rem;
|
|
}
|
|
|
|
.user-form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.form-row {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 1rem;
|
|
}
|
|
|
|
.form-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.form-group label {
|
|
margin-bottom: 0.5rem;
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group-input {
|
|
padding: 0.75rem;
|
|
background: var(--bg-primary);
|
|
border: 1px solid var(--bg-tertiary);
|
|
border-radius: 6px;
|
|
color: var(--text-primary);
|
|
font-size: 1rem;
|
|
width: 100%;
|
|
}
|
|
|
|
.form-group input:focus,
|
|
.form-group-input:focus {
|
|
outline: none;
|
|
border-color: var(--accent);
|
|
}
|
|
|
|
.form-error {
|
|
background: var(--error);
|
|
color: white;
|
|
padding: 0.75rem;
|
|
border-radius: 6px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-success {
|
|
background: var(--success);
|
|
color: white;
|
|
padding: 0.75rem;
|
|
border-radius: 6px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.loading-msg,
|
|
.error-msg {
|
|
padding: 1rem;
|
|
text-align: center;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.error-msg {
|
|
background: rgba(244, 67, 54, 0.1);
|
|
color: var(--error);
|
|
border-radius: 6px;
|
|
}
|
|
|
|
/* User list (tappable rows) */
|
|
.user-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0;
|
|
}
|
|
|
|
.user-list-empty {
|
|
text-align: center;
|
|
color: var(--text-secondary);
|
|
padding: 2rem;
|
|
}
|
|
|
|
.user-list-item {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0.85rem 0.75rem;
|
|
border-bottom: 1px solid var(--bg-tertiary);
|
|
cursor: pointer;
|
|
transition: background 0.15s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.user-list-item:first-child {
|
|
border-top: 1px solid var(--bg-tertiary);
|
|
}
|
|
|
|
.user-list-item:active {
|
|
background: var(--bg-tertiary);
|
|
}
|
|
|
|
.user-list-item .user-info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.1rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
.user-list-item .user-id {
|
|
font-weight: 600;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.user-list-item .user-displayname {
|
|
font-size: 0.8rem;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
.user-list-item .user-right {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.user-list-item .chevron {
|
|
color: var(--text-secondary);
|
|
font-size: 1.2rem;
|
|
}
|
|
|
|
.badge {
|
|
display: inline-block;
|
|
padding: 0.2rem 0.6rem;
|
|
border-radius: 12px;
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.badge-success {
|
|
background: var(--success);
|
|
color: white;
|
|
}
|
|
|
|
.badge-danger {
|
|
background: var(--error);
|
|
color: white;
|
|
}
|
|
|
|
/* Modal */
|
|
.modal {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: rgba(0, 0, 0, 0.8);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
z-index: 2000;
|
|
padding: 1rem;
|
|
}
|
|
|
|
.modal-content {
|
|
background: var(--bg-secondary);
|
|
padding: 1.5rem;
|
|
border-radius: 12px;
|
|
max-width: 400px;
|
|
width: 100%;
|
|
}
|
|
|
|
.modal-content h3 {
|
|
margin-top: 0;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
|
|
.modal-subtitle {
|
|
color: var(--text-secondary);
|
|
font-size: 0.9rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.modal-content p {
|
|
margin-bottom: 1rem;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
.modal-detail {
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.modal-detail label {
|
|
display: block;
|
|
font-size: 0.8rem;
|
|
color: var(--text-secondary);
|
|
font-weight: 600;
|
|
margin-bottom: 0.3rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.nc-password-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
font-family: monospace;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
.nc-password-row .pw-text {
|
|
flex: 1;
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.btn-small-action {
|
|
padding: 0.25rem 0.5rem;
|
|
font-size: 0.75rem;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
background: var(--bg-tertiary);
|
|
color: var(--text-secondary);
|
|
white-space: nowrap;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.btn-small-action:active {
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.modal-action-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
margin-top: 1.25rem;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.btn-block {
|
|
width: 100%;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn-tertiary {
|
|
background: transparent;
|
|
color: var(--text-secondary);
|
|
border: 1px solid var(--bg-tertiary);
|
|
}
|
|
|
|
.btn-tertiary:active {
|
|
background: var(--bg-tertiary);
|
|
}
|
|
|
|
.modal-actions {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
margin-top: 1.5rem;
|
|
}
|
|
|
|
.modal-actions .btn {
|
|
flex: 1;
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
bottom: 8rem;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
background: rgba(0, 0, 0, 0.9);
|
|
color: white;
|
|
padding: 1rem 1.5rem;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
z-index: 10000;
|
|
max-width: 90%;
|
|
text-align: center;
|
|
}
|
|
|
|
.toast.success {
|
|
background: var(--success);
|
|
}
|
|
|
|
.toast.error {
|
|
background: var(--error);
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.form-row {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script src="{{ url_for('static', filename='js/admin.js') }}"></script>
|
|
<script src="{{ url_for('static', filename='js/auth.js') }}"></script>
|
|
<script>
|
|
Admin.init();
|
|
|
|
// Close modals on outside click
|
|
['user-modal', 'pin-modal', 'confirm-modal'].forEach(id => {
|
|
document.getElementById(id).addEventListener('click', (e) => {
|
|
if (e.target.id === id) Admin.closeModal(id);
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|