0
votes

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,

http://localhost:8080/api/authenticate

with {name: "abc","password:"123"} should return

{success:false,status:401};

But userservice.logIn(username, password) from admin controller return status 200 each time.

1

1 Answers

-1
votes

Here is a list of all the status codes: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.

401 stands for unauthorized, which probably means your login data is not correct or there is a bug at the server side.