-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extended everyauth stuff, user database
- Loading branch information
Showing
4 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
config = require './config.coffee' | ||
User = require('./user.coffee').User | ||
users = new User config.mainDBHost, config.mainDBPort, 'spark-user' | ||
|
||
everyauth = module.exports = require 'everyauth' | ||
everyauth.debug = false | ||
everyauth.everymodule.moduleErrback (err) -> | ||
console.log "Auth ERROR - "+err | ||
|
||
everyauth.everymodule.findUserById (userId, callback) -> | ||
callback null, "moo" | ||
# callback has the signature, function (err, user) {...} | ||
everyauth.everymodule.findUserById (userId, callback) -> | ||
users.findById userId, (err,res) -> | ||
if res.id | ||
callback null, res | ||
else | ||
users.saveById JSON.stringify(userId), {"name":"test"}, (saveErr, saveRes) -> | ||
callback null, saveRes | ||
|
||
everyauth.twitter | ||
.consumerKey(config.twitterConsumerKey) | ||
.consumerSecret(config.twitterConsumerSecret) | ||
.findOrCreateUser((session, token, secret, user) -> | ||
promise = @.Promise().fulfill user | ||
promise = @.Promise().fulfill user | ||
).redirectPath '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# User Class - Handles all user functions | ||
config = require './config.coffee' | ||
cradle = require 'cradle' | ||
|
||
class User | ||
constructor: (host, port, collection) -> | ||
@.connect = new cradle.Connection host, port, { | ||
secure: false | ||
auth: { | ||
username: config.mainDBUser | ||
password: config.mainDBPass | ||
} | ||
cache: true | ||
raw: false | ||
} | ||
@.db = @.connect.database collection | ||
|
||
findById: (mykey, callback) -> | ||
@.db.view 'spark-user/byid', {key: JSON.stringify(mykey)}, (err, res) -> | ||
if (err) | ||
callback err, null | ||
else | ||
if res.length>0 | ||
callback null, res[0] | ||
else | ||
callback null, res | ||
saveById: (id, data, callback) -> | ||
@.db.save id, data, (err, res) -> | ||
callback err, res | ||
|
||
exports.User = User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters