Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $http://POST&;Passport.Js重定向_Javascript_Angularjs_Node.js_Passport.js - Fatal编程技术网

Javascript $http://POST&;Passport.Js重定向

Javascript $http://POST&;Passport.Js重定向,javascript,angularjs,node.js,passport.js,Javascript,Angularjs,Node.js,Passport.js,我有一个用于注册的多步骤Angular.js表单,它将所有用户输入保存到: $scope.user = {}; 然后我使用ng submit如下所示: <form class="css-form" name="myForm" ng-submit="signup()" novalidate> 注意:上述操作成功注册了新用户并将数据保存在MongoDB中 问题: 我正在使用Passport.Js服务器端对用户进行身份验证和注册。我正在使用本地注册策略 问题是,如果用户成功注册,则应自

我有一个用于注册的多步骤Angular.js表单,它将所有用户输入保存到:

$scope.user = {};
然后我使用
ng submit
如下所示:

<form class="css-form" name="myForm" ng-submit="signup()" novalidate>
注意:上述操作成功注册了新用户并将数据保存在MongoDB中

问题:

我正在使用Passport.Js服务器端对用户进行身份验证和注册。我正在使用本地注册策略

问题是,如果用户成功注册,则应自动将其重定向到特定页面,如果用户注册不成功,则应自动将其重定向到特定页面。 下面是我的服务器端代码:

    app.post('/signup', passport.authenticate('local-signup', {
        successRedirect : '/profile', // redirect to the secure profile section
        failureRedirect : '/', // redirect back to the signup page if there is an error
        failureFlash : true // allow flash messages
    }));
问题在于,无论注册成功还是注册失败,它都不会根据提供的路由重定向用户。它发回响应数据中的实际重定向页面代码。因此,成功注册后,应将用户发送到配置文件&如果不成功,则发送到主页

我似乎无法解决这个问题,也许我的整个技术都错了。
任何帮助都将不胜感激

不是舒尔,但它可能会有所帮助

在角度上:

$scope.signup = function(){
  return $http.post('/signup',$scope.user)
    .then(function(data) {
        location.replace(data.redirectUrl); // use appropriate function to update route
    });
};
在nodejs中:

   app.post('/signup',
      passport.authenticate('local-signup', { failWithError: true }),
      function(req, res, next) {
        // success
        return res.json({ redirectUrl: '/profile' });
      },
      function(err, req, res, next) {
        // error
        return res.json({ redirectUrl: '/' });
      }
   );

非常感谢你的回答。这很有效。您知道这种方法有什么风险吗?或者它安全吗?没有任何风险:这是通过xhr请求进行身份验证的标准方法。谢谢您的帮助。这件事已经拖了好几天了!
   app.post('/signup',
      passport.authenticate('local-signup', { failWithError: true }),
      function(req, res, next) {
        // success
        return res.json({ redirectUrl: '/profile' });
      },
      function(err, req, res, next) {
        // error
        return res.json({ redirectUrl: '/' });
      }
   );