Skip to content

Commit

Permalink
bootstrapped, jaded
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidkahl committed Mar 6, 2012
1 parent 444f166 commit 3d12e1e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 69 deletions.
11 changes: 2 additions & 9 deletions auth.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
everyauth = module.exports = require 'everyauth'
everyauth.debug = true
everyauth.debug = false
everyauth.everymodule.moduleErrback (err) ->
console.log err
everyauth.twitter
.consumerKey('umY6lNpuhh4B6I1BshJMLA')
.consumerSecret('I4qEqVHgZM0LEVY61sE9w1tFW5lTATCxOy7CwaO0NA')
.findOrCreateUser((session, token, secret, user) ->
promise = @.Promise().fulfill user
).redirectPath '/'

#everyauth = module.exports = require 'everyauth'
#
#everyauth.twitter.consumerKey 'umY6lNpuhh4B6I1BshJMLA'
#everyauth.twitter.consumerSecret 'I4qEqVHgZM0LEVY61sE9w1tFW5lTATCxOy7CwaO0NA'
#everyauth.twitter.findOrCreateUser ( sess, accessToken, accessSecret, twitUser, reqres) ->
# console.log twitUser.screen_name
).redirectPath '/'
3 changes: 2 additions & 1 deletion config.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
config = {}
config.port = 5984
config.host = 'arvidkahl.iriscouch.com'
config.name = 'sessions'
config.sessionDBName = 'sessions'

module.exports = config
31 changes: 16 additions & 15 deletions main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ md = require('node-markdown').Markdown
auth = require './auth.coffee'
config = require './config.coffee'

#session perstistence
connectCouchDB = require('connect-couchdb')(exp)
# Session perstistence implemented with CouchDB
sessionDB = require('connect-couchdb')(exp)

#auth.helpExpress app

Expand All @@ -22,39 +22,40 @@ app.configure () ->
app.use exp.methodOverride()
app.use exp.bodyParser()
app.use exp.cookieParser()
app.use exp.session {secret: 'nawollenwirdochmalsehn', store: new connectCouchDB({host: config.host,name: 'sessions', reapInterval: 600000, compactInterval: 300000})}
app.use exp.session {secret: 'nawollenwirdochmalsehn', store: new sessionDB({host: config.host,name: config.sessionDBName, reapInterval: 600000, compactInterval: 300000})}
app.use exp.compiler { src: __dirname + '/public', dest: __dirname + '/public', enable: ['less'] }
app.use exp.static __dirname + '/public'
app.use auth.middleware()

auth.helpExpress app

# Articler Class
Articler = require('./articler').Articler
article = new Articler config.host, config.port

app.get '/', (req, res) ->
if (req.session.auth)
console.log "You are authed."
#console.log req.session.auth.twitter
user = req.session.auth.twitter.user
else
console.log "You are not authed."
# if (req.session.auth)
# console.log "You are authed."
# else
# console.log "You are not authed."
article.findAll (err, docs) ->
console.log "GET /"
# console.log "GET /"
# console.log req.user
res.render 'index', {
locals: {
title: 'Sparks'
articles: docs
user: user
}
}

app.get '/new', (req, res) ->
console.log "GET /new"
res.render 'new', {locals: {title: 'Sparks / New Post'}}
# console.log "GET /new"
console.log req.user
res.render 'new', {locals: {title: 'Sparks / New Post - '}}

app.post '/new', (req, res) ->
console.log "POST /new"
console.log req.param 'title'
# console.log "POST /new"
# console.log req.param 'title'
article.save {
title: req.param 'title'
body: req.param 'body'
Expand Down
51 changes: 8 additions & 43 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
div.navbar.navbar-fixed-top
div.navbar-inner
div.container-fluid
a(href='#').brand #{title}
div.nav-collapse
ul.nav
li.active
a(href='#') Home
li
a(href='#') About
li
a(href='#') Contact
p.navbar-text.pull-right
- if (typeof(user) != "undefined")
span= "Logged in as "+user.name+" "
a(href="/logout")= "Logout"
- else
a(href= "/auth/twitter")= "Login with Twitter"
div.container
h1 #{title}
div.row
div.span10
- each article in articles
.article
h2= article.title
span.created= article.created_at
span.body= article.body
div.span2
h3 Secondary content
footer
p ©
a(href= "http://www.arvidkahl.de")="Arvid Kahl"
| . Website is built with
a(href= "http://nodejs.org")= "Node.js"
|,
a(href= "http://www.http://expressjs.com")="Express"
|,
a(href= "http://couchdb.apache.org/")="CouchDB"
|,
a(href= "http://lesscss.org/")="LESS"
| and
a(href= "http://coffeescript.org/")="Coffee-Script"
|.
div.span10
- each article in articles
.article
h1= article.title
span.created= article.created_at
span.body= article.body
div.span2
h3 Secondary content
37 changes: 36 additions & 1 deletion views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,39 @@ html
head
include bootstrap
title= title
body!= body
body
div.navbar.navbar-fixed-top
div.navbar-inner
div.container-fluid
a(href='#').brand #{title}
div.nav-collapse
ul.nav
li
a(href='#') Home
li
a(href='#') About
li
a(href='#') Contact
p.navbar-text.pull-right
- if (everyauth.loggedIn)
span= "Logged in as "+ everyauth.twitter.user.name +" "
a(href="/logout")= "Logout"
- else
a(href= "/auth/twitter")= "Login with Twitter"
div.container
div.row!= body

footer
p ©
a(href= "http://www.arvidkahl.de")="Arvid Kahl"
| . Website is built with
a(href= "http://nodejs.org")= "Node.js"
|,
a(href= "http://www.http://expressjs.com")="Express"
|,
a(href= "http://couchdb.apache.org/")="CouchDB"
|,
a(href= "http://lesscss.org/")="LESS"
| and
a(href= "http://coffeescript.org/")="Coffee-Script"
|.

0 comments on commit 3d12e1e

Please sign in to comment.