1

I'm using deployd for simulation of http requests. I want to authenticate with my credentials to the database.

This is my controller code

.controller("authCtrl", function($scope, $http, $location, authUrl) {


$scope.authenticate = function (user, pass) {
    $http.post(authUrl, {
        username: user,
        password: pass
    }).success(function (data) {
        console.log(data);
        $location.path("main");
    }).error(function (error) {
        console.log("error");
        $scope.authenticationError = error;
    });
}

})

I get following message after entering one of credentials wrong.

Object { message: "bad credentials", status: 401 }

and I get following message after entering two credentials correctly.

Object { path: "/users", id: "11a58ccdcc31c9b863b7a5e63d9d672fdae…", uid: "e2ad770f0847f8ac" }

My problem is not to get "error" log. Only success event is being fired. Entering credentials wrong or right does not change the situation.

mehmet riza oz
  • 541
  • 6
  • 18

1 Answers1

0

Try catching error.status=401, example from https://github.com/moorthi07/MarsCMS/

 $scope.login = function () {
            $scope.newUser.$login().then(function (success) {
                $rootScope.$broadcast('user:login');
                $state.go('dashboard.intro'); 
            }, function (err) {
                if (err.status == 401) {

    //                $mdToast.show(
    //                    $mdToast.simple()
    //                    .content('Username or password invalid!')
    //                    .position('right bottom')
    //                );
                } else {

    //                $mdToast.show(
    //                    $mdToast.simple()
    //                    .content('An error occured. Please check log.')
    //                    .position('right bottom')
    //                );
                    console.log(err);
                };


            });
        };
MPV
  • 337
  • 3
  • 10