PageSourceSearch

https://accounts.smartbear.com/static/js/auth.js

js smartbear.com collected 2026-10-09 21:48:47 UTC 11,619 bytes, 419 lines download raw bytes

1/*!
2  * domready (c) Dustin Diaz 2012 - License MIT
3  */
4!function(e,t){typeof module!="undefined"?module.exports=t():typeof define=="function"&&typeof define.amd=="object"?define(t):this[e]=t()}("domready",function(e){function p(e){h=1;while(e=t.shift())e()}var t=[],n,r=!1,i=document,s=i.documentElement,o=s.doScroll,u="DOMContentLoaded",a="addEventListener",f="onreadystatechange",l="readyState",c=o?/^loaded|^c/:/^loaded|c/,h=c.test(i[l]);return i[a]&&i[a](u,n=function(){i.removeEventListener(u,n,r),p()},r),o&&i.attachEvent(f,n=function(){/^c/.test(i[l])&&(i.detachEvent(f,n),p())}),e=o?function(n){self!=top?h?n():t.push(n):function(){try{s.doScroll("left")}catch(t){return setTimeout(function(){e(n)},50)}n()}()}:function(e){h?e():t.push(e)}})
5if (!Array.prototype.indexOf) {
6  Array.prototype.indexOf = function(elt /*, from*/)
7  {
8    var len = this.length >>> 0;
9
10    var from = Number(arguments[1]) || 0;
11    from = (from < 0)
12         ? Math.ceil(from)
13         : Math.floor(from);
14    if (from < 0)
15      from += len;
16
17    for (; from < len; from++)
18    {
19      if (from in this &&
20          this[from] === elt)
21        return from;
22    }
23    return -1;
24  };
25}
26
27var FormValidator = function() {};
28
29FormValidator.prototype = {
30	init: function() {
31		this.setErrorContainer();
32	},
33	setErrorContainer: function(elementId) {
34		this.errorContainer = document.getElementById(elementId || 'error-container');
35	},
36	generateValidationName: function(name) {
37		return 'validate' + 
38							name.charAt(0).toUpperCase() +
39							name.slice(1);
40	},
41	hasClass: function(el, cl) {
42		var regex = new RegExp('(?:^|\\s)' + cl + '(?!\\S)')
43		return el.className.match(regex);
44	},
45	addClass: function(el, cl) {
46		if ( !this.hasClass(el, cl) ) {
47			el.className += ' ' + cl;
48		}
49		return el;
50	},
51	removeClass: function(el, cl) {
52		var regex = new RegExp('(?:^|\\s)' + cl + '(?!\\S)');
53		el.className = el.className.replace(regex, '');
54		return el;
55	},
56	clearDisplayErrors: function() {
57		while (this.errorContainer.hasChildNodes()) {
58		    this.errorContainer.removeChild(this.errorContainer.lastChild);
59		}
60	},
61	// displayErrors: function(field) {
62	// 	for ( var r in field.rules ) {
63	// 		if ( field.rules.hasOwnProperty(r) ) {
64	// 			var rule = field.rules[r];
65	// 			if ( rule.isValid === false ) {
66	// 				var errorId = 'error-' + field.name + '-' + r
67	// 					, html = '<div id="' + errorId + '">' + rule.text + '</div>'
68	// 					, el = document.createElement('div');
69	// 				el.id = errorId;
70	// 				var icon = '<i class="icon-remove"></i> '
71	// 				el.innerHTML = icon + rule.text;
72	// 				this.errorContainer.appendChild(el);
73	// 			}
74	// 		}
75	// 	}
76	// },
77	displayErrors: function(field) {
78		for ( var r in field.rules ) {
79			if ( field.rules.hasOwnProperty(r) ) {
80				var rule = field.rules[r];
81				if ( rule.isValid === false ) {
82					var errElId = field.name + '-error';
83					var errEl = document.getElementById(errElId);
84
85					if (errEl) {
86						errEl.innerHTML = '<i class="icon-field-error"></i><span>' + rule.text + '</span>';
87					} else {
88						//errElHtml = '<div id="' + errElId + '">' + rule.text + '</div>';
89						errEl = document.createElement('span');
90						errEl.id = errElId;
91						errEl.className = 'field-error'
92						errEl.innerHTML = '<i class="icon-field-error"></i><span>' + rule.text + '</span>';
93						field.el.parentNode.appendChild(errEl);
94					}
95				}
96			}
97		}
98	},
99	manageErrors: function(field) {
100		if ( field.errors.length > 0 ) {
101			this.addClass(field.el.parentNode, 'error');
102		} else {
103			this.removeClass(field.el.parentNode, 'error');
104		};
105
106		this.displayErrors(field);
107	},
108	getFields: function(fields) {
109		for ( var field in fields ) {
110			if ( fields.hasOwnProperty(field) ) {
111				var id = 'id_' + field
112					, el = document.getElementById(id);
113
114				fields[field].el = el;
115			}
116		}
117	},
118	getValues: function(fields) {
119		for ( var field in fields ) {
120			if ( fields.hasOwnProperty(field) ) {
121				var value = fields[field].el.value;
122				fields[field].value = value;
123			}
124		}
125	},
126	validateRequired: function(fieldValue) {
127		return fieldValue.length > 0;
128	},
129	validatePattern: function(fieldValue, ruleValue) {
130		return ruleValue.test(fieldValue);
131	},
132	validateAscii: function(fieldValue) {
133		return /^[\x00-\x7F]*$/.test(fieldValue);
134	},
135	validateMinLength: function(fieldValue, ruleValue) {
136		return fieldValue.split('').length >= ruleValue;
137	},
138	validateUpper: function(fieldValue) {
139		return /[A-Z]/.test(fieldValue);
140	},
141	validateLower: function(fieldValue) {
142		return /[a-z]/.test(fieldValue);
143	},
144	validateDigit: function(fieldValue) {
145		return /[0-9]/.test(fieldValue);
146	},
147	validateSpecial: function(fieldValue) {
148		return /[^A-Za-z0-9]/.test(fieldValue);
149	},
150	validateGroup: function(fieldValue, ruleValue) {
151		minNumOfRules = ruleValue.slice(0,1);
152		validations = ruleValue.slice(1);
153		count = 0;
154
155		for ( var vi = 0, vl = validations.length; vi < vl; vi++ ) {
156			var validation = this.generateValidationName(validations[vi]);
157			if ( this[validation](fieldValue) ) {
158				count++;
159			}
160		}
161
162		return count >= minNumOfRules;
163	},
164	validateConsecutive: function(fieldValue, ruleValue) {
165		var regex = new RegExp('(.)' + new Array(ruleValue).join('\\1'));
166		return !regex.test(fieldValue);
167	},
168	validateSequence: function(fieldValue, ruleValue) {
169		var valueSplit = fieldValue.split('')
170		, characterLength = valueSplit.length
171		, converted = []
172		, hasSequence = false
173
174		for ( var vi = 0; vi < characterLength; vi++ ) {
175			converted.push(valueSplit[vi].charCodeAt());
176
177			var sequenceCount = 0;
178			if ( vi >= (ruleValue - 1) ) {
179				for ( var sl = 0; sl < ruleValue; sl++ ) {
180					var index = vi - sl;
181					index = index < 0 ? 0 : index;
182					if ( converted[index] === converted[vi] - sl) {
183						sequenceCount++;
184						if (sequenceCount >= ruleValue) {
185							hasSequence = true;
186							break;
187						}
188					}
189				}
190			}
191		}
192		return !hasSequence;
193	},
194	validateConfirmation: function(fieldValue, ruleValue) {
195		var targetValue = this.config[ruleValue].value;
196		return targetValue === fieldValue;
197	},
198	validateCopy: function(fieldValue, ruleValue) {
199		this.config[ruleValue.to].value = 
200			this.config[ruleValue.to].el.value = 
201			this.config[ruleValue.from].value;
202		return true;
203	},
204	validateZxcvbnScore: function(fieldValue, ruleValue) {
205		return zxcvbn(fieldValue).score >= ruleValue;
206	},
207	validate: function(fields) {
208		var validationResults = [];
209		for ( var f in fields ) {
210			if ( fields.hasOwnProperty(f) ) {
211				var field = fields[f];
212				var fieldPassthrough = true;
213				field.errors = [];
214				field.name = f;
215				for (  var r in field.rules ) {
216					var rule = field.rules[r];
217					if ( field.rules.hasOwnProperty(r) ) {
218						var isValid = false;
219
220						if ( rule.isGroupValidation ) {
221							isValid = this.validateGroup(field.value, rule.value);
222						} else {
223							isValid = this[
224								this.generateValidationName(r)
225							](field.value, rule.value);
226						};
227
228						rule.isValid = isValid;
229						validationResults.push(isValid);
230						if ( !isValid ) {
231							field.errors.push(rule.text)
232						}
233
234						if ( !fieldPassthrough ) {
235							rule.isValid = true;
236						}
237						if ( rule.isValid === false && rule.passthrough === false ) {
238							// break;
239							fieldPassthrough = false;
240						}
241					}
242				}
243				this.manageErrors(field);
244			}
245		}
246		return validationResults.indexOf(false) === -1;
247	},
248	clearSessionUTM : function() {
249		document.cookie.split(';').filter(cookie => {
250			if( cookie.toLowerCase().includes("sessionutm") ) {
251				const [name, rawValue] = cookie.split('=');
252				try {
253					const jsonValue = JSON.parse( decodeURIComponent(rawValue) );
254					if (typeof jsonValue === 'object') {
255						document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;`;
256					}
257				}
258				catch (error) {}
259			}
260		});
261	},
262	validateForm: function(event, form, config) {
263		// prevent default will stop submission if there is error in validation code
264		// event.preventDefault ? event.preventDefault() : event.returnValue = false;
265		event.preventDefault();
266		this.config = config;
267		this.getFields(this.config);
268		this.getValues(this.config);
269		this.clearDisplayErrors();
270		var isValid = this.validate(this.config);
271		this.clearSessionUTM();
272
273		// due to prevent default, sumbission needs to be retriggered
274		if ( isValid ) {
275			// console.log("Form is valid, submitting...");
276			form.submit()
277		} // else {
278		 //	console.log("Form is invalid, not submitting.");
279		// }
280
281		return isValid;
282	}
283}
284
285var authforms = {
286	login: {
287		email: {
288			rules: {
289				required: {
290					value: true,
291					text: 'Please enter your email address.',
292					passthrough: false,
293				},
294				pattern: {
295					value: /^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$/,
296					text: 'This doesn\'t look like a real e-mail address.',
297					passthrough: false,
298				}
299			}
300		},
301		password: {
302			rules: {
303				required: {
304					value: true,
305					text: 'Please enter your password.',
306					passthrough: false,
307				}
308			}
309		}
310	},
311	passwordResetForm: {
312		email: {
313			rules: {
314				required: {
315					value: true,
316					text: 'Please enter an email address.',
317					passthrough: false,
318				},
319				pattern: {
320					value: /^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$/,
321					text: 'This doesn\'t look like a real e-mail address.',
322					passthrough: false,
323				}
324			}
325		}
326	},
327	passwordResetConfirm: {
328		new_password1: {
329			rules: {
330				required: {
331					value: true,
332					text: 'Please enter a password.',
333					passthrough: false,
334				},
335				minLength: {
336					value: 8,
337					text: 'The password must be at least 8 characters long.',
338					passthrough: false,
339				}
340			}
341		},
342		new_password2: {
343			rules: {
344				// required: {
345				// 	value: true,
346				// 	text: 'Password confirmation field is required.',
347				// },
348				// confirmation: {
349				// 	value: 'new_password1',
350				// 	text: 'Passwords don\'t match.',
351				// }
352				//required: { isValid: true, text: 'Please confirm your password.' },
353				copy: {
354					value: {from: 'new_password1', to: 'new_password2'},
355					text: '',
356				}
357			}
358		}
359	}
360};
361
362var validator;
363;(function() {
364	domready(function() {
365		validator = new FormValidator();
366		validator.init();
367
368		// password reveal
369		var passwordField = document.getElementById('id_new_password1')
370			, passwordReveal = document.getElementById('password-reveal')
371			, passwordIsRevealed = false;
372
373		if ( passwordReveal ) {
374			passwordReveal.onclick = function(e) {
375				event.preventDefault ? event.preventDefault() : event.returnValue = false;
376
377				passwordIsRevealed = !passwordIsRevealed;
378				if ( !passwordIsRevealed ) {
379					validator.removeClass(passwordReveal, 'revealed');
380					passwordField.type = 'password';
381				}	else {
382					validator.addClass(passwordReveal, 'revealed');
383					passwordField.type = 'text';
384				}
385			};
386		}
387
388
389		if ( passwordField ) {
390			var passwordStrengthEl = document.getElementById('password-strength');
391			passwordField.onkeyup = function(e) {
392				var passwordStrength = zxcvbn(passwordField.value)
393					, html = '<div class="none"></div><span>None</span>';
394				if ( passwordField.value.length > 0 ) {
395					switch (passwordStrength.score) {
396						case 0:
397							html = '<div class="weak"></div><span>Weak</span>';
398							break;
399						case 1:
400							html = '<div class="mediocre"></div><span>Mediocre</span>';
401							break;
402						case 2:
403							html = '<div class="medium"></div><span>Medium</span>';
404							break;
405						case 3:
406							html = '<div class="good"></div><span>Good</span>';
407							break;
408						case 4:
409							html = '<div class="strong"></div><span>Strong</span>';
410							break;
411						default:
412							html;
413					}
414				}
415				passwordStrengthEl.innerHTML = html;
416			}
417		}
418	})
419})();

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.