Checked all the examples #1357

Closed
wants to merge 2 commits into
from
Jump to file
+158 −60
Split
View
@@ -2,10 +2,10 @@
* Module dependencies.
*/
-var express = require('../../lib/express')
+var express = require('../..')
, hash = require('./pass').hash;
-var app = module.exports = express();
+var app = express();
// config
@@ -78,7 +78,7 @@ app.get('/', function(req, res){
});
app.get('/restricted', restrict, function(req, res){
- res.send('Wahoo! restricted area');
+ res.send('Wahoo! restricted area, click to <a href="/logout">logout</a>');
});
@tj
tj Oct 8, 2012 expressjs member

this stuff is all good, thanks

app.get('/logout', function(req, res){
@@ -90,7 +90,10 @@ app.get('/logout', function(req, res){
});
app.get('/login', function(req, res){
- res.render('login');
+ res.render('login', {
+ title: "Authentication Example",
+ user: req.session.user ? req.session.user.name : undefined
+ });
});
app.post('/login', function(req, res){
@@ -120,4 +123,4 @@ app.post('/login', function(req, res){
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
-}
+}
@@ -0,0 +1,11 @@
+ <footer>
+ <p>
+ <% if (user) { %>
+ Authenticated as <%= user %>, click to <a href="/logout">logout</a>.
+ <%} else {%>
+ <%= title %>
+ <% } %>
+ </p>
+ </footer>
+ </body>
+</html>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Authentication Example</title>
+ <title><%= title %></title>
<style>
body {
padding: 50px;
@@ -13,9 +13,10 @@
.success {
color: green;
}
+ footer {
+ margin-top: 50px;
+ color: gray;
+ }
</style>
</head>
<body>
- <%- body %>
- </body>
-</html>
@@ -1,3 +1,5 @@
+<% include head %>
+
<h1>Login</h1>
<%- message %>
Try accessing <a href="/restricted">/restricted</a>, then authenticate with "tj" and "foobar".
@@ -13,4 +15,6 @@ Try accessing <a href="/restricted">/restricted</a>, then authenticate with "tj"
<p>
<input type="submit" value="Login">
</p>
-</form>
+</form>
+
+<% include foot %>
View
@@ -37,10 +37,22 @@ var users = [
];
app.get('/', function(req, res){
- res.render('users', { users: users });
+ res.render('users', {
+ users: users,
+ title: "EJS example",
+ header: "Some users"
+ });
+});
+
+app.get('/next', function(req, res){
+ res.render('emails', {
+ users: users,
+ title: "EJS example",
+ header: "Some email address"
+ });
});
if (!module.parent) {
app.listen(3000);
console.log('Express app started on port 3000');
-}
+}
@@ -0,0 +1,12 @@
+<% include header/emails.html %>
+
+<h1>Emails</h1>
+<ul id="emails">
+ <% users.forEach(function(user){ %>
+ <li><%= user.email %> by <%= user.name %></li>
+ <% }) %>
+</ul>
+
+<p><a href="/">back</a></p>
+
+<% include footer/all.html %>
@@ -0,0 +1,7 @@
+ <footer>
+ <p>
+ <%= title %>
+ </p>
+ </footer>
+</body>
+</html>
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title> <%= title %> </title>
+ <style type="text/css">
+ body {
+ padding: 50px;
+ font: 13px Helvetica, Arial, sans-serif;
+ }
+ .header {
+ font-size: 4em;
+ }
+ footer {
+ margin-top: 50px;
+ color: gray;
+ }
+ </style>
+</head>
+<body>
@@ -0,0 +1,3 @@
+<% include all.html %>
+
+<h1 class="header">Some email address</h1>
@@ -0,0 +1,3 @@
+<% include all.html %>
+
+<h1 class="header">Some users</h1>
@@ -1,6 +1,12 @@
+<% include header/users.html %>
+
<h1>Users</h1>
<ul id="users">
<% users.forEach(function(user){ %>
<li><%= user.name %> <%= user.email %></li>
<% }) %>
-</ul>
+</ul>
+
+<p><a href="/next">next</a></p>
+
+<% include footer/all.html %>
@@ -1,3 +1,4 @@
body {
padding: 50px 80px;
- font: 14px "Helvetica Nueue", "Lucida Grande", Arial, sans-serif;}
+ font: 14px "Helvetica Nueue", "Lucida Grande", Arial, sans-serif;
+}
@@ -11,7 +11,7 @@ var express = require('../..')
// Config
-app.set('view engine', 'ejs');
+app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.use(express.cookieParser());
app.use(express.methodOverride());
@@ -35,4 +35,4 @@ app.put('/user/:id/edit', user.update);
app.get('/posts', post.list);
app.listen(3000);
-console.log('Express app started on port 3000');
+console.log('Express app started on port 3000');
@@ -1,4 +0,0 @@
-<ul>
- <li>Visit the <a href="/users">users</a> page</li>
- <li>Visit the <a href="/posts">posts</a> page</li>
-</ul>
@@ -0,0 +1,6 @@
+extends layout
+
+block content
+ ul
+ li Visit the <a href="/users">users</a> page
+ li Visit the <a href="/posts">posts</a> page
@@ -1,9 +0,0 @@
-<html>
- <head>
- <title><%= title %></title>
- <link href="/style.css" rel="stylesheet" />
- </head>
- <body>
- <%- body %>
- </body>
-</html>
@@ -0,0 +1,6 @@
+html
+ head
+ title= title
+ link(href="/style.css", rel="stylesheet")
+ body
+ block content
@@ -1,7 +0,0 @@
-<h1>Posts</h1>
-<dl id="posts">
- <% posts.forEach(function(post){ %>
- <dt><%= post.title %></dt>
- <dd><%= post.body %></dd>
- <% }) %>
-</dl>
@@ -0,0 +1,8 @@
+extends ../layout
+
+block content
+ h1 Posts
+ dl#posts
+ for post in posts
+ dt= post.title
+ dd= post.body
@@ -1,9 +0,0 @@
-<h1>Editing <%= user.name %></h1>
-<div id="user">
- <form method="post">
- <input type="hidden" value="put" name="_method" />
- <p>Name: <input type="text" value="<%= user.name %>" name="user[name]"/></p>
- <p>Email: <input type="text" value="<%= user.email %>" name="user[email]"/></p>
- <p><input type="submit" value="Save" /></p>
- </form>
-</div>
@@ -0,0 +1,14 @@
+extends ../layout
+
+block content
+
+ h1 Editing #{user.name}
+ #user
+ form(method="post")
+ input(type="hidden", value="put", name="_method")
+ p Name:
+ input(type="text", value= user.name, name="user[name]")
+ p Email:
+ input(type="text", value= user.email, name="user[email]")
+ p
+ input(type="submit", value="Save")
@@ -1,9 +0,0 @@
-<h1>Users</h1>
-<ul id="users">
- <% users.forEach(function(user, id){ %>
- <li>
- <a href="/user/<%= id %>"><%= user.name %></a>
- <a class="edit" href="/user/<%= id %>/edit">edit</a>
- </li>
- <% }) %>
-</ul>
@@ -0,0 +1,9 @@
+extends ../layout
+
+block content
+ h1 Users
+ #users
+ for user, i in users
+ li
+ a(href="/user/#{i}")= user.name
+ a.edit(href="/user/#{i}/edit") edit
@@ -1,4 +0,0 @@
-<h1><%= user.name %></h1>
-<div id="user">
- <p>Email: <%= user.email %></p>
-</div>
@@ -0,0 +1,6 @@
+extends ../layout
+
+block content
+ h1= user.name
+ #user
+ p Email: #{user.email}
@@ -1,4 +1,8 @@
+// first:
+// $ npm install redis
+// $ redis-server
+
/**
* Module dependencies.
*/
@@ -54,4 +58,4 @@ app.get('/client.js', function(req, res){
});
app.listen(3000);
-console.log('app listening on port 3000');
+console.log('app listening on port 3000');
@@ -1,4 +1,8 @@
+// first:
+// $ npm install redis
+// $ redis-server
+
var express = require('../..');
var app = express();
@@ -25,4 +29,4 @@ app.get('/', function(req, res){
});
app.listen(3000);
-console.log('Express app started on port 3000');
+console.log('Express app started on port 3000');