403Webshell
Server IP : 104.171.130.249  /  Your IP : 216.73.216.146
Web Server : nginx/1.25.5
System : Linux 0dac65491b7e 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
User : root ( 0)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/html/wp-content/themes/matreshka/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wp-content/themes/matreshka/assets/js/registration.js
(function($){
'use strict';

const CFG = window.matreshka_reg || {};
let currentStep = parseInt(CFG.step) || 1;
let cooldownTimer = null;
let phoneRaw = '';

/* ───── INIT ───── */
$(function(){
	goToStep(currentStep);
	initPhoneMask();
	initCodeInputs();
	bindEvents();
});

/* ───── NAVIGATION ───── */
function goToStep(step){
	currentStep = step;
	$('.reg-step').hide();

	if(step === 'complete'){
		$('#reg-step-complete').fadeIn(300);
		updateProgress(5);
		return;
	}

	$('#reg-step-' + step).fadeIn(300);
	updateProgress(step);
}

function updateProgress(active){
	const stepTitles = {
		1: 'Вход по номеру телефона',
		2: 'Заполните профиль',
		3: 'Подтверждение email',
		4: 'Адрес доставки',
		5: 'Завершено'
	};

	$('#current-step-num').text(active <= 4 ? active : 4);
	$('#current-step-title').text(stepTitles[active] || '');

	/* fill: 0 % → 33 % → 66 % → 100 % */
	var pct = Math.min((active - 1) / 3 * 100, 100);
	$('#progress-fill').css('width', pct + '%');

	$('.reg-progress-node').each(function(){
		var s = parseInt($(this).data('step'));
		$(this).toggleClass('active', s === active)
		       .toggleClass('done', s < active);
	});
}

/* ───── PHONE MASK ───── */
function initPhoneMask(){
	const $input = $('#reg-phone');

	$input.on('focus', function(){
		if(!this.value) this.value = '+7 (';
	});

	$input.on('input', function(e){
		let digits = this.value.replace(/\D/g, '');
		if(digits.length === 0){
			this.value = '';
			phoneRaw = '';
			$('#btn-send-sms').prop('disabled', true);
			return;
		}
		// always start with 7
		if(digits[0] !== '7') digits = '7' + digits;
		if(digits.length > 11) digits = digits.substring(0, 11);
		phoneRaw = digits;

		let formatted = '+7';
		if(digits.length > 1) formatted += ' (' + digits.substring(1, 4);
		if(digits.length >= 4) formatted += ')';
		if(digits.length > 4) formatted += ' ' + digits.substring(4, 7);
		if(digits.length > 7) formatted += '-' + digits.substring(7, 9);
		if(digits.length > 9) formatted += '-' + digits.substring(9, 11);

		this.value = formatted;
		$('#btn-send-sms').prop('disabled', digits.length !== 11);
	});

	$input.on('keydown', function(e){
		if(e.key === 'Backspace' && this.value === '+7 ('){
			e.preventDefault();
			this.value = '';
			phoneRaw = '';
			$('#btn-send-sms').prop('disabled', true);
		}
	});
}

/* ───── CODE DIGIT INPUTS ───── */
function initCodeInputs(){
	const $digits = $('.code-digit');

	$digits.on('input', function(){
		const val = this.value.replace(/\D/g, '');
		this.value = val.charAt(0) || '';

		if(val && $(this).data('index') < 5){
			$digits.eq($(this).data('index') + 1).focus();
		}

		checkCodeComplete();
	});

	$digits.on('keydown', function(e){
		if(e.key === 'Backspace' && !this.value && $(this).data('index') > 0){
			$digits.eq($(this).data('index') - 1).focus().val('');
		}
	});

	$digits.on('paste', function(e){
		e.preventDefault();
		const pasted = (e.originalEvent.clipboardData || window.clipboardData)
			.getData('text').replace(/\D/g, '').substring(0, 6);

		pasted.split('').forEach(function(ch, i){
			$digits.eq(i).val(ch);
		});
		if(pasted.length > 0) $digits.eq(Math.min(pasted.length, 5)).focus();
		checkCodeComplete();
	});
}

function checkCodeComplete(){
	let code = '';
	$('.code-digit').each(function(){ code += this.value; });
	$('#btn-verify-code').prop('disabled', code.length !== 6);
}

function getCode(){
	let code = '';
	$('.code-digit').each(function(){ code += this.value; });
	return code;
}

/* ───── EVENTS ───── */
function bindEvents(){
	// Step 1: Send SMS
	$('#btn-send-sms').on('click', sendSms);
	$('#reg-phone').on('keydown', function(e){
		if(e.key === 'Enter' && phoneRaw.length === 11) sendSms();
	});

	// Step 1: Verify code
	$('#btn-verify-code').on('click', verifyCode);

	// Step 1: Resend
	$('#btn-resend-sms').on('click', sendSms);

	// Step 2: Save profile
	$('#btn-save-profile').on('click', saveProfile);

	// Step 3: Continue
	$('#btn-continue').on('click', continueToAddress);

	// Step 3: Resend email
	$('#btn-resend-email').on('click', resendEmail);

	// Step 4: Save address
	$('#btn-save-address').on('click', saveAddress);

	// Step 4: Skip
	$('#btn-skip-address').on('click', skipAddress);
}

/* ───── STEP 1: SEND SMS ───── */
function sendSms(){
	if(phoneRaw.length !== 11) return;
	const $btn = $('#btn-send-sms');
	setLoading($btn, true);
	hideError(1);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_send_sms',
		_ajax_nonce: CFG.nonce,
		phone: phoneRaw,
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			$('#phone-form').slideUp(200);
			$('#code-form').slideDown(200);
			$('.code-digit').val('').eq(0).focus();
			startCooldown(res.data.cooldown || 60);
		} else {
			if(res.data && res.data.wait){
				$('#phone-form').slideUp(200);
				$('#code-form').slideDown(200);
				startCooldown(res.data.wait);
			}
			showError(1, res.data ? res.data.message : 'Ошибка');
		}
	}).fail(function(){
		setLoading($btn, false);
		showError(1, 'Ошибка сети');
	});
}

/* ───── STEP 1: VERIFY CODE ───── */
function verifyCode(){
	const code = getCode();
	if(code.length !== 6) return;

	const $btn = $('#btn-verify-code');
	setLoading($btn, true);
	hideError(1);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_verify_code',
		_ajax_nonce: CFG.nonce,
		phone: phoneRaw,
		code: code,
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			if(res.data.redirect){
				window.location.href = res.data.redirect;
				return;
			}
			// Refresh nonce for logged-in user
			if(res.data.nonce) CFG.nonce = res.data.nonce;
			goToStep(res.data.step || 2);
		} else {
			showError(1, res.data ? res.data.message : 'Неверный код');
			$('.code-digit').val('').eq(0).focus();
		}
	}).fail(function(){
		setLoading($btn, false);
		showError(1, 'Ошибка сети');
	});
}

/* ───── STEP 2: SAVE PROFILE ───── */
function saveProfile(){
	const name = $.trim($('#reg-name').val());
	const email = $.trim($('#reg-email').val());
	const birthday = $('#reg-birthday').val();
	const consent = $('#reg-consent').is(':checked');

	hideError(2);

	if(!name){
		showError(2, 'Введите имя'); return;
	}
	if(!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)){
		showError(2, 'Введите корректный email'); return;
	}
	if(!consent){
		showError(2, 'Необходимо дать согласие на обработку данных'); return;
	}

	const $btn = $('#btn-save-profile');
	setLoading($btn, true);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_save_profile',
		_ajax_nonce: CFG.nonce,
		name: name,
		email: email,
		birthday: birthday,
		want_receipts: $('#reg-want-receipts').is(':checked') ? 1 : 0,
		consent_personal_data: 1,
		want_promotions: $('#reg-promotions').is(':checked') ? 1 : 0,
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			$('#email-sent-to').html('На адрес <strong>' + $('<span>').text(email).html() + '</strong>');
			goToStep(3);
		} else {
			showError(2, res.data ? res.data.message : 'Ошибка сохранения');
		}
	}).fail(function(){
		setLoading($btn, false);
		showError(2, 'Ошибка сети');
	});
}

/* ───── STEP 3: CONTINUE ───── */
function continueToAddress(){
	const $btn = $('#btn-continue');
	setLoading($btn, true);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_continue',
		_ajax_nonce: CFG.nonce,
	}, function(res){
		setLoading($btn, false);
		if(res.success) goToStep(4);
	}).fail(function(){
		setLoading($btn, false);
	});
}

/* ───── STEP 3: RESEND EMAIL ───── */
function resendEmail(){
	const $btn = $('#btn-resend-email');
	setLoading($btn, true);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_resend_email',
		_ajax_nonce: CFG.nonce,
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			$btn.text('Письмо отправлено!');
			setTimeout(function(){ $btn.text('Отправить письмо повторно'); }, 3000);
		}
	}).fail(function(){
		setLoading($btn, false);
	});
}

/* ───── STEP 4: SAVE ADDRESS ───── */
function saveAddress(){
	const address = $.trim($('#reg-address').val());
	hideError(4);

	if(!address){
		showError(4, 'Введите адрес доставки'); return;
	}

	const $btn = $('#btn-save-address');
	setLoading($btn, true);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_save_address',
		_ajax_nonce: CFG.nonce,
		address: address,
		entrance: $.trim($('#reg-entrance').val()),
		intercom: $.trim($('#reg-intercom').val()),
		floor: $.trim($('#reg-floor').val()),
		apartment: $.trim($('#reg-apartment').val()),
		courier_comment: $.trim($('#reg-courier-comment').val()),
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			if(res.data.redirect){
				goToStep('complete');
				return;
			}
			goToStep(res.data.step);
		} else {
			showError(4, res.data ? res.data.message : 'Ошибка сохранения');
		}
	}).fail(function(){
		setLoading($btn, false);
		showError(4, 'Ошибка сети');
	});
}

/* ───── STEP 4: SKIP ───── */
function skipAddress(){
	const $btn = $('#btn-skip-address');
	setLoading($btn, true);

	$.post(CFG.ajax_url, {
		action: 'matreshka_reg_skip_address',
		_ajax_nonce: CFG.nonce,
	}, function(res){
		setLoading($btn, false);
		if(res.success){
			goToStep('complete');
		}
	}).fail(function(){
		setLoading($btn, false);
	});
}

/* ───── COUNTDOWN TIMER ───── */
function startCooldown(seconds){
	let remaining = seconds;
	$('#resend-timer').show();
	$('#btn-resend-sms').hide();
	updateCountdown(remaining);

	if(cooldownTimer) clearInterval(cooldownTimer);
	cooldownTimer = setInterval(function(){
		remaining--;
		if(remaining <= 0){
			clearInterval(cooldownTimer);
			$('#resend-timer').hide();
			$('#btn-resend-sms').show();
		} else {
			updateCountdown(remaining);
		}
	}, 1000);
}

function updateCountdown(sec){
	$('#countdown').text(sec);
}

/* ───── HELPERS ───── */
function setLoading($btn, loading){
	$btn.prop('disabled', loading);
	if(loading){
		$btn.data('original-text', $btn.text());
		$btn.html('<span class="reg-spinner"></span>');
	} else {
		$btn.text($btn.data('original-text') || $btn.text());
	}
}

function showError(step, msg){
	$('#reg-error-' + step).text(msg).slideDown(200);
}

function hideError(step){
	$('#reg-error-' + step).slideUp(200);
}

})(jQuery);

Youez - 2016 - github.com/yon3zu
LinuXploit