PageSourceSearch

https://static.lpgenerator.ru/media/js/login.js?v=11124

js lpgenerator.ru collected 2026-10-02 03:30:11 UTC 8,920 bytes, 307 lines download raw bytes

1/**
2 * @description Показывает попапы авторизации/регистрации на главных страницах и на странице промо партнерки
3 */
4
5var _loginDefaultData = {
6	enableSocial:			true,
7	enableSocialVk:			true,
8	enableSocialTwitter:	true,
9	requireEmailConfirm:	LPG.LOCALE === 'pl',
10	checkUrl:				'/accounts/registration/check/',
11	authUrl:				'/accounts/registration/login/',
12	regUrl:					LPG.LOCALE === 'pl' ? "/accounts/registration/registration/pl/" : "/accounts/registration/registration/"
13};
14
15Object.keys(_loginDefaultData).forEach(function(propName) {
16	if (!window.loginConfig.hasOwnProperty(propName)) {
17		window.loginConfig[propName] = _loginDefaultData[propName];
18	}
19});
20
21
22
23var templateSet = function (tplName, model, callback) {
24	var tplRaw = $("#tpl_authForm_"+tplName).html(),
25		$dialog = $( '#login_dialog' ),
26		oldClass = $dialog.data( 'tplName' ),
27		classPrefix = 'tpl__';/* при изменении не забыть поменять в стлях */
28
29	if (model) {
30		tplRaw = tplRaw.replace(/{@([\w ]+)@}/g, function(_, varName) {
31			return model[varName.trim()];
32		});
33	}
34
35	if ( oldClass !== undefined ) {
36		$dialog.removeClass( classPrefix + oldClass );
37	}
38	$dialog.addClass( classPrefix + tplName ).data( 'tplName', tplName );
39	$dialog.find( '.authForm' )[0].innerHTML = tplRaw;
40	if ( typeof callback === 'function' ) {
41		callback();
42	}
43};
44var setProgress = function(progress) {
45	document.getElementById( 'login_dialog' ).querySelector( '.line' ).style.width = progress + "%";
46};
47
48
49LPG.namespace('LPG.login');
50
51var loginModel = {
52	"enableSocialLogin":	loginConfig.enableSocial ? 'dib' : 'dn',
53	"enableSocialVk":		loginConfig.enableSocialVk ? 'dib' : 'dn',
54	"enableSocialTwitter":	loginConfig.enableSocialTwitter ? 'dib' : 'dn',
55	"requireName":			loginConfig.requireName ? 'dib' : 'dn',
56	"termsCheckedAttr":		LPG.LOCALE !== 'ru' ? '' : 'checked',
57	"privacyCheckedAttr":	LPG.LOCALE !== 'ru' ? '' : 'checked'
58};
59LPG.login = {
60	email:	null,
61	mobDt: new MobileDetect(window.navigator.userAgent),
62	utmData: {},
63	agreementsData: {
64		terms: false,
65		privacy: false
66	},
67	inProgress: false,
68
69	init: function (el) {
70		if (el) {
71			var utmData = el.getAttribute('utmData');
72			if (utmData) {
73				LPG.login.utmData = (new Function("return " + utmData))();
74			}
75		}
76		templateSet('check', loginModel);
77		setProgress(33);
78		setTimeout(function() {
79			$('#authForm_email')[0].focus();
80		}, 500);
81	},
82	ifEnterPress: function(e, action, el) {
83		if (e.key === 'Enter') {
84			LPG.login[action](el);
85		}
86	},
87
88	check: function(button) {
89		if (LPG.login.inProgress) {
90			return;
91		} else {
92			LPG.login.inProgress = true;
93		}
94		var that = this;
95		this.email = $('#authForm_email')[0].value;
96		LPG.forms.showLoaderIn(button, LT['Check']);
97		LPG.login.ajax(loginConfig.checkUrl, {
98			email: this.email
99		}, function(res) {
100			LPG.login.inProgress = false;
101			if (res) {
102				if (res.errors && Object.keys(res.errors).length > 0) {
103					LPG.login.errorShow(res.errors);
104					LPG.forms.hideLoaderIn(button);
105				} else {
106					if (res['is_exist']) {
107						templateSet('auth', loginModel);
108					} else {
109						templateSet('register', loginModel, that.watchAgreements.bind( that ) );
110						if (loginConfig.requireName) {
111							setTimeout(function() {
112								MASK.init({
113									onReady: function () {
114										MASK.Set($('#authForm_phone')[0], {countryCode: ['kr', 'de13']});
115									}
116								});
117							}, 100);
118						}
119					}
120					$("#cnt_authForm_email").html(LPG.login.email);
121					setProgress(66);
122					setTimeout(function() {		//и в авторизации и в реге есть поле
123						$('#authForm_password')[0].focus();
124					}, 100);
125				}
126			}
127		});
128	},
129	redirectMake: function ( redirect_to ) {
130		if ( typeof redirect_to !== 'undefined' && redirect_to === '/' && loginConfig.requireEmailConfirm ) {
131			templateSet( 'requireEmailConfirmation' );
132		} else {
133			document.location = loginConfig.regSuccessUrl || redirect_to;
134		}
135	},
136	auth: function(button) {
137		var that = this;
138		if (LPG.login.inProgress) {
139			return;
140		} else {
141			LPG.login.inProgress = true;
142		}
143		var password = $('#authForm_password')[0].value;
144		LPG.forms.showLoaderIn(button, LT['Auth']);
145		setProgress(66);
146		LPG.login.ajax(loginConfig.authUrl, {
147			email:		this.email,
148			password:	password
149		}, function(res) {
150			if (res) {
151				if (res['success']) {
152					that.redirectMake( loginConfig.authSuccessUrl || res[ 'redirect_to' ] || '/pages/' );
153				} else if (res['errors']) {
154					LPG.login.errorShow(res.errors);
155					LPG.forms.hideLoaderIn(button);
156					LPG.login.inProgress = false;
157				}
158			}
159		});
160	},
161	register: function (button) {
162		if (LPG.login.inProgress) {
163			return;
164		} else {
165			LPG.login.inProgress = true;
166		}
167		var nameObj = $('#authForm_name')[0];
168		var phoneObj = $('#authForm_phone')[0];
169		var that = this,
170			password = $('#authForm_password')[0].value;
171		LPG.forms.showLoaderIn(button, LT['Register']);
172		var data = {
173			email:		that.email,
174			password:	password,
175			name:		nameObj ? nameObj.value : null,
176			phone:		phoneObj ? phoneObj.value : null,
177			is_mobile:	( that.mobDt.mobile() !== null ),
178			terms:		that.agreementsData.terms,
179			privacy:	that.agreementsData.privacy
180		};
181		Object.assign(data, LPG.login.utmData);
182		LPG.login.ajax(loginConfig.regUrl, data, function(res) {
183			if (res) {
184				if (res['success']) {
185					try {
186						yaCounter17937001.reachGoal( 'reg-cg', function () {
187							that.redirectMake( loginConfig.regSuccessUrl || res['redirect_to'] );
188						}, that );
189					} catch ( e ) {
190						LPG.utils.cookie.setCookie( 'YA_COUNTER_EVENT', JSON.stringify( { "event" : "reg" } ), {
191							expires: ( 30 * 24 * 60 * 60 ),
192							path: '/',
193							domain: window.location.hostname
194						} );
195						that.redirectMake( loginConfig.regSuccessUrl || res['redirect_to'] );
196						if ( LPG.utils.urlData.getValue( 'js_debug' ) !== '' ) {
197							console.log( 'On reg metriks failed: ', e );
198						}
199					}
200				} else if (res.errors){
201					that.errorShow(res.errors);
202					LPG.forms.hideLoaderIn(button);
203					LPG.login.inProgress = false;
204				}
205			}
206		});
207	},
208	passwordRestore: function () {
209		templateSet('passwordRestore');
210		setProgress(66);
211		$('#authForm_email')[0].focus();
212	},
213	passwordReset: function () {
214		var email = $('#authForm_email')[0].value;
215		LPG.login.ajax('/accounts/registration/password-reset/', {
216			email:		email
217		}, function(res) {
218			if (res) {
219				if (res['success']) {
220					templateSet('passwordRestoreProcess');
221				} else if (res.errors){
222					LPG.login.errorShow(res.errors);
223				}
224			}
225		});
226	},
227
228	ajax: function(url, data, callback, method) {
229		var csrf = JSON.parse($.ajax({type: 'GET', url: '/accounts/csrf/', async: false}).responseText).token;
230		$.ajax({
231			url: url,
232			type: method || 'POST',
233			beforeSend: function (xhr) {
234				xhr.setRequestHeader('X-CSRFToken', csrf);
235			},
236			data: data,
237			success: function (response) {
238				callback(response);
239			},
240			error: function () { }
241		});
242	},
243
244	watchAgreements: function () {
245		this.checkAgreements();
246		this.initAgreementsListeners();
247	},
248	checkAgreements: function () {
249		this.agreementsData.terms = document.getElementById( 'authForm__termsOfUse_checkbox' ).checked;
250		this.agreementsData.privacy = document.getElementById( 'authForm__privacyPolicy_checkbox' ).checked;
251		this.switchButtonState();
252	},
253	initAgreementsListeners: function () {
254		var that = this;
255		$( '#authForm__termsOfUse_checkbox, #authForm__privacyPolicy_checkbox' ).on( 'change', function () {
256			that.agreementsData[ this.name ] = this.checked;
257			that.switchButtonState();
258		} );
259	},
260	switchButtonState: function () {
261		var isAgreeWithAll = true;
262		var keys = Object.keys( this.agreementsData );
263		var l = keys.length;
264
265		for ( var i = 0 ; i < l ; i += 1 ) {
266			if ( this.agreementsData[ keys[ i ] ] === false ) {
267				isAgreeWithAll = false;
268			}
269		}
270
271		document.querySelector( '.authForm__submitBtn' ).disabled = !isAgreeWithAll;
272	},
273
274	errorShow: function(errors) {
275		var i, ln, fields, errs, texts = [];
276		console.log('errors:', errors);
277		fields = Object.keys(errors);
278		for (i=0, ln =fields.length; i<ln; i++) {
279			errs = errors[fields[i]];
280			errs.forEach(function(text) {
281				texts.push(text);
282			});
283		}
284
285		$("#authForm_error").removeClass( 'hidden' ).html("<i class='ico_error'></i><div class='dib'>"+texts.join('<br>') + "</div>");
286	}
287};
288
289$('a[data-target="#login_dialog"]').on('click', function(el) {LPG.login.init(el.currentTarget);});
290
291// Open auth
292location.search.replace(/\?/, '').split('&').forEach(function(param) {
293	param = param.split('=')[0];
294	if (param === 'openAuthModal') {
295		$('a[data-target="#login_dialog"]').click();
296	}
297});
298
299
300$( function ( $ ) {
301	$( '#login_dialog' ).on( 'shown', function () {
302		$( 'body' ).css( { overflowY: 'hidden' } );
303	} );
304	$( '#login_dialog' ).on( 'hidden', function () {
305		$( 'body' ).css( { overflowY: '' } );
306	} );
307} );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.