【问题标题】:Show current Username in angular Authentication在角度身份验证中显示当前用户名
【发布时间】:2016-02-22 13:45:50
【问题描述】:

我正在处理其他人已经制作的登录脚本。我的目标实际上是整合使用ng-option 而不是input。正如您从示例中看到的那样,这很有效。但是当我登录时,我看不到用户的数据。为什么?

完整代码:http://plnkr.co/edit/ImsqhVFVanCp5OXNisrA?p=preview

Controllers.js:

angular.module('Authentication')

.controller('LoginController',
['$scope', '$rootScope', '$location', 'AuthenticationService',
function ($scope, $rootScope, $location, AuthenticationService) {
    // reset login status
    AuthenticationService.ClearCredentials();
         $scope.users = [
                {"username": "test", "number": "13242342"},
                {"username": "2", "number": "00000000"},
                {"username": "3", "number": "0483184"},
            ];
    $scope.login = function () {
        $scope.dataLoading = true;
        AuthenticationService.Login($scope.username, $scope.password,        function(response) {
            if(response.success) {
                AuthenticationService.SetCredentials($scope.username,     $scope.password);
                $location.path('/');
            } else {
                $scope.error = response.message;
                $scope.dataLoading = false;
            }
        });
    };
}]);

【问题讨论】:

  • 我希望你意识到你不能在浏览器中进行授权......所有的登录凭据都暴露在你的脚本中
  • 当然,我只是在做一些测试来学习更好的角度:D
  • 只是检查......你会在这里看到很多奇怪的误解

标签: javascript angularjs angularjs-directive angular-ui-router


【解决方案1】:

在您的身份验证服务中,您正在像这样设置用户的凭据:

$rootScope.globals = {
    currentUser: {
        username: username,
        authdata: authdata
    }
};

所以在您看来,您需要将{{user.username}} 更改为{{globals.currentUser.username}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2020-11-15
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多