Showing
11 changed files
with
31 additions
and
154 deletions
| ... | @@ -3,14 +3,14 @@ | ... | @@ -3,14 +3,14 @@ |
| 3 | var express = require('express'), | 3 | var express = require('express'), |
| 4 | bodyParser = require('body-parser'), | 4 | bodyParser = require('body-parser'), |
| 5 | Realm = require('realm'); | 5 | Realm = require('realm'); |
| 6 | - | 6 | +var uname; |
| 7 | var app = express(); | 7 | var app = express(); |
| 8 | 8 | ||
| 9 | let PostSchema = { | 9 | let PostSchema = { |
| 10 | name: 'Post', | 10 | name: 'Post', |
| 11 | properties: { | 11 | properties: { |
| 12 | + user: 'string', | ||
| 12 | timestamp: 'date', | 13 | timestamp: 'date', |
| 13 | - title: 'string', | ||
| 14 | content: 'string' | 14 | content: 'string' |
| 15 | } | 15 | } |
| 16 | }; | 16 | }; |
| ... | @@ -24,7 +24,7 @@ let UserSchema = { | ... | @@ -24,7 +24,7 @@ let UserSchema = { |
| 24 | } | 24 | } |
| 25 | }; | 25 | }; |
| 26 | var blogRealm = new Realm({ | 26 | var blogRealm = new Realm({ |
| 27 | - path: 'blog.realm', | 27 | + path: 'blog3.realm', |
| 28 | schema: [PostSchema] | 28 | schema: [PostSchema] |
| 29 | }); | 29 | }); |
| 30 | var userRealm = new Realm({ | 30 | var userRealm = new Realm({ |
| ... | @@ -34,6 +34,7 @@ var userRealm = new Realm({ | ... | @@ -34,6 +34,7 @@ var userRealm = new Realm({ |
| 34 | 34 | ||
| 35 | app.use(bodyParser.urlencoded({extended: true})); | 35 | app.use(bodyParser.urlencoded({extended: true})); |
| 36 | 36 | ||
| 37 | +let posts = blogRealm.objects('Post').sorted('timestamp', true); | ||
| 37 | app.get('/', function(req, res) { | 38 | app.get('/', function(req, res) { |
| 38 | // res.sendFile(__dirname + "/index.html"); | 39 | // res.sendFile(__dirname + "/index.html"); |
| 39 | // let posts = blogRealm.objects('Post').sorted('timestamp', true); | 40 | // let posts = blogRealm.objects('Post').sorted('timestamp', true); |
| ... | @@ -60,7 +61,8 @@ app.post('/login', function(req, res) { | ... | @@ -60,7 +61,8 @@ app.post('/login', function(req, res) { |
| 60 | if(id==users[i].id && pw ==users[i].pw) | 61 | if(id==users[i].id && pw ==users[i].pw) |
| 61 | { | 62 | { |
| 62 | let name = users[i].name; | 63 | let name = users[i].name; |
| 63 | - res.render('main2.ejs', {name: name}); | 64 | + uname = users[i].name; |
| 65 | + res.render('main2.ejs', {name: name, posts: posts}); | ||
| 64 | 66 | ||
| 65 | chk = true; | 67 | chk = true; |
| 66 | } | 68 | } |
| ... | @@ -91,13 +93,14 @@ res.sendFile(__dirname+"/pages/info.html"); | ... | @@ -91,13 +93,14 @@ res.sendFile(__dirname+"/pages/info.html"); |
| 91 | }); | 93 | }); |
| 92 | 94 | ||
| 93 | app.post('/write', function(req, res) { | 95 | app.post('/write', function(req, res) { |
| 94 | - let title = req.body['title'], | 96 | + let content = req.body['content'], |
| 95 | - content = req.body['content'], | ||
| 96 | timestamp = new Date(); | 97 | timestamp = new Date(); |
| 98 | + // posts = blogRealm.objects('Post').sorted('timestamp', true); | ||
| 97 | blogRealm.write(() => { | 99 | blogRealm.write(() => { |
| 98 | - blogRealm.create('Post', {title: title, content: content, timestamp: timestamp}); | 100 | + blogRealm.create('Post', {user: uname, content: content, timestamp: timestamp}); |
| 99 | }); | 101 | }); |
| 100 | - res.sendFile(__dirname + "/pages/main.html"); | 102 | + |
| 103 | + res.render('main2.ejs', {name: uname, posts: posts}); | ||
| 101 | }); | 104 | }); |
| 102 | app.post('/register', function(req, res) { | 105 | app.post('/register', function(req, res) { |
| 103 | let id = req.body['id'], | 106 | let id = req.body['id'], |
| ... | @@ -106,7 +109,7 @@ app.post('/register', function(req, res) { | ... | @@ -106,7 +109,7 @@ app.post('/register', function(req, res) { |
| 106 | userRealm.write(() => { | 109 | userRealm.write(() => { |
| 107 | userRealm.create('User', {id: id, pw: pw, name: name}); | 110 | userRealm.create('User', {id: id, pw: pw, name: name}); |
| 108 | }); | 111 | }); |
| 109 | - res.sendFile(__dirname + "/write-complete.html"); | 112 | + res.sendFile(__dirname + "/pages/main.html"); |
| 110 | }); | 113 | }); |
| 111 | app.listen(3000, function() { | 114 | app.listen(3000, function() { |
| 112 | console.log("Go!"); | 115 | console.log("Go!"); | ... | ... |
No preview for this file type
blog2.realm
0 → 100644
No preview for this file type
blog2.realm.lock
0 → 100644
No preview for this file type
blog3.realm
0 → 100644
No preview for this file type
blog3.realm.lock
0 → 100644
No preview for this file type
main2.ejs
deleted
100644 → 0
| 1 | -<!DOCTYPE html> | ||
| 2 | -<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> | ||
| 3 | - | ||
| 4 | -<!-- 부가적인 테마 --> | ||
| 5 | -<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css"> | ||
| 6 | - | ||
| 7 | -<!-- 합쳐지고 최소화된 최신 자바스크립트 --> | ||
| 8 | -<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | ||
| 9 | -<html lang="en"> | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | -<head> | ||
| 15 | - <meta charset="utf-8"> | ||
| 16 | - <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| 17 | - <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| 18 | - <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | ||
| 19 | - <meta name="description" content=""> | ||
| 20 | - <meta name="author" content=""> | ||
| 21 | - <link rel="icon" href="../../favicon.ico"> | ||
| 22 | - | ||
| 23 | - <title>Coin Community</title> | ||
| 24 | - | ||
| 25 | - <!-- Bootstrap core CSS --> | ||
| 26 | - <link href="../../dist/css/bootstrap.min.css" rel="stylesheet"> | ||
| 27 | - | ||
| 28 | - <!-- Custom styles for this template --> | ||
| 29 | - <link href="navbar-fixed-top.css" rel="stylesheet"> | ||
| 30 | - | ||
| 31 | - <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> | ||
| 32 | - <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> | ||
| 33 | - <script src="../../assets/js/ie-emulation-modes-warning.js"></script> | ||
| 34 | - | ||
| 35 | - <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | ||
| 36 | - <!--[if lt IE 9]> | ||
| 37 | - <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | ||
| 38 | - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | ||
| 39 | - <![endif]--> | ||
| 40 | -</head> | ||
| 41 | -<style> | ||
| 42 | -<body> | ||
| 43 | - background-image: url("background.jpg"); | ||
| 44 | - background-color: #cccccc; | ||
| 45 | - </style> | ||
| 46 | - <style type = "text/css"> | ||
| 47 | - .jumbotron{ | ||
| 48 | - background-image: url('images/background.jpg'); | ||
| 49 | - background-size: cover; | ||
| 50 | - text-shadow: black 0.1em 0.1em 0.1em; | ||
| 51 | - color: whites; | ||
| 52 | - } | ||
| 53 | - </style> | ||
| 54 | - <!-- Fixed navbar --> | ||
| 55 | - <nav class="navbar navbar-default"> | ||
| 56 | - <div class="container-fluid"> | ||
| 57 | - <!-- Brand and toggle get grouped for better mobile display --> | ||
| 58 | - <div class="navbar-header"> | ||
| 59 | - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> | ||
| 60 | - <span class="sr-only">Toggle navigation</span> | ||
| 61 | - <span class="icon-bar"></span> | ||
| 62 | - <span class="icon-bar"></span> | ||
| 63 | - <span class="icon-bar"></span> | ||
| 64 | - </button> | ||
| 65 | - <a class="navbar-brand" href="#">Coin Community</a> | ||
| 66 | - </div> | ||
| 67 | - | ||
| 68 | - <!-- Collect the nav links, forms, and other content for toggling --> | ||
| 69 | - <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | ||
| 70 | - <ul class="nav navbar-nav"> | ||
| 71 | - <!--<li class="active"><a href="#">View Chart <span class="sr-only">(current)</span></a></li> | ||
| 72 | - <li><a href="#">Freeboard</a></li>--> | ||
| 73 | - | ||
| 74 | - </ul> | ||
| 75 | - | ||
| 76 | - <ul class="nav navbar-nav navbar-right"> | ||
| 77 | - <li><a href="/logout">Logout</a></li> | ||
| 78 | - <li><a href="/info">About me</a></li> | ||
| 79 | - | ||
| 80 | - </ul> | ||
| 81 | - </div> | ||
| 82 | - <!-- /.navbar-collapse --> | ||
| 83 | - </div> | ||
| 84 | - <!-- /.container-fluid --> | ||
| 85 | - </nav> | ||
| 86 | - | ||
| 87 | - <div class="container"> | ||
| 88 | - | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - <div class="col-lg-12"> | ||
| 92 | - <div class="panel panel-default"> | ||
| 93 | - <div class="panel-heading"> | ||
| 94 | - Line Chart Example | ||
| 95 | - | ||
| 96 | - <script src="https://mining-profit.com/js/mp-btc-chart.js"></script> | ||
| 97 | - <script type="text/javascript"> | ||
| 98 | - MiningProfitBTCChart.setChartWidth(1070); | ||
| 99 | - MiningProfitBTCChart.setChartHeight(500); | ||
| 100 | - MiningProfitBTCChart.isDisplayControlRanges(true); | ||
| 101 | - MiningProfitBTCChart.isDisplayControlInterval(false); | ||
| 102 | - MiningProfitBTCChart.setInitialRange('20h'); | ||
| 103 | - MiningProfitBTCChart.setChartRanges(['6h', '10h', '20h', '2d', '1w', '2w', '1m']); | ||
| 104 | - MiningProfitBTCChart.setChartExchanges([{mpvaluation: '#428bca'}, {bitstamp: '#B4CD3E'}, {coinbase: '#D54E88'}, {btce: '#F0522B'}]); | ||
| 105 | - MiningProfitBTCChart.setInitialExchange('coinbase'); | ||
| 106 | - MiningProfitBTCChart.setMajorColor('rgb(35, 119, 58)'); | ||
| 107 | - MiningProfitBTCChart.draw(); | ||
| 108 | - </script> | ||
| 109 | - </div> | ||
| 110 | - <!-- /.panel-heading --> | ||
| 111 | - <div class="panel-body"> | ||
| 112 | - <div class="flot-chart"> | ||
| 113 | - <div class="flot-chart-content" id="flot-line-chart"></div> | ||
| 114 | - </div> | ||
| 115 | - </div> | ||
| 116 | - <!-- /.panel-body --> | ||
| 117 | - </div> | ||
| 118 | - <!-- /.panel --> | ||
| 119 | - </div> | ||
| 120 | - | ||
| 121 | - </div> | ||
| 122 | - <!-- /container --> | ||
| 123 | - | ||
| 124 | - <!-- Bootstrap core JavaScript | ||
| 125 | - ================================================== --> | ||
| 126 | - <!-- Placed at the end of the document so the pages load faster --> | ||
| 127 | - <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> | ||
| 128 | - <script src="../../dist/js/bootstrap.min.js"></script> | ||
| 129 | - <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> | ||
| 130 | - <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> | ||
| 131 | - <script scr="https://code.jquery.com/jquery-3.1.1.min.js"></script> | ||
| 132 | - <script src="js/bootstrap.js"></script> | ||
| 133 | -</body> | ||
| 134 | - | ||
| 135 | -</html> |
| ... | @@ -53,7 +53,7 @@ | ... | @@ -53,7 +53,7 @@ |
| 53 | <form role="form"> | 53 | <form role="form"> |
| 54 | <fieldset> | 54 | <fieldset> |
| 55 | 이름 : 손장민<br> 나이 : 24<br> 학교 : KHU.univ<br> 과 : 컴퓨터 공학과<br> 이메일 : djkaiden@naver.com<br> | 55 | 이름 : 손장민<br> 나이 : 24<br> 학교 : KHU.univ<br> 과 : 컴퓨터 공학과<br> 이메일 : djkaiden@naver.com<br> |
| 56 | - <a href="/" class="btn btn-lg btn-success btn-block">Close</a> | 56 | + <a href="/main" class="btn btn-lg btn-success btn-block">Close</a> |
| 57 | </fieldset> | 57 | </fieldset> |
| 58 | </form> | 58 | </form> |
| 59 | </div> | 59 | </div> | ... | ... |
| ... | @@ -53,13 +53,13 @@ | ... | @@ -53,13 +53,13 @@ |
| 53 | <form action="/register" method="POST"> | 53 | <form action="/register" method="POST"> |
| 54 | <fieldset> | 54 | <fieldset> |
| 55 | <div class="form-group"> | 55 | <div class="form-group"> |
| 56 | - <input class="form-control" placeholder="E-mail" name="id" type="name" autofocus> | 56 | + <input class="form-control" placeholder="ID" name="id" type="name" autofocus> |
| 57 | </div> | 57 | </div> |
| 58 | <div class="form-group"> | 58 | <div class="form-group"> |
| 59 | <input class="form-control" placeholder="Password" name="pw" type="password" value=""> | 59 | <input class="form-control" placeholder="Password" name="pw" type="password" value=""> |
| 60 | </div> | 60 | </div> |
| 61 | <div class="form-group"> | 61 | <div class="form-group"> |
| 62 | - <input class="form-control" placeholder="Confirm Password" name="password2" type="password2" value=""> | 62 | + <input class="form-control" placeholder="Confirm Password" name="password" type="password" value=""> |
| 63 | </div> | 63 | </div> |
| 64 | <div class="form-group"> | 64 | <div class="form-group"> |
| 65 | <input class="form-control" placeholder="Name" name="name" type="name" value=""> | 65 | <input class="form-control" placeholder="Name" name="name" type="name" value=""> | ... | ... |
No preview for this file type
| ... | @@ -125,23 +125,32 @@ | ... | @@ -125,23 +125,32 @@ |
| 125 | </div> | 125 | </div> |
| 126 | <!-- /.panel --> | 126 | <!-- /.panel --> |
| 127 | </div> | 127 | </div> |
| 128 | - | 128 | + <div class="container"> |
| 129 | + <form action="/write" method="POST"> | ||
| 130 | + <fieldset> | ||
| 131 | + <div class="form-group"> | ||
| 132 | + <input class="form-control" placeholder="내용" name="content" type="name" autofocus> | ||
| 133 | + </div> | ||
| 134 | + <button type="submit" float:"right">Submit</button> | ||
| 135 | + </fieldset> | ||
| 136 | + </form> | ||
| 137 | +</div> | ||
| 129 | <table class="table"> | 138 | <table class="table"> |
| 130 | <thread> | 139 | <thread> |
| 131 | <tr> | 140 | <tr> |
| 132 | - <th>제목</th> | ||
| 133 | - <th>내용</th> | ||
| 134 | <th>작성자</th> | 141 | <th>작성자</th> |
| 142 | + <th>내용</th> | ||
| 135 | <th>날짜</th> | 143 | <th>날짜</th> |
| 136 | </tr> | 144 | </tr> |
| 137 | </thead> | 145 | </thead> |
| 138 | <tbody> | 146 | <tbody> |
| 147 | + <% for(var i=0; i<posts.length; i++) {%> | ||
| 139 | <tr> | 148 | <tr> |
| 140 | - <td>아인스</td> | 149 | + <td><%= posts[i].user%></td> |
| 141 | - <td>오르나요</td> | 150 | + <td><%= posts[i].content%></td> |
| 142 | - <td>마나요</td> | 151 | + <td><%= posts[i].timestamp%></td> |
| 143 | - <td>1234</td> | ||
| 144 | </tr> | 152 | </tr> |
| 153 | + <% } %> | ||
| 145 | </tbody> | 154 | </tbody> |
| 146 | </table> | 155 | </table> |
| 147 | 156 | ... | ... |
-
Please register or login to post a comment