1/* global GLOBAL_SETTINGS, $ */ 2 3'use strict'; 4 5(function(settings, $) { 6 var logger = false; 7 8 var INVALID_CLASS_NAME = settings.getInvalidClass(); 9 10 var $signInForm = $('#sign-in_form'); 11 var signInFormUrl = $signInForm.attr('action'); 12 var signInFormAjaxCheckUrl = $signInForm.attr('data-ajax-check'); 13 var $signInFormSubmitButton = $signInForm.find('button[type="submit"]'); 14 var $loginField = $signInForm.find('#sign-in__login'); 15 var $loginFieldComponent = $loginField.closest('.custom-label'); 16 var $passwordField = $signInForm.find('#sign-in__password'); 17 var $passwordFieldComponent = $passwordField.closest('.custom-label'); 18 var $csrfField = $signInForm.find('input[name="csrfmiddlewaretoken"]'); 19 var $formError = $signInForm.find('[data-login-error]'); 20 var defaultFormError = $formError.attr('data-default-error') || $formError.text(); 21 22 // ТекÑÑ Ð¾Ñибки Ð¿Ð¾Ð»Ñ Ð²ÑводиÑÑÑ css-пÑавилом content: attr(data-validation-message). 23 // ÐÑи блокиÑовке Ð²Ñ Ð¾Ð´Ð° он подменÑеÑÑÑ ÑообÑением ÑеÑвеÑа, поÑÑÐ¾Ð¼Ñ Ð¸ÑÑ Ð¾Ð´Ð½Ð¾Ðµ 24 // знаÑение ÑÐ¾Ñ ÑанÑеÑÑÑ Ð¸ воÑÑÑанавливаеÑÑÑ Ð¿ÐµÑед каждой оÑпÑавкой. 25 var passwordFieldDefaultMessage = $passwordFieldComponent.attr('data-validation-message'); 26 27 28 var submitSignInForm = function() { 29 30 $formError.hide().text(defaultFormError); 31 32 $loginField.val($loginField.val().trim()); // trim spaces in login field 33 34 var formData = $signInForm.serialize(); 35 36 if (logger) { 37 console.log('Trying to submit form!', $signInForm); 38 console.log('form action attr:', signInFormUrl); 39 console.log('form data-ajax-check attr:', signInFormAjaxCheckUrl); 40 console.log('clicked button:', $signInFormSubmitButton); 41 console.log('formData:', formData); 42 } 43 44 $passwordField.removeClass(INVALID_CLASS_NAME); 45 $loginField.removeClass(INVALID_CLASS_NAME); 46 47 $passwordFieldComponent.removeClass(INVALID_CLASS_NAME); 48 $loginFieldComponent.removeClass(INVALID_CLASS_NAME); 49 50 if (passwordFieldDefaultMessage) { 51 $passwordFieldComponent.attr('data-validation-message', passwordFieldDefaultMessage); 52 } 53 54 $.ajax({
55 url: signInFormAjaxCheckUrl, 56 data: formData, 57 type: 'POST', 58 dataType: 'json' 59 }).done(function(jsonResponse) { 60 if (logger) { 61 console.log(jsonResponse); 62 console.log('form submitted...'); 63 } 64 if (jsonResponse.status === 'mfa_required' && jsonResponse.redirect) { 65 window.location.assign(jsonResponse.redirect); 66 } else if (jsonResponse.status === 'error') { 67 $formError.text(jsonResponse.lockout_message || jsonResponse.detail || defaultFormError).show(); 68 switch (jsonResponse.type) { 69 case 'Not found': 70 $loginField.addClass(INVALID_CLASS_NAME); 71 $loginFieldComponent.addClass(INVALID_CLASS_NAME); 72 break; 73 case 'Invalid data': 74 if (jsonResponse.lockout_message) { 75 // ÐÑ Ð¾Ð´ заблокиÑован: показÑваем пÑиÑÐ¸Ð½Ñ Ð¸ вÑÐµÐ¼Ñ Ð¿Ð¾Ð²ÑоÑной 76 // попÑÑки вмеÑÑо ÑÑаÑиÑеÑкого «Wrong password». 77 $passwordFieldComponent.attr('data-validation-message', jsonResponse.lockout_message); 78 } 79 $passwordField.addClass(INVALID_CLASS_NAME); 80 $passwordFieldComponent.addClass(INVALID_CLASS_NAME); 81 } 82 } else { 83 // $signInForm.submit(); // оÑпÑавлÑÑÑ ÑоÑÐ¼Ñ Ð±Ð¾Ð»ÑÑе Ð½ÐµÑ ÑмÑÑла, Ñ.к. Ð¼Ñ Ñже авÑоÑизовалиÑÑ ÐЯÐСом. 84 window.location.assign(signInFormUrl); // пÑоÑÑо пеÑÐµÑ Ð¾Ð´Ð¸Ð¼ на url коÑоÑÑй пÑопиÑан в аÑÑибÑÑе action ÑоÑмÑ. 85 } 86 }).fail(function(xhr, status, errorThrown) { 87 var response = xhr.responseJSON || {}; 88 $formError.text(response.lockout_message || response.detail || $formError.attr('data-network-error') || defaultFormError).show(); 89 if (logger) { 90 console.log( 'Error: ' + errorThrown ); 91 console.log( 'Status: ' + status ); 92 console.dir( xhr ); 93 } 94 }).always(function() { 95 if (logger) { 96 console.log( 'The request is complete!' ); 97 } 98 }); 99 }; 100 101 102 var onFormSubmitButtonClick = function(evt) { 103 evt.preventDefault(); 104 submitSignInForm(); 105 }; 106 107 108 var onFormSubmitButtonKeyDown = function(evt) { 109 if ([13, 32].indexOf(evt.keyCode) > -1) { 110 evt.preventDefault(); 111 submitSignInForm(); 112 } 113 }; 114 115 116 $signInFormSubmitButton.on('click', onFormSubmitButtonClick); 117 $signInFormSubmitButton.on('keydown', onFormSubmitButtonKeyDown); 118})(GLOBAL_SETTINGS, $);
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.