XToGrow
Features
Pricing
How to use
Contact
language
en
expand_more
{ e.preventDefault(); const email = document.getElementById('email').value; const password = document.getElementById('password').value; const errorDiv = document.getElementById('errorMessage'); const button = document.getElementById('loginButton'); // Hide previous errors errorDiv.classList.add('hidden'); button.disabled = true; button.textContent = 'Signing in...'; try { const response = await fetch('/api/auth.php?action=login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }); const data = await response.json(); if (data.status === 'success') { // Store token in localStorage and cookie document.cookie = `userToken=${data.userToken}; path=/; domain=.soktp.com; max-age=2592000`; // 30 days // Notify extension window.postMessage({ type: 'USER_TOKEN_UPDATE', userToken: data.userToken }, '*'); // Check for returnURL cookie const getCookie = (name) => { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); return null; }; const returnURL = getCookie('returnURL'); if (returnURL) { // Clear the cookie document.cookie = "returnURL=; path=/; domain=.soktp.com; expires=Thu, 01 Jan 1970 00:00:00 GMT"; window.location.href = decodeURIComponent(returnURL); } else { window.location.href = '/dashboard'; } } else { if (data.error_code === 'PENDING') { Swal.fire({ title: '
Email Pending Verification
', text: data.message || 'Please verify your email before logging in. Check your inbox for verification link.', icon: 'warning', showCancelButton: true, confirmButtonText: 'Resend Email', cancelButtonText: 'Maybe Later', background: '#161618', color: '#fff', confirmButtonColor: '#F59E0B', cancelButtonColor: '#303030', customClass: { popup: 'rounded-3xl border border-white/5 shadow-2xl', title: 'text-white font-bold', confirmButton: 'rounded-xl px-6 py-3 text-sm font-bold', cancelButton: 'rounded-xl px-6 py-3 text-sm font-bold' } }).then((result) => { if (result.isConfirmed) { resendVerification(email); } }); } else { errorDiv.querySelector('.message-content').textContent = data.message || 'Login failed. Please try again.'; errorDiv.classList.remove('hidden'); } } } catch (error) { errorDiv.querySelector('.message-content').textContent = 'An unexpected error occurred. Please try again later.'; errorDiv.classList.remove('hidden'); } finally { button.disabled = false; button.textContent = 'SIGN IN'; } }); async function resendVerification(email) { try { const response = await fetch('/api/auth.php?action=resendVerification', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email }) }); const data = await response.json(); if (data.status === 'success') { Swal.fire({ title: 'Success!', text: data.message, icon: 'success', background: '#161618', color: '#fff', confirmButtonColor: '#F59E0B', customClass: { popup: 'rounded-3xl border border-white/5 shadow-2xl' } }); } else { Swal.fire({ title: 'Error', text: data.message || 'Failed to resend email', icon: 'error', background: '#161618', color: '#fff', confirmButtonColor: '#F59E0B', customClass: { popup: 'rounded-3xl border border-white/5 shadow-2xl' } }); } } catch (error) { console.error('Error resending verification:', error); } } async function loginWithGoogle() { // Save returnURL to cookie if present in URL const urlParams = new URLSearchParams(window.location.search); const returnURL = urlParams.get('returnURL') || window.location.pathname + window.location.search; document.cookie = `returnURL=${encodeURIComponent(returnURL)}; path=/; domain=.soktp.com; max-age=3600`; const client_id = '489345494275-dkmrltvhl4cc4m6t70o2s56qb4qfatbu.apps.googleusercontent.com'; const redirect_uri = encodeURIComponent('https://so.soktp.com/auth.php'); const scope = encodeURIComponent('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'); window.location.href = `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=google`; }