Файл: style/web/static/ui/js/authorization.js
Строк: 96
<?php
$(document).ready(function(){
$('#loginForm, .loginForm').submit(function(e) {
e.preventDefault();
e.stopPropagation();
var csrftoken = getCookie('csrftoken');
var $form = $(this);
$.ajax({
url: $form.attr('action'),
type: "POST",
data: $form.serialize(),
success: function(response) {
// console.log('success login');
$form.find('div.error').remove();
$form.find('input.error').removeClass('error');
location.reload();
},
error: function(response) {
var form_errors = response.responseJSON.form_errors;
var template = _.template($('#formErrorTemplate').html());
$form.find('div.error').remove();
$form.find('input.error').removeClass('error');
$.each(form_errors, function(key, val) {
if (key === '__all__') {
$form.prepend(template({val: val}));
} else {
var $el = $form.find('[name="'+key+'"]');
$el.addClass('error').parent().prepend(template({val: val}));
}
});
},
});
});
$('#logout').click(function() {
$('#userLogoutWrap').addClass('hidden');
$('#userLoginWrap').removeClass('hidden');
$.post('/accounts/logout/', $('#logoutForm').serialize(), function() {
location.reload();
});
});
$('.openLoginModal').click(function(e) {
var $login_modal = $('#loginModal');
var $btn = $(this);
var type = $btn.data('type');
var project_id = $btn.data('project-id');
var template = _.template($('#loginModalBody').html());
$login_modal
.modal('show')
.find('.modal-content').html(template({type: type}));
$('.modalVkLogin').click(function(e) {
var vk_login_url = '/accounts/vk/login/?process=login&next=' + location.pathname;
if (type === 'vote') {
vk_login_url += '?voting=' + project_id;
}
location = vk_login_url;
});
});
});
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
?>