Angularjs Passportjs(成功登录后)
我从这个优秀的资源中借用了以下代码: 但我不想使用Angularjs Passportjs(成功登录后),angularjs,node.js,passport.js,Angularjs,Node.js,Passport.js,我从这个优秀的资源中借用了以下代码: 但我不想使用成功重定向或失败重定向,因为我的前端是Angularjs应用程序。如果注册成功,我想告诉我的Angularjs前端,但我该怎么做?而不是: app.post('/signup', passport.authenticate('local-signup', { successRedirect : '/profile', // redirect to the secure profile section failureRedirect : '
成功重定向
或失败重定向
,因为我的前端是Angularjs应用程序。如果注册成功,我想告诉我的Angularjs前端,但我该怎么做?而不是:
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/profile', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
}));
您可以执行以下操作:
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting signup
if (! user) {
return res.send({ success : false, message : 'signupfailed' });
}
return res.send({ success : true, message : 'signup succeeded' });
})(req, res, next);
});
有关更多详细信息,请转到并查看底部的自定义回调部分。而不是执行以下操作:
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/profile', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
}));
您可以执行以下操作:
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting signup
if (! user) {
return res.send({ success : false, message : 'signupfailed' });
}
return res.send({ success : true, message : 'signup succeeded' });
})(req, res, next);
});
有关更多详细信息,请转到并查看底部的自定义回调部分。而不是执行以下操作:
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/profile', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
}));
您可以执行以下操作:
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting signup
if (! user) {
return res.send({ success : false, message : 'signupfailed' });
}
return res.send({ success : true, message : 'signup succeeded' });
})(req, res, next);
});
有关更多详细信息,请转到并查看底部的自定义回调部分。而不是执行以下操作:
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/profile', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
}));
您可以执行以下操作:
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting signup
if (! user) {
return res.send({ success : false, message : 'signupfailed' });
}
return res.send({ success : true, message : 'signup succeeded' });
})(req, res, next);
});
有关更多详细信息,请转到并查看底部的“自定义回调”部分。谢谢-因此您认为我应该将身份验证逻辑从单独的passport.js文件移回routes.js文件?无需“本地注册”是身份验证过程的命名策略。根据那篇文章passport.use('local-signup',newlocalstrategy({…所以当您调用passport.authenticate时('local-signup'它会寻找这种策略,并使用那里的流程设置。一个愚蠢的问题,但为什么Passport中的注册会有身份验证流程?如果我是在制作自己的系统,我会在用户注册后才对其进行身份验证。他们注册时会登录吗?文章显示的是,你可以在任何带有passport的策略,以及根据与authenticate方法一起使用的命名策略,都会产生不同的结果。如果您查看,它们具有本地登录和本地注册。本地注册创建用户并对其进行身份验证,而本地登录仅对其进行身份验证。谢谢您的帮助-因此您认为我应该将身份验证逻辑移回从我单独的passport.js文件到我的routes.js文件?不需要“local signup”是身份验证过程的命名策略。根据该文章passport.js。使用('local-signup',new local strategy({…所以当您调用passport.authenticate时('local-signup'它会寻找这种策略,并使用那里的流程设置。一个愚蠢的问题,但为什么Passport中的注册会有身份验证流程?如果我是在制作自己的系统,我会在用户注册后才对其进行身份验证。他们注册时会登录吗?文章显示的是,你可以在任何带有passport的策略,以及根据与authenticate方法一起使用的命名策略,都会产生不同的结果。如果您查看,它们具有本地登录和本地注册。本地注册创建用户并对其进行身份验证,而本地登录仅对其进行身份验证。谢谢您的帮助-因此您认为我应该将身份验证逻辑移回从我单独的passport.js文件到我的routes.js文件?不需要“local signup”是身份验证过程的命名策略。根据该文章passport.js。使用('local-signup',new local strategy({…所以当您调用passport.authenticate时('local-signup'它会寻找这种策略,并使用那里的流程设置。一个愚蠢的问题,但为什么Passport中的注册会有身份验证流程?如果我是在制作自己的系统,我会在用户注册后才对其进行身份验证。他们注册时会登录吗?文章显示的是,你可以在任何带有passport的策略,以及根据与authenticate方法一起使用的命名策略,都会产生不同的结果。如果您查看,它们具有本地登录和本地注册。本地注册创建用户并对其进行身份验证,而本地登录仅对其进行身份验证。谢谢您的帮助-因此您认为我应该将身份验证逻辑移回从我单独的passport.js文件到我的routes.js文件?不需要“local signup”是身份验证过程的命名策略。根据该文章passport.js。使用('local-signup',new local strategy({…所以当您调用passport.authenticate时('local-signup'它会寻找这种策略,并使用那里的流程设置。一个愚蠢的问题,但为什么Passport中的注册会有身份验证流程?如果我是在制作自己的系统,我会在用户注册后才对其进行身份验证。他们注册时会登录吗?文章显示的是,你可以在任何带有passport的策略,以及根据与authenticate方法一起使用的命名策略,都将产生不同的结果。如果您查看,它们具有本地登录和本地注册。本地注册创建用户并对其进行身份验证,而本地登录仅对其进行身份验证。