Skip to content

Commit

Permalink
Merge branch 'master' of nodester.com:/node/git/arvidkahl/6751-1067f4…
Browse files Browse the repository at this point in the history
…4123fb76654fa80e28cf17fdb5
  • Loading branch information
arvidkahl committed Jul 27, 2012
2 parents 8a0e5da + 09acfe3 commit bd6ed40
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CONCEPT.md
Original file line number Diff line number Diff line change
@@ -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


Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.
21 changes: 17 additions & 4 deletions auth.coffee
Original file line number Diff line number Diff line change
@@ -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 '/'
22 changes: 21 additions & 1 deletion config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
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);}}"
1 change: 1 addition & 0 deletions main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
41 changes: 41 additions & 0 deletions user.coffee
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd6ed40

Please sign in to comment.