Fixing a MVC view that in the javascript has http://username:password@ - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Fixing a MVC view that in the javascript has http://username:password@

  • Fixing a MVC view that in the javascript has http://username:password@
  • I have taken on a new client and they have several places where the original developer used the 'username:password'  format of authentication. I want to change that so it is more secure and browsers do not block it. I do not know much about MVC.

    @model SitefinityWebApp.Mvc.Models.FlightDeparturesModel

    <div style="overflow-x:auto;">
        <div id="departures"></div>
    </div>

    <script type="text/javascript">
        var usn = '********';
        var apikey = '*******';
        var simplechr = 'testy';
        var fxml_url = 'https://' + usn +':' + apikey +'@flightxml.flightaware.com/json/FlightXML2/';

        $(document).ready(function ()
            $.ajax(
                type: 'GET',
                url: fxml_url + 'Departed',
                data: 'airport': 'KTBN', 'howMany': 10, offset: 0 ,
                success: function (result)
                    if (result.error)
                        alert('Failed to fetch flight: ' + result.error);
                        return;
                   
                    // create the Departures <table>
                    var $arTable = $('<table class="flightTable">');
                    // caption
                    $arTable.append('<caption class="flightCaption">Departures</caption>')
                        // thead
                        .append('<thead class="flightTableHeader">').children('thead')
                        .append('<tr />').children('tr').append('<th>Ident</th><th>Type</th><th>To</th><th>Depart</th><th>Arrive</th>');
                    //tbody
                    var $tbody = $arTable.append('<tbody class="flightTbody" />').children('tbody');
                    //loop through arrivals
                    for (departure of result.DepartedResult.departures)
                        //convert times
                        var arTime = new Date(departure.actualarrivaltime * 1000);

                        var dpTime = new Date(departure.actualdeparturetime * 1000);
                        var options =
                            weekday: "short", month: "short", day: "numeric",
                            hour: "2-digit", minute: "2-digit", timeZoneName: "short"
                       
                        // add row
                        $tbody.append('<tr />').children('tr:last')
                            .append("<td class='flightIdent'><a href=flightaware.com/.../" + departure.ident + " target=_blank>" + departure.ident + "</a></td>")
                            .append("<td class='flightType'>" + departure.aircrafttype + "</td>")
                            .append("<td class='flightOrigin'>" + departure.originName + "(" + departure.origin + ")</td>")
                            .append("<td class='flightDpTime'>" + dpTime.toLocaleTimeString("en-US", options).slice(0, 12) + "<br>" + dpTime.toLocaleTimeString("en-US", options).slice(12) + "</td>")

                            .append("<td class='flightArTime'>" + arTime.toLocaleTimeString("en-US", options).slice(0, 12) + "<br>" + arTime.toLocaleTimeString("en-US", options).slice(12) + "</td>")
                   
                    // add table to dom
                    $arTable.appendTo('#departures');
                ,
                error: function (jqXHR)
                    console.log("ajax error " + jqXHR.status);
                ,
                dataType: 'jsonp',
                jsonp: 'jsonp_callback',
                xhrFields: withCredentials: true
            );
        );
    </script>