I lowkey forgot to commit
This commit is contained in:
124
templates/_partials/auth_modal.html.twig
Normal file
124
templates/_partials/auth_modal.html.twig
Normal file
@@ -0,0 +1,124 @@
|
||||
<div class="modal fade" id="authModal" tabindex="-1" aria-labelledby="authModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="authModalLabel">Account</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div data-auth-panel="login" class="d-none">
|
||||
<form data-auth-login action="{{ path('app_login') }}" method="post" class="vstack gap-2">
|
||||
<div>
|
||||
<label class="form-label">Email</label>
|
||||
<input class="form-control" type="email" name="_username" required autocomplete="email" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label">Password</label>
|
||||
<input class="form-control" type="password" name="_password" required autocomplete="current-password" />
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="_remember_me" id="rememberMe" checked>
|
||||
<label class="form-check-label" for="rememberMe">Remember me</label>
|
||||
</div>
|
||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
|
||||
<input type="hidden" name="_target_path" value="" data-auth-target />
|
||||
<input type="hidden" name="_failure_path" value="" data-auth-failure />
|
||||
<button class="btn btn-success" type="submit">Login</button>
|
||||
<button class="btn btn-outline-success" type="button" data-auth-open-register>Sign up</button>
|
||||
</form>
|
||||
<div class="text-danger small mt-2 d-none" data-auth-login-error></div>
|
||||
</div>
|
||||
<div data-auth-panel="register" class="d-none">
|
||||
<form data-auth-register action="{{ path('app_register') }}" method="post" class="vstack gap-2">
|
||||
<input type="hidden" name="registration_form[_token]" value="{{ csrf_token('registration_form') }}" />
|
||||
<div><label class="form-label">Email</label><input class="form-control" type="email" name="registration_form[email]" required /></div>
|
||||
<div><label class="form-label">Display name (optional)</label><input class="form-control" type="text" name="registration_form[displayName]" maxlength="120" /></div>
|
||||
<div><label class="form-label">Password</label><input class="form-control" type="password" name="registration_form[plainPassword][first]" minlength="8" required /></div>
|
||||
<div><label class="form-label">Repeat password</label><input class="form-control" type="password" name="registration_form[plainPassword][second]" minlength="8" required /></div>
|
||||
<button class="btn btn-success" type="submit">Create account</button>
|
||||
<button class="btn btn-outline-secondary" type="button" data-auth-open-login>Back to login</button>
|
||||
</form>
|
||||
<div class="text-danger small mt-2 d-none" data-auth-register-error></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function(){
|
||||
const modalEl = document.getElementById('authModal');
|
||||
if (!modalEl) return;
|
||||
const bsModal = new bootstrap.Modal(modalEl);
|
||||
const panels = modalEl.querySelectorAll('[data-auth-panel]');
|
||||
function showPanel(kind){
|
||||
panels.forEach(p => p.classList.toggle('d-none', p.getAttribute('data-auth-panel') !== kind));
|
||||
bsModal.show();
|
||||
}
|
||||
modalEl.querySelector('[data-auth-open-register]')?.addEventListener('click', ()=> showPanel('register'));
|
||||
modalEl.querySelector('[data-auth-open-login]')?.addEventListener('click', ()=> showPanel('login'));
|
||||
document.querySelectorAll('[data-open-auth]')?.forEach(btn => {
|
||||
btn.addEventListener('click', (e)=>{ e.preventDefault(); showPanel(btn.getAttribute('data-open-auth') || 'login'); });
|
||||
});
|
||||
|
||||
const currentUrl = location.pathname + location.search + location.hash;
|
||||
modalEl.querySelector('[data-auth-target]')?.setAttribute('value', currentUrl);
|
||||
modalEl.querySelector('[data-auth-failure]')?.setAttribute('value', currentUrl);
|
||||
|
||||
// AJAX login
|
||||
const loginForm = modalEl.querySelector('form[data-auth-login]');
|
||||
const loginError = modalEl.querySelector('[data-auth-login-error]');
|
||||
if (loginForm) {
|
||||
loginForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
if (loginError) { loginError.classList.add('d-none'); }
|
||||
try {
|
||||
const resp = await fetch(loginForm.action, { method: 'POST', body: new FormData(loginForm), credentials: 'same-origin' });
|
||||
if (resp.ok || resp.status === 302) {
|
||||
bsModal.hide();
|
||||
location.reload();
|
||||
} else {
|
||||
if (loginError) { loginError.textContent = 'Login failed. Please check your credentials.'; loginError.classList.remove('d-none'); }
|
||||
}
|
||||
} catch (_) {
|
||||
if (loginError) { loginError.textContent = 'Network error. Please try again.'; loginError.classList.remove('d-none'); }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// AJAX registration
|
||||
const regForm = modalEl.querySelector('form[data-auth-register]');
|
||||
const regError = modalEl.querySelector('[data-auth-register-error]');
|
||||
if (regForm) {
|
||||
regForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
if (regError) { regError.classList.add('d-none'); }
|
||||
try {
|
||||
const resp = await fetch(regForm.action, { method: 'POST', body: new FormData(regForm), credentials: 'same-origin', headers: { 'X-Requested-With': 'XMLHttpRequest' } });
|
||||
if (resp.ok) {
|
||||
showPanel('login');
|
||||
if (loginError) { loginError.textContent = 'Account created. You can now sign in.'; loginError.classList.remove('d-none'); }
|
||||
} else if (resp.status === 422) {
|
||||
const data = await resp.json();
|
||||
const messages = Object.values(data.errors || {}).flat().join(' ');
|
||||
if (regError) { regError.textContent = messages || 'Please correct the highlighted fields.'; regError.classList.remove('d-none'); }
|
||||
} else {
|
||||
if (regError) { regError.textContent = 'Registration failed. Please try again.'; regError.classList.remove('d-none'); }
|
||||
}
|
||||
} catch (_) {
|
||||
if (regError) { regError.textContent = 'Network error. Please try again.'; regError.classList.remove('d-none'); }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// auto-open via ?auth=
|
||||
const params = new URLSearchParams(location.search);
|
||||
const authParam = params.get('auth');
|
||||
if (authParam === 'login' || authParam === 'register') {
|
||||
showPanel(authParam);
|
||||
}
|
||||
window.__openAuthModal = showPanel;
|
||||
})();
|
||||
</script>
|
||||
|
||||
|
||||
40
templates/_partials/navbar.html.twig
Normal file
40
templates/_partials/navbar.html.twig
Normal file
@@ -0,0 +1,40 @@
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary" data-auth-header>
|
||||
<div class="container">
|
||||
<a class="navbar-brand fw-bold" href="{{ path('album_search') }}">Tonehaus</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMain" aria-controls="navMain" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navMain">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item"><a class="nav-link" href="{{ path('review_index') }}">Your Reviews</a></li>
|
||||
</ul>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
{% if app.user %}
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary dropdown-toggle d-flex align-items-center gap-2" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
|
||||
<path fill-rule="evenodd" d="M14 14s-1-1.5-6-1.5S2 14 2 14s1-4 6-4 6 4 6 4z"/>
|
||||
</svg>
|
||||
<span class="text-truncate" style="max-width: 180px;">{{ app.user.displayName ?? app.user.userIdentifier }}</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
{% if is_granted('ROLE_ADMIN') %}
|
||||
<li><a class="dropdown-item" href="{{ path('admin_settings') }}">Site settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
{% endif %}
|
||||
<li><a class="dropdown-item" href="{{ path('account_dashboard') }}">Dashboard</a></li>
|
||||
<li><a class="dropdown-item" href="{{ path('account_settings') }}">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="{{ path('app_logout') }}">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<button class="btn btn-success" type="button" data-open-auth="login">Login / Sign up</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user