From 3d12e1e5773890270a0b846458e860904778615b Mon Sep 17 00:00:00 2001 From: Arvid Kahl Date: Tue, 6 Mar 2012 13:30:26 +0100 Subject: [PATCH] bootstrapped, jaded --- auth.coffee | 11 ++-------- config.coffee | 3 ++- main.coffee | 31 ++++++++++++++-------------- views/index.jade | 51 ++++++++--------------------------------------- views/layout.jade | 37 +++++++++++++++++++++++++++++++++- 5 files changed, 64 insertions(+), 69 deletions(-) diff --git a/auth.coffee b/auth.coffee index f07659f..21e4c49 100644 --- a/auth.coffee +++ b/auth.coffee @@ -1,5 +1,5 @@ everyauth = module.exports = require 'everyauth' -everyauth.debug = true +everyauth.debug = false everyauth.everymodule.moduleErrback (err) -> console.log err everyauth.twitter @@ -7,11 +7,4 @@ everyauth.twitter .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 \ No newline at end of file + ).redirectPath '/' \ No newline at end of file diff --git a/config.coffee b/config.coffee index f6d97de..e867882 100644 --- a/config.coffee +++ b/config.coffee @@ -1,5 +1,6 @@ config = {} config.port = 5984 config.host = 'arvidkahl.iriscouch.com' -config.name = 'sessions' +config.sessionDBName = 'sessions' + module.exports = config \ No newline at end of file diff --git a/main.coffee b/main.coffee index 2f0e496..f470d42 100644 --- a/main.coffee +++ b/main.coffee @@ -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 @@ -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' diff --git a/views/index.jade b/views/index.jade index 5a90ca5..3bf2e71 100644 --- a/views/index.jade +++ b/views/index.jade @@ -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 \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade index 61c2c90..bf6a894 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -3,4 +3,39 @@ html head include bootstrap title= title - body!= body \ No newline at end of file + 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" + |. \ No newline at end of file