I have website where I'm trying to login over https with an AngularJS controller. Every time I try to log in I get a message like this
Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://example.com/'. This request has been blocked; the content must be served over HTTPS."
The site is running on nginx configured to redirect everything to https.
Here is my controller code.
app.controller("LoginCtrl", function ($scope, $http, $window) {
$scope.formData = {};
$scope.remember_me = false;
$scope.doLogin = function(){
var xsrf = $scope.formData;
$http({
url: "/login",
method: "POST",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function(obj) {
var str = [];
for(var p in obj)
if (obj.hasOwnProperty(p)){
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
},
data: xsrf
}).success(function(data) {
if( $window.location.pathname == '/login') {
$window.location.href = '/';
}
else{
$window.location.reload();
}
});
}
$scope.doJsonLogin = function(){
var xsrf = $scope.formData;
$http.post('/', { 'u': $scope.formData.username, 'p': $scope.formData.password, 'c': $scope.remember_me }).success(function(data) {
if( $window.location.pathname == '/login') {
$window.location.href = '/';
}
else{
$window.location.reload();
}
}).error(function (data, status, headers, config) {
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
alert("failed!");
});
}
});
My backend is running on Flask, and everything seems to be working properly on that part.
Currently it will stall like it failed, but when I reload the homepage it has me successfully logged in.
Why is AngularJS pushing XMLHttpRequest
to http when everything was loaded through https, and how do I fix it so it works properly?