- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我在我的应用程序中使用 Passport 模块(github 身份验证),我想根据操作进行重定向...我检查它是否只是普通登录,或者用户是否是第一次登录。
passport.use(new GitHubStrategy({
clientID: conf.github.app_id,
clientSecret: conf.github.app_secret,
callbackURL: conf.github.callback_url
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's GitHub profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the GitHub account with a user record in your database,
// and return that user instead.
Models_User.findOrCreateUser(profile, function(msg){
console.log("auth type:" + msg);
});
return done(null, profile);
});
}
));
在我的 findOrCreateUser 函数中,我检查它是否是新用户并执行所有 db 操作......为了测试,我让函数返回一个 msg 变量,它只是一个表示“login”或“new_registration”的字符串。
所以我的问题是如何“传输”我从 findOrCreateUser 获得的变量,以便在 Passport 身份验证完成后我可以相应地重定向(“/welcome”或“/back_again”)。
我的应用程序中的另一个 Passport 代码:
// GET /auth/github
// Use passport.authenticate() as route middleware to authenticate the
// request. The first step in GitHub authentication will involve redirecting
// the user to github.com. After authorization, GitHubwill redirect the user
// back to this application at /auth/github/callback
app.get('/auth/github',
passport.authenticate('github'),
//passport.authenticate('github', { scope: ['user', 'public_repo', 'gist'] }),
function(req, res){
// The request will be redirected to GitHub for authentication, so this
// function will not be called.
});
// GET /auth/github/callback
// Use passport.authenticate() as route middleware to authenticate the
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function function will be called,
// which, in this example, will redirect the user to the home page.
app.get('/auth/github/callback',
passport.authenticate('github', { successRedirect: '/', failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
最佳答案
在您的验证回调中,我会进行更改,以便 findOrCreateUser
函数将实际记录提供给回调,然后将其传递给 done()
,像这样:
Models_User.findOrCreateUser(profile, function(user){
console.log("auth type:" + msg);
return done(null, user);
});
// take this out, use the actual model above
//return done(null, profile);
现在,在验证后处理回调 URL 时,您可以检查此用户记录,看看它是否是新的(我假设它在这里有一个 isNew 属性):
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/login' }),
function(req, res) {
// successful auth, user is set at req.user. redirect as necessary.
if (req.user.isNew) { return res.redirect('/back_again'); }
res.redirect('/welcome');
});
关于node.js - Passport : different redirect for login and account registration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10111445/
我今天被 gcm 弄糊涂了。我不知道我的 registrationid 是否正确。我在以 APA 开头的 registrationid 前面有字符和冒号。模式是 xXXXxxX:APA...。我使用此
要求用户提供电子邮件地址,以便我们向他/她发送一封电子邮件以完成注册过程有什么好处?它当然无法抵御 (D)DoS 攻击,而且我看不出它如何提高安全性。 最佳答案 我想到的第一件事是它允许他们实际确认帐
任何支持使用 Web 服务或类似功能进行域名注册的域名注册商都不会告诉您成为经销商? 我没有注册那么多域名,我对支付经销商费用不感兴趣。 如果我可以在不支付预付费用的情况下成为经销商,那就没问题了。
我正在使用 Jersey 创建一个 Web 服务。 该服务应处理用户注册。我的计划是获取一个包含用户名和密码的注册请求,将它们都存储在 MySql 数据库中,并在每次用户想要登录时获取它。 我读过您应
iOS9的当前API状态更改为-setKeepAliveTimeout:handler:已过时。 到目前为止,这是iOS上的VoIP SIP应用程序可以维持其在SIP服务器上注册的唯一方法。 LinP
好吧,让我先解释一下我的情况: 我是“主办”事件的组织的一部分。例如,我们有一个年度训练营,溜冰,掷骰子/足球比赛,晚餐等。 现在他们要我设计他们的网站。我的习惯通常是先将其放在纸上,因此我正在尝试这
我知道最终无法完成。 但是,有哪些选择: a)限制人员创建多个帐户的选项, b)增加检测多个帐户/人的机会 类似博客的网络服务? (人们可以注册自己的博客) 更新: 我认为“限制选择权”已经很好地回答
我读到,用户觉得必须验证电子邮件才能完成简单的注册很烦人,但是删除这个额外的步骤并使用验证码来处理机器人会导致用户无法重新获得对其的控制权的不舒服的情况如果他们忘记了密码。 那么,该怎么办呢?除了电子
我想知道用户注册的最佳实践。我倾向于将站点注册存储在单独的注册表中,然后在通过电子邮件确认注册后将数据传输到用户表中。 这样做的好处是从用户表中读取的内容不会因从未激活的注册而困惑。另一个好处是电子邮
我有兴趣在注册表中添加其他字段,例如昵称和出生日期。 我正在使用 django-registration 0.8,我打算编写自己的自定义表单。我看过 django-profiles,我认为它的隐私控制
如何设置需要由管理员手动激活帐户的 django-registration? 在帐户持有人单击电子邮件中的链接后,我希望向管理员发送一封电子邮件,他还需要单击一个链接,然后该帐户才会处于事件状态。 d
在我的应用程序中,我有 AUTH_PROFILE_MODULE设置为 users.UserProfile .此 UserProfile 具有功能 create当新用户注册时应该调用它,然后创建 Use
我正在使用 django-registration,我正在尝试连接到它的信号以自动创建一个 UserProfile。 信号定义: from django.dispatch import Signal
我关注了 this page建立一个django注册网站。它非常棒,注册和身份验证都很好地包装了。 但是,它没有告诉我,在显示网页之前,我如何检查用户是否已登录,该用户是谁?以及如何在登录后将用户定向
我在我的最新产品上使用(和学习)Django,我刚刚安装并开始使用 django-registration允许我的用户自动注册的应用程序。 一切正常,但我正在考虑将每个新用户分配到一个特定的组(已经创
如何使用电子邮件而不是用户名进行身份验证 django-registration . 进一步了解如何在安装注册模块后实现此更改。 我要在这里编辑解决方案吗 Anyone knows a good ha
我正在尝试创建自定义配置文件以将其他字段添加到 django-registration。这是我到目前为止的代码 -- 在models.py中 from django.db import models
我正在使用 django-registration (请参阅: https://bitbucket.org/ubernostrum/django-registration )在我的一个项目中。 dja
我有注册过程,以便在用户单击注册时存储“电话”的自定义属性,如果用户在其中输入了电话号码。但是,我希望它是一个必填字段,如果留空则防止注册。我还没有找到任何关于如何执行此操作的 keycloak 文档
我有django注册设置,它会发送电子邮件-是的! 但是,我们决定将我的网站命名为“example.com”,这不是我决定使用的名称。很酷的名字,但不适合我。 如何将example.com更改为其他内
我是一名优秀的程序员,十分优秀!