More in this section
Forums / Developing with Sitefinity / Fixing a MVC view that in the javascript has http://username:password@

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

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Scott
    Scott avatar
    11 posts
    Registered:
    17 Oct 2008
    01 Dec 2017
    Link to this post

    I have taken on a new client and they have several places where the original developer used the 'http://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=http://flightaware.com/live/flight/" + 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>

1 posts, 0 answered