passportjs和angularjs路由错误

时间:2017-02-07 23:05:25

标签: javascript angularjs node.js passport.js angular-routing

我有一个非常大的问题,我不知道如何解决,我尝试在MEAN项目中使用passportJS实现登录验证。 当我尝试实施登录时 - 我一次又一次地收到此错误: enter image description here

这是我的代码: login.html

<form method="post">
   <input class="form_input" name="email" type="text" id="login_userName" ng-model="user.userName">
   <input class="form_input" name="password" type="password" id="login_pass" ng-model="user.password">
  <button class="form_btn" type="submit" ng-click="loginForm(user)">login!</button>
   </form>

client.js - 角度路由

SocialParking.controller('mainCtrl', function($scope, $http)
{
    $scope.loginForm = function(user){
       $http.post('/login', user).then(function (response) {
           alert("Success Login! " + response);
    });
   }
});

route.js - 登录代码无法到达此处!

app.post('/login', passport.authenticate('local-login'), function(req, res) {
    res.json(req.user);
});

passportConfig.js

    passport.use('local-login', new LocalStrategy(
    function(username, password, done) {
        User.findOne({
            username: username.toLowerCase()
        }, function(err, user) {
            // if there are any errors, return the error before anything else
            if (err)
                return done(err);

            // if no user is found, return the message
            if (!user)
                return done(null, false);

            // if the user is found but the password is wrong
            if (!user.validPassword(password))
                return done(null, false);

            // all is well, return successful user
            return done(null, user);
        });
    }
));

非常感谢你!

0 个答案:

没有答案