{% extends "layout2.html" %} {% load i18n %} {% load static %} {% block css_include %} {% endblock %} {% block js_include %} {% endblock %} {% block content %} {% csrf_token %} {% if form.non_field_errors %} {# Print form errors correctly #} {% if form.non_field_errors %} {% translate "Form errors" %} {{ form.non_field_errors|safe }} {% endif %} {% endif %} {% translate "Radius Repository edition" %} {{ form.name.label }} {{form.name}} {{form.name.errors|safe}} {{ form.host.label }} {{form.host}} {{form.host.errors|safe}} {{ form.port.label }} {{form.port}} {{form.port.errors|safe}} {{ form.nas_id.label }} {{form.nas_id}} {{form.nas_id.errors|safe}} {{form.secret.label}} {{form.secret}} {{form.secret.errors|safe}} {{form.retry.label}} {{form.retry}} {{form.retry.errors|safe}} {{form.timeout.label}} {{form.timeout}} {{form.timeout.errors|safe}} {% translate "Test User authentication settings" %} × {% translate "User authentication test" %} {% translate "Username" %} {% translate "Password" %} {% endblock %} {% block jquery_code %} if (!String.prototype.endsWith) { String.prototype.endsWith = function(searchString, position) { var subjectString = this.toString(); if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.lastIndexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } /* Initialize select2 objects */ $('.select2').select2(); /* Switchery mandatory code */ var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch')); elems.forEach(function(html) { var switchery = new Switchery(html, { 'color': '#FA9834', }); }); function handle_form_errors(data){ if (typeof(data['form_errors']) !== 'undefined'){ $('.errorlist').remove(); $.each(data['form_errors'], function(field_name, error_list){ field_selector = $('#id_'+field_name); var ul = $('').insertAfter(field_selector); $.each(error_list, function(idx, err_msg){ console.log(err_msg); var li = $('').addClass('errorlist').attr('role', 'menuitem').appendTo(ul); var group = $('').text(err_msg).appendTo(li); }); }); } } /* User search test */ $('#user_search_test').on("click", function(e) { $('.test_user').html(''); $('.errorlist').remove(); $("#modal_test_user_search").modal('show'); e.preventDefault() }); $('#btn_send_user_search').on("click", function(e){ $('.test_user').html(''); username = $('#test_username').val(); password = $('#test_password').val(); url = "/authentication/radius/user_search_test/"; form_data = $('#radius_edit_form').serializeArray(); var indexed_data = {}; $.map(form_data, function(n, i){ indexed_data[n['name']] = n['value']; }); indexed_data['username'] = username; indexed_data['password'] = password; $.post(url, indexed_data, function(data){ status = data['status']; handle_form_errors(data); reason = data['reason']; if(status == 'true'){ $('#user_search_test_msg').html('{% translate "Successful connection : " %}' + reason + ''); $(".btn-save").removeAttr('disabled'); $(".btn-save").removeAttr('style'); } else{ $('#user_search_test_msg').html("{% translate 'Unable to authenticate user, reason: '%}" + reason + ""); } }); }); //}); // end of function() {% endblock %}