我的 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 中发布它时,它说无法发布/发布,我正在创建基于 nodejs 的 cms,我使用了 express body parser 和方法 ovveride