-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 855548f
Showing
1,644 changed files
with
244,103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
var express = require('express'); | ||
var bodyParser = require('body-parser') | ||
var app = express(); | ||
app.locals.pretty = true; | ||
app.set('view engine', 'jade'); | ||
app.set('views', './views'); | ||
app.use(express.static('public')); | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
app.get('/form_receiver', function(req, res){ | ||
var title = req.query.title; | ||
var description = req.query.description; | ||
res.send(title+','+description); | ||
}); | ||
app.post('/form_receiver',function(req, res){ | ||
var title = req.body.title; | ||
var description = req.body.description; | ||
res.send(title+','+description); | ||
}) | ||
app.get('/form', function(req, res){ | ||
res.render('form'); | ||
}); | ||
app.get('/topic/:id', function(req, res){ | ||
var topics = [ | ||
'Javascript is ...', | ||
'Nodejs is ...', | ||
'Express is ...' | ||
]; | ||
var output = ` | ||
<a href="/topic/0">Javascript</a><br> | ||
<a href="/topic/1">Nodejs</a><br> | ||
<a href="/topic/2">Express</a><br> | ||
${topics[req.params.id]} | ||
` | ||
res.send(output); | ||
}) | ||
app.get('/topic/:id/:mode', function(req, res){ | ||
res.send(req.params.id+','+req.params.mode) | ||
}) | ||
app.get('/template', function(req, res){ | ||
res.render('temp', {time:Date(), _title:'Jade'}); | ||
}) | ||
app.get('/dynamic', function(req, res){ | ||
var lis = ''; | ||
for(var i=0; i<5; i++){ | ||
lis= lis + '<li>coding</li>' ; | ||
} | ||
var time = Date(); | ||
var output = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
</head> | ||
<body> | ||
Hello, Dynamic !! | ||
<ul> | ||
${lis} | ||
</ul> | ||
${time} | ||
</body> | ||
</html>` | ||
res.send(output); | ||
}) | ||
app.get('/router', function(req, res){ | ||
res.send('Hello world ! <img src="/testimg.jpg">') | ||
}) | ||
app.get('/', function(req, res){ | ||
res.send('<h1>'+'Hello home page'+'</h1>'); | ||
}); | ||
app.get('/login',function(req, res){ | ||
res.send('Login please'); | ||
}) | ||
app.listen(3000, function(){ | ||
console.log('Connected 3000 port!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
var express = require('express'); | ||
var cookieParser = require('cookie-parser') | ||
var app = express(); | ||
app.use(cookieParser('2FDGSDAFH2232TSZCGE')); | ||
|
||
//실제로는 데이터베이스로. | ||
var products = { | ||
1 : {title:'The history of web 1'}, | ||
2 : {title:'The next web'} | ||
}; | ||
|
||
app.get('/products', function(req, res){ | ||
var output = ''; | ||
for(var name in products){ | ||
output += ` | ||
<li> | ||
<a href="/cart/${name}">${products[name].title}</a> | ||
</li>` | ||
} | ||
res.send(`<h1>Products</h1><ul>${output}</ul><a href='/cart'>Cart</a>`); | ||
}); | ||
|
||
/* | ||
cart = { | ||
1:1, | ||
2:1 | ||
} | ||
*/ | ||
|
||
app.get('/cart/:id', function(req, res){ | ||
var id = req.params.id; | ||
if(req.signedCookies.cart){ | ||
var cart = req.signedCookies.cart ; | ||
} else { | ||
var cart = {}; | ||
} | ||
if(!cart[id]){ | ||
cart[id] = 0; | ||
} | ||
cart[id] = parseInt(cart[id])+1; | ||
res.cookie('cart' , cart, {signed:true}); | ||
res.redirect('/cart'); | ||
}); | ||
|
||
app.get('/cart', function(req, res){ | ||
var cart = req.signedCookies.cart; | ||
if(!cart){ | ||
res.send('Empty!'); | ||
} else { | ||
var output = ''; | ||
for(var id in cart){ | ||
output += `<li>${products[id].title} (${cart[id]})</li>`; | ||
} | ||
} | ||
res.send(` | ||
<h1>Cart</h1> | ||
<ul>${output}</ul> | ||
<a href="/products">Products List</a> | ||
`); | ||
}) | ||
|
||
app.get('/count', function(req, res){ | ||
if(req.signedCookies.count){ | ||
var count = parseInt(req.signedCookies.count); | ||
} else { | ||
var count = 0; | ||
} | ||
count = count+1; | ||
res.cookie('count', count, {signed:true}); | ||
res.send('count : '+count); | ||
}); | ||
|
||
app.listen(3003, function(){ | ||
console.log('Connected 3003 port !!!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
var multer = require('multer'); | ||
var _storage = multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
cb(null, 'uploads/') | ||
}, | ||
filename: function (req, file, cb) { | ||
cb(null, file.originalname); | ||
} | ||
}) | ||
var upload = multer({ storage: _storage }) | ||
var fs = require('fs'); | ||
var app = express(); | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
app.locals.pretty = true; | ||
app.use('/user', express.static('uploads')); | ||
app.set('views', './views_file'); | ||
app.set('view engine', 'jade'); | ||
app.get('/upload', function(req, res){ | ||
res.render('upload'); | ||
}) | ||
app.post('/upload', upload.single('userfile'), function(req, res){ | ||
console.log(req.file); | ||
res.send('uploaded : '+req.file.filename); | ||
}) | ||
app.get('/topic/new', function(req, res){ | ||
fs.readdir('data', function(err, files){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
res.render('new' , {topics:files}); | ||
}); | ||
}); | ||
app.get(['/topic', '/topic/:id'], function(req, res){ | ||
fs.readdir('data', function(err, files){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
var id = req.params.id; | ||
if(id){ | ||
// id 값이 있을 때 | ||
fs.readFile('data/'+id, 'utf8', function(err, data){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
res.render('view', {topics:files, title:id, description:data}); | ||
}) | ||
} else { | ||
// id 값이 없을 때 | ||
res.render('view', {topics:files, title:'welcome', description:'Hello'}); | ||
} | ||
}) | ||
}); | ||
/* | ||
app.get('/topic/:id', function(req, res){ | ||
var id = req.params.id; | ||
fs.readdir('data', function(err, files){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
fs.readFile('data/'+id, 'utf8', function(err, data){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
res.render('view', {topics:files, title:id, description:data}); | ||
}) | ||
}); | ||
}) | ||
*/ | ||
app.post('/topic', function(req, res){ | ||
var title = req.body.title; | ||
var description = req.body.description | ||
fs.writeFile('data/'+title, description, function(err){ | ||
if(err){ | ||
console.log(err); | ||
res.status(500).send('Internal Server Error'); | ||
} | ||
res.redirect('/topic/'+title); | ||
}) | ||
}) | ||
app.listen(3000, function(){ | ||
console.log('Connected, 3000 port!'); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
var express = require('express'); | ||
var session = require('express-session'); | ||
var FileStore = require('session-file-store')(session); | ||
var bodyParser = require('body-parser'); | ||
var bkfd2Password = require("pbkdf2-password"); | ||
var hasher = bkfd2Password(); | ||
|
||
var app = express(); | ||
app.use(bodyParser.urlencoded({ extended: false})); | ||
|
||
app.use(session({ | ||
secret: '1sad%@f1s5d@%1fs3d13s%d1', | ||
resave: false, | ||
saveUninitialized: true, | ||
store:new FileStore() | ||
})); | ||
|
||
|
||
app.get('/welcome' , function(req, res){ | ||
if(req.session.displayName){ | ||
res.send(` | ||
<h1>Hello, ${req.session.displayName}</h1> | ||
<a href="/auth/logout">logout</a> | ||
`); | ||
} else { | ||
res.send(` | ||
<h1>Welcome</h1> | ||
<ul> | ||
<li><a href="/auth/login">Login</a></li> | ||
<li><a href="/auth/register">Register</a></li> | ||
</ul> | ||
`) | ||
} | ||
}) | ||
|
||
app.get('/auth/register' , function(req, res){ | ||
var output = ` | ||
<h1>Register</h1> | ||
<form action="/auth/register" method="post"> | ||
<p> | ||
<input type="text" name="username" placeholder="username"> | ||
</p> | ||
<p> | ||
<input type="password" name="password" placeholder="password"> | ||
</p> | ||
<p> | ||
<input type="text" name="displayName" placeholder="displayName"> | ||
</p> | ||
<p> | ||
<input type="submit"> | ||
</p> | ||
</form> | ||
`; | ||
res.send(output); | ||
}) | ||
|
||
var users = [ | ||
{ | ||
username:'egoing', | ||
password:'dYfmFeOv6xKAHnc0sjrNWVXtdyJ2TbVi5Iw1lnVkQxxiBpE0tPWxcCYNOYEGk/HSCKN3xhBXiNqR4NlxMnOFUv/MXvqBU5opOjKxWohug5bYoVE0QYsw6YhdDCap30eDTQVqfabLm8oPyM1RXO1tTZJdBTeQjTPJBoYPZ4PJ+OI=', | ||
salt:'k/X42MvOk5ghPOCoZFAmdxRP+Zo+nzFdDedu9dNBoeiPkfxVXMwnwzrV11w55XXYqKtTVGgbvy/ytenBIm8y9w==', | ||
displayName:'Egoing' | ||
} | ||
]; | ||
app.post('/auth/register', function(req, res){ | ||
hasher({password:req.body.password}, function(err, pass, salt, hash){ | ||
var user = { | ||
username:req.body.username, | ||
password:hash, | ||
salt:salt, | ||
displayName:req.body.displayName | ||
}; | ||
users.push(user); | ||
res.session.displayName = req.body.displayName; | ||
req.session.save(function(){ | ||
res.redirect('/welcome'); | ||
}) | ||
}) | ||
}); | ||
|
||
app.post('/auth/login', function(req, res){ | ||
var uname = req.body.username; | ||
var pwd = req.body.password; | ||
for(var i=0; i<users.length; i++){ | ||
var user = users[i]; | ||
if(uname === user.username) { | ||
return hasher({password:pwd, salt:user.salt}, function(err, pass, salt, hash){ | ||
if(hash === user.password){ | ||
req.session.displayName = user.displayName; | ||
req.session.save(function(){ | ||
res.redirect('/welcome'); | ||
}) | ||
} else { | ||
res.send('Who are you? <a href="/auth/login">login</a>'); | ||
} | ||
}); | ||
} | ||
// if(uname === user.username && sha256(pwd+user.salt) === user.password){ | ||
// req.session.displayName = user.displayName; | ||
// return req.session.save(function(){ | ||
// res.redirect('/welcome'); | ||
// }); | ||
// } | ||
} | ||
res.send('Who are you? <a href="/auth/login">login</a>'); | ||
}); | ||
|
||
app.get('/auth/logout', function(req, res){ | ||
delete req.session.displayName; | ||
res.redirect('/welcome'); | ||
}); | ||
|
||
app.get('/auth/login', function(req, res){ | ||
var output = ` | ||
<h1>Login</h1> | ||
<form action="/auth/login" method="post"> | ||
<p> | ||
<input type="text" name="username" placeholder="username"> | ||
</p> | ||
<p> | ||
<input type="password" name="password" placeholder="password"> | ||
</p> | ||
<p> | ||
<input type="submit"> | ||
</p> | ||
</form> | ||
`; | ||
res.send(output); | ||
}); | ||
|
||
app.get('/count', function(req, res){ | ||
if(req.session.count){ | ||
req.session.count++; | ||
} else { | ||
req.session.count = 1; | ||
} | ||
res.send('count :'+req.session.count); | ||
}) | ||
|
||
app.listen(3003, function(){ | ||
console.log('Connected 3003 port !!!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var app = require('./config/mysql/express')(); | ||
|
||
var passport = require('./config/mysql/passport')(app); | ||
var auth = require('./routes/mysql/auth')(passport); | ||
app.use('/auth/', auth); | ||
|
||
var topic = require('./routes/mysql/topic')(); | ||
app.use('/topic', topic); | ||
|
||
app.listen(3003, function(){ | ||
console.log('Connected, 3000 port!'); | ||
}) |
Oops, something went wrong.