我正在关注此博客的教程
用于angualrJS中的身份验证和授权
还尝试在Stackoverflow中暂停一些实现 在这个链接上 $injector:modulerr : authentication in AngularJS applications
我一直收到这个错误 $ scope.setCurrentUser不是函数 它来自loginController
有人可以帮忙吗?
pmaster.factory(' AuthService',[' $ http','会话',功能($ http, 会议){ var authService = {};
authService.login = function (credentials) { return $http.get('/api/userLogin/' + credentials).then(function (data) { // this is the date coming from the Server //[{"sessionID":"aendypagaw5ytojlxjcvjgyo","userID":"ljanneh1","Role":"superAdmin"}] Session.create(data.sessionID, data.userID, data.Role); return data }); }; authService.isAuthenticated = function() { return !!Session.userId; }; authService.isAuthorized = function (authorizedRoles) { if (!angular.isArray(authorizedRoles)) { authorizedRoles = [authorizedRoles]; } return (authService.isAuthenticated() && authorizedRoles.indexOf(Session.userRole) !== -1); }; return authService; }]);
这是登录控件
pmaster.controller(' loginController',[' $ scope',' $ location', ' $ rootScope',' AUTH_EVENTS',' AuthService', 函数($ scope,$ location,$ rootScope,AUTH_EVENTS,AuthService) {
$rootScope.menuHide = true; $rootScope.sideHide = true; $scope.Login = function() { $scope.loading = true; var credentials = { 'username': $scope.username, 'password': $scope.password } var obj = credentials.username + "-" + credentials.password; AuthService.login(obj).then(function (data) { console.log(data); $rootScope.$broadcast(AUTH_EVENTS.loginSuccess); //$scope.setCurrentUser = function (data) //{ // $rootScope.$emit("setUserRoles", data); //} $scope.setCurrentUser(data); $location.path('/addBank'); $scope.loading = false; }, function (error) { $rootScope.$broadcast(AUTH_EVENTS.loginFailed); alert("Bad"); $scope.loading = false; }); } }]);