diff --git a/CONCEPT.md b/CONCEPT.md index fd619d3..5e1ab0e 100644 --- a/CONCEPT.md +++ b/CONCEPT.md @@ -1,5 +1,13 @@ # spark +## todo +* disclaimer + * maybe "All the artwork seen here is the property of it's various creators. To support our seven source forums, we always link back to the original thread. However, if you see something that's yours and would like it removed, please let me know here." +* chat system +* hide stories / scenes +* feedback system +* complaint system +* only allow images from certain communites? ## modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdb76be --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Spark. +## What is Spark? +Spark is a community-based imageboard for authors. It references images (called 'Scenes') from popular art community sites (such as CGSociety) and allows users to add text (called 'Stories') of any size to the Scenes. +Images are not hosted on the site, they are referenced via URLs. Additional information must be provided for adding images to Spark. This serves the purpose of paying proper respect to intellectual property rights of the original authors of the images. +## Why is it on GitHub? +I want the project to flourish. If you have comments, issues or ideas, feel free to add them to Spark. +## How can I use Spark? +Just browse over to [spark.nodester.com](http://spark.nodester.com) and start using the site. +## How can I install it for myself? +Clone the repo. Easy as that. Run npm for the dependencies, run `main.coffee`. \ No newline at end of file diff --git a/auth.coffee b/auth.coffee index 16dad4a..f8518b0 100644 --- a/auth.coffee +++ b/auth.coffee @@ -1,17 +1,30 @@ 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.findByTwitterId userId, (err,res) -> + if res.id + callback null, res.value + else + callback null, null everyauth.twitter .consumerKey(config.twitterConsumerKey) .consumerSecret(config.twitterConsumerSecret) .findOrCreateUser((session, token, secret, user) -> - promise = @.Promise().fulfill user + users.findByTwitterId user.id, (err,res) -> + if res.id + user=res.value + else + newUser = {id:user.id,name:user.name,twitter:user} + user = newUser + users.saveById JSON.stringify(user.id), user, (saveErr, saveRes) -> + promise = @.Promise().fulfill user + ).redirectPath '/' \ No newline at end of file diff --git a/config.coffee b/config.coffee index 7734dd5..a5f3a52 100644 --- a/config.coffee +++ b/config.coffee @@ -11,4 +11,24 @@ config.sessionDBName = process.env.SPARK_SESSIONDBNAME || 'database_sessions' config.twitterConsumerKey = process.env.SPARK_TWITTERCONSUMERKEY || 'twitterconsumerkey' config.twitterConsumerSecret = process.env.SPARK_TWITTERCONSUMERSECRET || 'twitterconsumersecret' -module.exports = config \ No newline at end of file +module.exports = config + +# views for the user database +# "all": { +# "map": "function(doc) { emit(doc._id, doc);}" +# }, +# "byid": { +# "map": "function(doc) {if(doc._id) emit(doc._id,doc); }" +# }, +# "byTwitterId": { +# "map": "function(doc) {if(doc.twitter.id) emit(doc._id,doc); }" +# +# view for scene database +# "all": { +# "map": "function(doc) {\n emit(null, doc);\n}" +# }, +# "byid": { +# "map": "function(doc) {if(doc._id){emit(doc._id, doc);}}" +# }, +# "allbyid": { +# "map": "function(doc) {if(doc.url){emit(doc._id, null);}}" diff --git a/main.coffee b/main.coffee index 50f5b3d..c24b246 100644 --- a/main.coffee +++ b/main.coffee @@ -47,6 +47,7 @@ Articler = require('./articler.coffee').Articler scene = new Articler config.mainDBHost, config.mainDBPort, config.mainDB app.get '/', (req, res) -> + console.log req.user scene.findAll (err, docs) -> threeDocs = [] for tempDoc in [1..3] diff --git a/user.coffee b/user.coffee new file mode 100644 index 0000000..960f0e0 --- /dev/null +++ b/user.coffee @@ -0,0 +1,41 @@ +# 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 + + findByTwitterId: (mykey, callback) -> + @.db.view 'spark-user/byTwitterId', {key: JSON.stringify(mykey)}, (err, res) -> + if (err) + callback err, null + else + if res.length>0 + callback null, res[0] + else + callback null, res + + 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 \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade index 55c957b..e65d7d6 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -41,8 +41,9 @@ html p.navbar-text.pull-right.highlightLogin - if (everyauth.loggedIn) span= "Logged in as " - img.twitterImage(src=everyauth.twitter.user.profile_image_url) - span= " "+ everyauth.twitter.user.name +" - " + - if (user.twitter) + img.twitterImage(src=user.twitter.profile_image_url) + span= " "+ user.name +" - " a(href="/logout")= "Logout" - else a(href= "/auth/twitter")= "Login with Twitter" @@ -80,7 +81,7 @@ html a(href= "http://coffeescript.org/")="Coffee-Script" |, a(href= "https://github.com/tomgallacher/gzippo")="gzippo" - | and + | and a(href= "http://twitter.github.com/bootstrap/")="Twitter Bootstrap" |. br