DeborahK / AngularF2BWebAPI

Files for the "Angular Front to Back With Web API" Pluralsight course by Deborah Kurata.
MIT License
124 stars 228 forks source link

Unauthorized #7

Closed tonymedrano closed 5 years ago

tonymedrano commented 8 years ago

Errors:

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 commented 8 years ago

Hope you can help me, thanks!

DeborahK commented 8 years ago

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 notifications@github.com Date: 11/04/2015 9:02 AM (GMT-08:00) To: DeborahK/AngularF2BWebAPI AngularF2BWebAPI@noreply.github.com Subject: Re: [AngularF2BWebAPI] Unauthorized (#7)

Hope you can help me, thanks!

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

tonymedrano commented 8 years ago

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

tonymedrano commented 8 years ago

And thank you for the course, it was great!

DeborahK commented 5 years ago

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