AngularF2BWebAPI icon indicating copy to clipboard operation
AngularF2BWebAPI copied to clipboard

Unauthorized

Open tonymedrano opened this issue 11 years ago • 5 comments

Errors:

  • Failed to load resource: the server responded with a status of 404 (Not Found)
  • Failed to load resource: the server responded with a status of 401 (Unauthorized)

Everything was fine until start with currentUser.js

(function () { "use strict";

angular
    .module("common.services")
    .factory("currentUser", currentUser)

function currentUser() {
    var profile = {
        isLoggedIn: false,
        username: "",
        token: ""
    };

    var setProfile = function (username, token) {
        profile.username = username;
        profile.token = token;
        profile.isLoggedIn = true;
    };

    var getProfile = function () {
        return profile;
    }

    return {
        setProfile: setProfile,
        getProfile: getProfile
    }
}

})();

maiCtrl.js:

(function () { "use strict";

angular
.module("productManagement")
.controller("MainCtrl",
            ["userAccount",
             "currentUser",
               MainCtrl]);

function MainCtrl(userAccount, currentUser) {
    var vm = this;
    vm.isLoggedIn = function () {
        return currentUser.getProfile().isLoggedIn;
    };
    vm.userData = {
        userName: '',
        email: '',
        password: '',
        confirmPassword: ''
    };

    vm.registerUser = function () {
        vm.userData.confirmPassword = vm.userData.password;

        userAccount.registration.registerUser(vm.userData, function (data) {
            vm.confirmPassword = "";
            vm.message = "...Registration successful";
            vm.login();
        },
        function (response) {
            vm.isLoggedIn = false;
            vm.message = response.statusText + "\r\n";
            if (response.data.exceptionMessage) {
                vm.message += response.data.exceptionMessage;
            }

            if (response.data.modelState) {
                for (var key in response.data.modelState) {
                    vm.message += response.data.modelState[key] + "\r\n";
                }
            }
        });
    };

    vm.login = function () {
        vm.userData.grant_type = "password";
        vm.userData.userName = vm.userData.email;

        userAccount.login.loginUser(vm.userData,
            function (data) {
                vm.message = "";
                vm.password = "";
                currentUser.setProfile(vm.userData.userName, data.access_token);
            },
        function (response) {
            vm.password = "";
            vm.message = response.statusText + "\r\n";
            if (response.data.exceptionMessage) {
                vm.message += response.data.exceptionMessage;
            }

            if (response.data.error) {
                vm.message += response.data.error;
            }
        });
    };
}

})();

Thanks.

tonymedrano avatar Nov 04 '15 16:11 tonymedrano

Hope you can help me, thanks!

tonymedrano avatar Nov 04 '15 17:11 tonymedrano

I'm out off the office and won't be able to look at this until I return.  Have you seen this? http://blogs.msmvps.com/deborahk/angular-front-to-back-with-web-api-problem-solver/

Sent from my Verizon Wireless 4G LTE smartphone

-------- Original message -------- From: Tony Medrano [email protected] Date: 11/04/2015 9:02 AM (GMT-08:00) To: DeborahK/AngularF2BWebAPI [email protected] Subject: Re: [AngularF2BWebAPI] Unauthorized (#7)

Hope you can help me, thanks!

— Reply to this email directly or view it on GitHub.

DeborahK avatar Nov 04 '15 17:11 DeborahK

Hi Deborah, do you have an example with a nested json to see how it works?. Thanks

tonymedrano avatar Jan 27 '16 19:01 tonymedrano

And thank you for the course, it was great!

tonymedrano avatar Jan 27 '16 19:01 tonymedrano

I assume this issue has been resolved or is no longer relevant. I'm closing this issue. Thanks!

DeborahK avatar Jul 25 '19 16:07 DeborahK