I'm creating a login screen using AnugularJS and ExpressJS. I had created authentication API URL that work well in Postman plugin. When I make a post request on Angular, it return unexpected status code.
View
<input ng-model="login.name" type="text" placeholder="Admin User">
<input ng-model="login.password" type="password" placeholder="Password">
<div ng-click="logIn(login.name, login.password)">Login</div>
Admin controller
$scope.logIn = function logIn(username, password){
if(username !== undefined && password !== undefined) {
userservice.logIn(username, password).success(function(data){
authenticationservice.isLogged = true;
$window.sessionStorage.token = data.token;
$location.path("/dashboard");
}).error(function(status, data){
console.log(status);
console.log(data);
});
}
};
UserService
.factory('userservice',['$http','$location', function ($http,$location) {
return {
logIn: function(name, password){
return $http.post($location.protocol() + '://'+ $location.host() +':'+ $location.port() +'/api/authenticate',{name: name, password: password});
}
}
}]);
The Problem
Using Postman POST,
with {name: "abc","password:"123"} should return
{success:false,status:401};
But userservice.logIn(username, password) from admin controller return status 200 each time.