我有三种用户:
- 查看者(登录链接:auth/ v /twitter)
- 创建者(登录链接:auth/ c /twitter)
- 管理员(登录链接:auth/ a /twitter)
而且我还有 3 个不同的数据库/集合
- c_viewer
- c_creator
- c_admin
每种用户都有不同的登录链接。
现在让我们看一下代码
var passport = require('passport')
,TwitterStrategy = require('passport-twitter').Strategy;
passport.use(new TwitterStrategy({
consumerKey: config.development.tw.consumerKey,
consumerSecret: config.development.tw.consumerSecret,
callbackURL: config.development.tw.callbackURL
},
function(token, tokenSecret, profile, done) {
process.nextTick(function(req, res) {
var query = User.findOne({ 'twId': profile.id});
query.exec(function(err, oldUser){
if(oldUser) {
done(null, oldUser);
} else {
var newUser = new User();
newUser.twId = profile.id;
newUser.twUsername = profile.username;
newUser.name = profile.displayName;
newUser.avatar = profile.photos[0].value;
-> newUser.age = req.body.creator.age; ???
newUser.save(function(err) {
if(err) throw err;
done(null, newUser);
});
};
});
});
}));
app.get('/auth/c/twitter', passport.authenticate('twitter'),
function(req, res) {
var userUrl = req.url;
// codes to pass the userUrl to TwitterStrategy
});
app.get('/auth/twitter/callback',
passportForCreator.authenticate('twitter', { successRedirect: '/dashboard', failureRedirect: '/' }));
这是我的表格
<input type="text" name="creator[age]" placeholder="How old are you?">
<a id="si" class="btn" href="/auth/c/twitter">Sign in</a>
我的问题:
1.我们可以将<input>
数据传递给登录过程吗?所以我们可以读取 TwitterStrategy 中的输入数据,并保存到数据库
2.我们可以从登录 url (auth/ c /twitter) 中获取“c”并将其传递给 TwitterStrategy 吗?所以我们可以简单地签入不同的数据库/集合并更改查询。