我对 node.js 很陌生,而且我遇到了 everyAuth 模块的问题。
我的问题是,我正在尝试创建一个应用程序,让用户通过 github oauth 登录并检查用户是否在数据库中被列入白名单。我想停止身份验证返回 true,直到我检查用户是否在白名单中。我尝试了几种方法来做到这一点,但无济于事。
任何人都可以解释一下吗?
调用github方法
everyauth.github
.appId(conf.github.appId)
.appSecret(conf.github.appSecret)
.redirectPath('/')
.findOrCreateUser (sess, accessToken, accessTokenExtra, ghUser) ->
promise = this.Promise()
users.findOrCreateByGhData ghUser, accessToken, accessTokenExtra, promise
promise;
用户类
conf = require '../config'
# Mongoose
mongoose = require 'mongoose'
Schema = mongoose.Schema
ObjectId = Schema.ObjectId
# Connect
mongoose.connect('mongodb://' + conf.db.user + ':' + conf.db.password + '@' + conf.db.url )
# User Schema
NewUser = new Schema
id :
type: Number
min: 18
index: true
login :
type: String
ghId :
type: Number
unique: true
date :
type: Date
default: Date.now
# Create Model
User = mongoose.model 'NewUser', NewUser
exports.findOrCreateByGhData = ( ghData , accessToken, accessTokenExtra, promise ) ->
User.find 'ghId': ghData.id , (err, docs) ->
if docs.length
console.log '=========User==============='
console.log docs
return promise.fulfill ['Nah its an error']
else
console.log '=========No user============='
user = new User()
user.login = ghData.login
user.ghId = ghData.id
user.save ( err ) ->
if err
throw err
console.log 'saved'
promise.fulfill user