const _e = function(str) { return atob(str); };
function switchTab(tab) {
document.querySelectorAll('.auth-tab').forEach(el => el.classList.remove('active'));
document.querySelectorAll('.auth-form').forEach(el => el.classList.remove('active'));
if (tab === 'login') {
document.querySelector('.auth-tab[data-tab="login"]').classList.add('active');
document.getElementById('loginForm').classList.add('active');
} else {
document.querySelector('.auth-tab[data-tab="register"]').classList.add('active');
document.getElementById('registerForm').classList.add('active');
resetOTPState();
}
document.getElementById('loginMsg').className = 'msg';
document.getElementById('regMsg').className = 'msg';
}
async function userLogin() {
const mobile = document.getElementById('loginMobile').value.replace(/[^0-9]/g, '');
const password = document.getElementById('loginPassword').value;
const loginBtn = document.getElementById('loginBtn');
if (!mobile || !password) {
showMsg('loginMsg', 'કૃપા કરીને મોબાઈલ અને પાસવર્ડ ભરો', 'error');
return;
}
if (!/^[6-9]\d{9}$/.test(mobile)) {
showMsg('loginMsg', 'અમાન્ય મોબાઈલ નંબર (10 અંક, 6-9 થી શરૂ)', 'error');
return;
}
showMsg('loginMsg', ' ચકાસણી થઈ રહી છે...', 'info');
loginBtn.disabled = true;
loginBtn.innerHTML = ' પ્રક્રિયા ચાલુ છે...';
try {
const response = await fetch(_e('bG9naW4ucGhw'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mobile, password })
});
const data = await response.json();
if (data.success) {
if (data.subscription_expired) {
showMsg('loginMsg', 'લોગિન સફળ! પણ સબ્સ્ક્રિપ્શન સમાપ્ત થઈ ગયું છે.', 'error');
setTimeout(() => { window.location.href = _e('c3Vic2NyaXB0aW9uLnBocA=='); }, 1000);
} else {
showMsg('loginMsg', 'સફળ લોગિન! ડેશબોર્ડ ખૂલી રહ્યું છે...', 'success');
setTimeout(() => { window.location.href = _e('ZGFzaGJvYXJkLnBocA=='); }, 200);
}
} else {
showMsg('loginMsg', data.message || 'અમાન્ય યુઝર આઈડી અથવા પાસવર્ડ', 'error');
loginBtn.disabled = false;
loginBtn.innerHTML = ' લોગિન કરો';
}
} catch(error) {
console.error('Login Error:', error);
showMsg('loginMsg', 'સિસ્ટમ ભૂલ: ' + error.message, 'error');
loginBtn.disabled = false;
loginBtn.innerHTML = ' લોગિન કરો';
}
}
let otpTimerInterval = null;
let otpSeconds = 60;
let isOtpVerified = false;
let currentDebugOtp = '';
function showOtpModal(otp) {
currentDebugOtp = otp;
document.getElementById('displayOtpValue').textContent = otp;
document.getElementById('otpModal').classList.add('show');
}
function closeOtpModal() {
document.getElementById('otpModal').classList.remove('show');
}
function copyOtpAndClose() {
if (currentDebugOtp) {
navigator.clipboard.writeText(currentDebugOtp).then(() => {
document.getElementById('regOtp').value = currentDebugOtp;
alert('✅ OTP સફળતાપૂર્વક કોપી થયો અને ઈનપુટમાં ઉમેરાઈ ગયો છે!');
closeOtpModal();
}).catch(() => {
const tempInput = document.createElement('input');
tempInput.value = currentDebugOtp;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
document.getElementById('regOtp').value = currentDebugOtp;
alert('✅ OTP સફળતાપૂર્વક કોપી થયો અને ઈનપુટમાં ઉમેરાઈ ગયો છે!');
closeOtpModal();
});
}
}
async function sendOTP() {
let mobile = document.getElementById('regMobile').value.replace(/[^0-9]/g, '');
if (mobile.startsWith('0')) mobile = mobile.substring(1);
if (mobile.startsWith('91')) mobile = mobile.substring(2);
if (!mobile || !/^[6-9]\d{9}$/.test(mobile)) {
document.getElementById('otpStatus').innerHTML =
'❌ અમાન્ય મોબાઈલ નંબર';
return;
}
document.getElementById('regMobile').value = mobile;
document.getElementById('otpStatus').innerHTML =
' OTP મોકલાઈ રહ્યો છે...';
document.getElementById('sendOtpBtn').disabled = true;
try {
const response = await fetch(_e('c2VuZF9vdHAucGhw'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mobile })
});
const data = await response.json();
if (data.success) {
document.getElementById('otpStatus').innerHTML =
'✅ OTP મોકલાઈ ગયો! કૃપા કરી તમારું WhatsApp તપાસો.';
if (data.debug_otp) {
showOtpModal(data.debug_otp);
}
startOtpTimer();
document.getElementById('regOtp').disabled = false;
document.getElementById('verifyOtpBtn').disabled = false;
} else {
document.getElementById('otpStatus').innerHTML =
'❌ ' + (data.message || 'OTP મોકલવામાં નિષ્ફળ') + '';
document.getElementById('sendOtpBtn').disabled = false;
}
} catch(error) {
console.error('Send OTP Error:', error);
document.getElementById('otpStatus').innerHTML =
'❌ જોડાણ નિષ્ફળ: ' + error.message + '';
document.getElementById('sendOtpBtn').disabled = false;
}
}
async function verifyOTP() {
const otp = document.getElementById('regOtp').value.trim();
const mobile = document.getElementById('regMobile').value.replace(/[^0-9]/g, '');
if (!otp || otp.length !== 6) {
document.getElementById('otpStatus').innerHTML =
'❌ કૃપા કરીને 6 અંકનો OTP દાખલ કરો';
return;
}
if (!/^\d{6}$/.test(otp)) {
document.getElementById('otpStatus').innerHTML =
'❌ OTP માં ફક્ત અંકો જ હોઈ શકે';
return;
}
document.getElementById('otpStatus').innerHTML =
' ચકાસણી ચાલુ છે...';
document.getElementById('verifyOtpBtn').disabled = true;
try {
const response = await fetch(_e('dmVyaWZ5X290cC5waHA='), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mobile, otp })
});
const data = await response.json();
if (data.success) {
isOtpVerified = true;
document.getElementById('otpStatus').innerHTML =
'✅ OTP સફળતાપૂર્વક ચકાસાઈ ગયો છે. હવે રજીસ્ટ્રેશન કરો.';
document.getElementById('regOtp').disabled = true;
document.getElementById('verifyOtpBtn').disabled = true;
document.getElementById('regOtp').style.borderColor = 'var(--success)';
document.getElementById('regOtp').style.backgroundColor = '#f0fff4';
document.getElementById('registerBtn').disabled = false;
document.getElementById('registerBtn').style.opacity = '1';
} else {
document.getElementById('otpStatus').innerHTML =
'❌ ' + (data.message || 'ખોટો OTP દાખલ કરેલ છે') + '';
isOtpVerified = false;
document.getElementById('verifyOtpBtn').disabled = false;
}
} catch(error) {
console.error('Verify OTP Error:', error);
document.getElementById('otpStatus').innerHTML =
'❌ સર્વર એરર: ' + error.message + '';
isOtpVerified = false;
document.getElementById('verifyOtpBtn').disabled = false;
}
}
function startOtpTimer() {
otpSeconds = 60;
document.getElementById('otpTimer').style.display = 'block';
updateTimerDisplay();
clearInterval(otpTimerInterval);
otpTimerInterval = setInterval(() => {
otpSeconds--;
updateTimerDisplay();
if (otpSeconds <= 0) {
clearInterval(otpTimerInterval);
document.getElementById('otpTimer').style.display = 'none';
document.getElementById('sendOtpBtn').disabled = false;
document.getElementById('otpStatus').innerHTML =
'⏰ સમય પૂર્ણ થયો છે. ફરીથી OTP મેળવો.';
}
}, 1000);
}
function updateTimerDisplay() {
const minutes = Math.floor(otpSeconds / 60);
const seconds = otpSeconds % 60;
document.getElementById('timerDisplay').textContent =
minutes > 0 ? minutes + ':' + (seconds < 10 ? '0' : '') + seconds : seconds;
}
function resetOTPState() {
isOtpVerified = false;
document.getElementById('regOtp').value = '';
document.getElementById('regOtp').disabled = false;
document.getElementById('regOtp').style.borderColor = '';
document.getElementById('regOtp').style.backgroundColor = '';
document.getElementById('verifyOtpBtn').disabled = false;
document.getElementById('sendOtpBtn').disabled = false;
document.getElementById('otpStatus').innerHTML = '';
document.getElementById('otpTimer').style.display = 'none';
clearInterval(otpTimerInterval);
document.getElementById('registerBtn').disabled = false;
document.getElementById('registerBtn').style.opacity = '1';
}
async function userRegister() {
const full_name = document.getElementById('regFullName').value.trim();
const email = document.getElementById('regEmail').value.trim();
let mobile = document.getElementById('regMobile').value.replace(/[^0-9]/g, '');
const password = document.getElementById('regPassword').value;
const district = document.getElementById('regDistrict').value;
const taluka = document.getElementById('regTaluka').value;
const gram_panchayat = document.getElementById('regGramPanchayat').value.trim();
const village = document.getElementById('regVillage').value.trim();
const pincode = document.getElementById('regPincode').value.trim();
const category = document.getElementById('regCategory').value;
const otp = document.getElementById('regOtp').value.trim();
const registerBtn = document.getElementById('registerBtn');
if (mobile.startsWith('0')) mobile = mobile.substring(1);
if (mobile.startsWith('91')) mobile = mobile.substring(2);
if (!full_name || !email || !mobile || !password || !pincode || !gram_panchayat) {
showMsg('regMsg', 'કૃપા કરીને બધી ફરજિયાત વિગતો ભરો (ગ્રામ પંચાયત સહિત)', 'error');
return;
}
if (!district) {
showMsg('regMsg', 'કૃપા કરીને જિલ્લો પસંદ કરો', 'error');
return;
}
if (!taluka) {
showMsg('regMsg', 'કૃપા કરીને તાલુકો પસંદ કરો', 'error');
return;
}
if (!/^[1-9][0-9]{5}$/.test(pincode)) {
showMsg('regMsg', 'અમાન્ય પીનકોડ (૬ અંક હોવા જરૂરી છે)', 'error');
return;
}
if (!isOtpVerified) {
showMsg('regMsg', '❌ કૃપા કરીને પહેલા OTP ચકાસો', 'error');
return;
}
if (password.length < 6) {
showMsg('regMsg', 'પાસવર્ડ લઘુત્તમ 6 અક્ષરોનો હોવો જોઈએ', 'error');
return;
}
if (!/^[6-9]\d{9}$/.test(mobile)) {
showMsg('regMsg', 'અમાન્ય મોબાઈલ નંબર', 'error');
return;
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
showMsg('regMsg', 'અમાન્ય ઈમેલ એડ્રેસ', 'error');
return;
}
showMsg('regMsg', 'નોંધણી થઈ રહી છે...', 'info');
registerBtn.disabled = true;
registerBtn.innerHTML = ' પ્રક્રિયા ચાલુ છે...';
try {
const response = await fetch(_e('cmVnaXN0ZXIucGhw'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
full_name, email, mobile, password, district, taluka, gram_panchayat, village, pincode, category, otp, isOtpVerified: isOtpVerified
})
});
const data = await response.json();
if (data.success) {
showMsg('regMsg', '✅ ' + data.message, 'success');
isOtpVerified = false;
setTimeout(() => { window.location.href = _e('ZGFzaGJvYXJkLnBocA=='); }, 1500);
} else {
showMsg('regMsg', '❌ ' + (data.message || 'નોંધણી થઈ શકી નથી'), 'error');
registerBtn.disabled = false;
registerBtn.innerHTML = ' નોંધણી કરો';
if (data.message && (data.message.includes('OTP') || data.message.includes('otp'))) {
isOtpVerified = false;
document.getElementById('regOtp').value = '';
document.getElementById('regOtp').disabled = false;
document.getElementById('regOtp').style.borderColor = '';
document.getElementById('regOtp').style.backgroundColor = '';
document.getElementById('verifyOtpBtn').disabled = false;
document.getElementById('sendOtpBtn').disabled = false;
}
}
} catch(error) {
console.error('Registration Error:', error);
showMsg('regMsg', '❌ નેટવર્ક કનેક્શનની ભૂલ: ' + error.message, 'error');
registerBtn.disabled = false;
registerBtn.innerHTML = ' નોંધણી કરો';
}
}
async function forgotPassword() {
const mobile = document.getElementById('forgotMobile').value.replace(/[^0-9]/g, '');
const forgotBtn = document.querySelector('#forgotModal .btn-warning');
if (!mobile || !/^[6-9]\d{9}$/.test(mobile)) {
document.getElementById('forgotMsg').innerHTML =
'❌ અમાન્ય મોબાઈલ નંબર';
return;
}
document.getElementById('forgotMsg').innerHTML =
' પ્રક્રિયા ચાલુ છે...';
forgotBtn.disabled = true;
try {
const response = await fetch(_e('Zm9yZ290X3Bhc3N3b3JkLnBocA=='), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mobile })
});
const data = await response.json();
if (data.success) {
closeForgotModal();
alert('✅ નવો પાસવર્ડ તમારા WhatsApp પર મોકલવામાં આવ્યો છે');
} else {
document.getElementById('forgotMsg').innerHTML =
'❌ ' + (data.message || 'પ્રક્રિયા નિષ્ફળ') + '';
}
} catch(error) {
console.error('Forgot Password Error:', error);
document.getElementById('forgotMsg').innerHTML =
'❌ પ્રક્રિયા નિષ્ફળ: ' + error.message + '';
}
forgotBtn.disabled = false;
}
function showMsg(elementId, message, type) {
const el = document.getElementById(elementId);
el.innerHTML = message;
el.className = 'msg ' + type;
}
function showForgotModal() {
document.getElementById('forgotModal').classList.add('show');
document.getElementById('forgotMsg').className = 'msg';
document.getElementById('forgotMobile').value = '';
}
function closeForgotModal() {
document.getElementById('forgotModal').classList.remove('show');
document.getElementById('forgotMsg').className = 'msg';
document.getElementById('forgotMobile').value = '';
}
document.addEventListener('DOMContentLoaded', function() {
const registerBtn = document.getElementById('registerBtn');
if (registerBtn) {
registerBtn.disabled = false;
registerBtn.style.opacity = '1';
}
document.getElementById('regOtp').disabled = false;
document.getElementById('verifyOtpBtn').disabled = false;
document.getElementById('sendOtpBtn').disabled = false;
document.getElementById('regCategory').value = 'vce';
});
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('tab') === 'register') {
switchTab('register');
}