From ddaae5a91058d219d866e9f0f24d501d54a45213 Mon Sep 17 00:00:00 2001 From: Arvid Kahl Date: Fri, 16 Mar 2012 01:09:58 +0100 Subject: [PATCH 1/3] readme --- CONCEPT.md | 8 ++++++++ README.md | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 README.md 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 From 106ca8c99f1ad4d8004949c5e3cb634f3d27a3f8 Mon Sep 17 00:00:00 2001 From: Arvid Kahl Date: Fri, 16 Mar 2012 22:37:06 +0100 Subject: [PATCH 2/3] extended everyauth stuff, user database --- auth.coffee | 14 ++++++++++---- main.coffee | 4 ++++ user.coffee | 31 +++++++++++++++++++++++++++++++ views/layout.jade | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 user.coffee diff --git a/auth.coffee b/auth.coffee index 16dad4a..b830c20 100644 --- a/auth.coffee +++ b/auth.coffee @@ -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 '/' \ No newline at end of file diff --git a/main.coffee b/main.coffee index 50f5b3d..70c16d2 100644 --- a/main.coffee +++ b/main.coffee @@ -47,6 +47,10 @@ Articler = require('./articler.coffee').Articler scene = new Articler config.mainDBHost, config.mainDBPort, config.mainDB app.get '/', (req, res) -> + console.log req.user + if req.user is [] + console.log "Push new user to db!" + else "No need to push to db!" scene.findAll (err, docs) -> threeDocs = [] for tempDoc in [1..3] diff --git a/user.coffee b/user.coffee new file mode 100644 index 0000000..5a29779 --- /dev/null +++ b/user.coffee @@ -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 \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade index 55c957b..aa188ab 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -80,7 +80,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 From 09acfe38e3ddff08de539031fa97b38b36ea7fbb Mon Sep 17 00:00:00 2001 From: Arvid Kahl Date: Sat, 17 Mar 2012 22:32:43 +0100 Subject: [PATCH 3/3] user handling, starting updating views --- auth.coffee | 15 +++++++++++---- config.coffee | 22 +++++++++++++++++++++- main.coffee | 3 --- user.coffee | 10 ++++++++++ views/layout.jade | 5 +++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/auth.coffee b/auth.coffee index b830c20..f8518b0 100644 --- a/auth.coffee +++ b/auth.coffee @@ -8,16 +8,23 @@ everyauth.everymodule.moduleErrback (err) -> console.log "Auth ERROR - "+err everyauth.everymodule.findUserById (userId, callback) -> - users.findById userId, (err,res) -> + users.findByTwitterId userId, (err,res) -> if res.id - callback null, res + callback null, res.value else - users.saveById JSON.stringify(userId), {"name":"test"}, (saveErr, saveRes) -> - callback null, saveRes + callback null, null everyauth.twitter .consumerKey(config.twitterConsumerKey) .consumerSecret(config.twitterConsumerSecret) .findOrCreateUser((session, token, secret, 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 70c16d2..c24b246 100644 --- a/main.coffee +++ b/main.coffee @@ -48,9 +48,6 @@ scene = new Articler config.mainDBHost, config.mainDBPort, config.mainDB app.get '/', (req, res) -> console.log req.user - if req.user is [] - console.log "Push new user to db!" - else "No need to push to db!" scene.findAll (err, docs) -> threeDocs = [] for tempDoc in [1..3] diff --git a/user.coffee b/user.coffee index 5a29779..960f0e0 100644 --- a/user.coffee +++ b/user.coffee @@ -15,6 +15,16 @@ class User } @.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) diff --git a/views/layout.jade b/views/layout.jade index aa188ab..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"