私のapp.coffeeのコードは、コーヒースクリプトを使用しています。ボディパーサーとメソッドovverideを配置しました
express = require("express")
everyauth = require("everyauth")
should = require("should")
fs = require("fs")
everyauth.debug = true
usersByLogin = krishna:
login: "krishna"
email: "krishna@blogab.com"
password: "krishna"
everyauth.password.loginWith("login").getLoginPath("/login").postLoginPath("
/login").loginView("bcore/login.jade").loginLocals((req, res, done) ->
setTimeout (->
done null,
title: "blogab - login"
), 200
).authenticate((login, password) ->
errors = []
errors.push "Missing login" unless login
errors.push "Missing password" unless password
return errors if errors.length
user = usersByLogin[login]
return [ "Login failed" ] unless user
return [ "Login failed" ] if user.password isnt password
user
).getRegisterPath("/register").postRegisterPath("
/register").registerView("bcore
/register.jade").registerLocals((req, res, done) ->
setTimeout (->
done null,
title: " Register"
), 200
).extractExtraRegistrationParams((req) ->
email: req.body.email
).validateRegistration((newUserAttrs, errors) ->
login = newUserAttrs.login
errors.push "Login already taken" if usersByLogin[login]
errors
).registerUser((newUserAttrs) ->
login = newUserAttrs[@loginKey()]
usersByLogin[login] = newUserAttrs
).loginSuccessRedirect("/admin").registerSuccessRedirect "/admin"
app = express.createServer
(express.bodyParser(),express.methodOverride(),
express.static(__dirname + "/public"),
express.session(secret: "htuayreve"), everyauth.middleware())
express.cookieParser(),
app.configure ->
app.set "view engine", "jade"
app.get "/", (req, res) ->
res.render "templates/default/index",
title: "blogab"
users: JSON.stringify(usersByLogin, null, 2)
app.get "/admin", (req, res) ->
res.render "bcore/admin",
title: "Blogab-admin"
users: JSON.stringify(usersByLogin, null, 2)
app.get "/login", (req, res) ->
res.render "bcore/login",
title: "login"
users: JSON.stringify(usersByLogin, null, 2)
app.get "/post", (req, res) ->
res.render "bcore/viewpost",
title: "login"
users: JSON.stringify(usersByLogin, null, 2)
app.get "/admin/post/new", (req, res) ->
res.render "bcore/newpost",
title: "Blogab-newpost"
users: JSON.stringify(usersByLogin, null, 2)
everyauth.helpExpress app
app.listen 1224, ->
console.log "blogab is running on port %d in %s mode",
app.address().port, app.setting
そしてnewpost.jadeではnewpostのコードです
!!! 5
html(xmlns='http://www.w3.org/1999/xhtml')
head
title
link(href='/css/master.css', rel='stylesheet', type='text/css')
body
h1
| New post
form#new_post.new_post(method='post', action='/posts')
.field
label(for='post_title') Title
br
input#post_title(type='text', name='title', size='30')
.field
label(for='post_content') Content
br
textarea#post_content(name='content', cols='40', rows='20')
.actions
input#post_submit(type='submit', value='Create Post')
p
br
a(href='/posts') Back
newpost.jade で投稿をクリックすると、/post を投稿できないと表示され、nodejs ベースの cms を作成しています。express body パーサーとメソッド ovveride を使用しました。