Kreirajte svoj korisnički račun
Nakon kreiranja bit ćete preusmjereni na ojjoj.com/user/vaše-ime — vašu osobnu stranicu.
🎁
Kreiraj profil i osvoji tiket!
Svaki kreiran profil = 1 tiket za nagradnu igru za ljetovanje na Tkonu (Pašman) za 4 osobe!
async function handleSaveProfile(event) {
event.preventDefault();
const firstName = document.getElementById('firstName').value.trim();
const lastName = document.getElementById('lastName').value.trim();
const email = document.getElementById('email').value.trim();
const phone = document.getElementById('phone').value.trim();
const slogan = document.getElementById('slogan').value.trim();
const street = document.getElementById('street').value.trim();
const postalCode = document.getElementById('postalCode').value.trim();
const city = document.getElementById('city').value.trim();
// Validacija...
if (!firstName || !lastName || !email || !phone || !slogan || !street || !postalCode || !city) {
showProfileToast('Nedostaju podaci', 'Popunite sva obavezna polja', 'error');
return;
}
const profile = {
firstName, lastName, email, phone,
birthDate: document.getElementById('birthDate').value,
slogan, street, postalCode, city,
country: document.getElementById('country').value,
apartment: document.getElementById('apartment').value,
notes: document.getElementById('notes').value,
newsletter: document.getElementById('newsletter').checked,
orderNotifications: document.getElementById('orderNotifications').checked
};
const btn = document.querySelector('.btn-gold');
const orig = btn.innerHTML;
btn.disabled = true;
btn.innerHTML = ' Kreiram profil...';
try {
// POŠALJI NA SERVER
const res = await fetch('/api/create-user.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(profile)
});
const result = await res.json();
if (!result.success) throw new Error(result.error);
// SPREMI LOKALNO
localStorage.setItem(PROFILE_STORAGE_KEY + email, JSON.stringify({
...profile,
username: result.username,
userUrl: result.url
}));
localStorage.setItem(CURRENT_USER_KEY, email);
// KREIRAJ TIKET
const ticket = {
ticketNumber: 'TK-' + Math.floor(100000 + Math.random() * 900000),
email, name: firstName + ' ' + lastName,
username: result.username,
userUrl: result.url,
phone, slogan,
prize: 'Ljetovanje na Tkonu (Pašman) za 4 osobe',
createdAt: new Date().toISOString(),
validUntil: '2026-12-31T23:59:59',
status: 'active'
};
localStorage.setItem(TICKET_STORAGE_KEY + email, JSON.stringify(ticket));
// PRIKAŽI MODAL
showTicketModal(ticket);
spawnConfetti();
// PREUSMJERI
redirectTargetUrl = result.url;
document.getElementById('redirectUrl').textContent = 'ojjoj.com/user/' + result.username;
redirectTimer = setTimeout(() => {
window.location.href = result.url;
}, 5000);
} catch (e) {
console.error(e);
showProfileToast('Greška', e.message || 'Nije moguće kreirati profil', 'error');
} finally {
btn.disabled = false;
btn.innerHTML = orig;
}
}