Showing
8 changed files
with
147 additions
and
21 deletions
contents/Input.html
0 → 100644
1 | +<h1 style="width: 100%; text-align: center; font-size: 40px;">오늘은 얼마나 먹었어요?</h1> | ||
2 | +<form action="/logout" method="get"> | ||
3 | + <input id ="logout" type="submit" value="Logout" class="btn btn-default" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;"> | ||
4 | + </form> | ||
5 | + <br><br><br> | ||
6 | + | ||
7 | + <div id = "input-ing" style="width:100%; text-align: center;"> | ||
8 | + <form action="/starting" method="post"> | ||
9 | + <div class="form-inline"> | ||
10 | + | ||
11 | + <p style="text-decoration-line: underline; font-weight:bold;">오늘 먹은 것들을 적어주세요!</p> | ||
12 | + | ||
13 | + <input type="text" style="width:30%; height:130px;" placeholder="ex) coffee and croissant"> | ||
14 | + <br><br><br><br> | ||
15 | + | ||
16 | + <input id="go" type="button" value="Go!" style=" width:100px; height:80px; font-weight: bold; color:white; font-size: 25px; background-color: rgb(104, 211, 104); border-radius: 2em;"> | ||
17 | + | ||
18 | + | ||
19 | + </div> | ||
20 | + </form> | ||
21 | + </div> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -5,15 +5,15 @@ | ... | @@ -5,15 +5,15 @@ |
5 | 5 | ||
6 | <div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch"> | 6 | <div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch"> |
7 | <div class="form-inline"> | 7 | <div class="form-inline"> |
8 | - <form action="/login" method="post"> | 8 | + <form action="/login_process" method="post"> |
9 | <label>ID</label> | 9 | <label>ID</label> |
10 | - <input type="text" name="name" class="form-control" placeholder="홍길동" style="width:200px;"> | 10 | + <input type="text" name="ID" class="form-control" placeholder="홍길동" style="width:200px;"> |
11 |       | 11 |       |
12 | 12 | ||
13 | <label>Password</label> | 13 | <label>Password</label> |
14 | - <input type="password" name="birth" class="form-control" placeholder="*******" style="width:200px;"> | 14 | + <input type="password" name="pwd" class="form-control" placeholder="*******" style="width:200px;"> |
15 | <br><br><br> | 15 | <br><br><br> |
16 | - <input type="submit" value="Login" class="btn btn-default" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;"> | 16 | + <input type="submit" value="login" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;"> |
17 | </form> | 17 | </form> |
18 | <br><br> | 18 | <br><br> |
19 | <form action="/signup" method="get"> | 19 | <form action="/signup" method="get"> | ... | ... |
... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
4 | <br><br><br> | 4 | <br><br><br> |
5 | 5 | ||
6 | <div id = "signup-ing" style="width:100%; text-align: center;"> | 6 | <div id = "signup-ing" style="width:100%; text-align: center;"> |
7 | - <form action="/starting" method="post"> | 7 | + <form action="/signup_process" method="post"> |
8 | <div class="form-inline"> | 8 | <div class="form-inline"> |
9 | <div class="input-area"> | 9 | <div class="input-area"> |
10 | <span class="input-label"> | 10 | <span class="input-label"> |
... | @@ -17,10 +17,10 @@ | ... | @@ -17,10 +17,10 @@ |
17 | 17 | ||
18 | <div class="input-area"> | 18 | <div class="input-area"> |
19 | <span class="input-label"> | 19 | <span class="input-label"> |
20 | - <label name="Password">Password</label> | 20 | + <label name="pwd">Password</label> |
21 | </span> | 21 | </span> |
22 | <span class="input-box"> | 22 | <span class="input-box"> |
23 | - <input type="text" name="Password" > | 23 | + <input type="text" name="pwd" > |
24 | </span> | 24 | </span> |
25 | </div> | 25 | </div> |
26 | 26 | ||
... | @@ -35,12 +35,13 @@ | ... | @@ -35,12 +35,13 @@ |
35 | 35 | ||
36 | <div class="input-area"> | 36 | <div class="input-area"> |
37 | <span class="input-label"> | 37 | <span class="input-label"> |
38 | - <label name="male/female">성별</label> | 38 | + <label name="gender">성별</label> |
39 | </span> | 39 | </span> |
40 | - <select id="male/female" style="width: 200px; "> | 40 | + <select name="gender" style="width: 200px; "> |
41 | - <option>성별 선택</option> | 41 | + <optgroup label="성별 선택"> |
42 | - <option>남자</option> | 42 | + <option value="male">남자</option> |
43 | - <option>여자</option> | 43 | + <option value="female">여자</option> |
44 | + </optgroup> | ||
44 | 45 | ||
45 | </select> | 46 | </select> |
46 | </div> | 47 | </div> | ... | ... |
... | @@ -41,7 +41,7 @@ | ... | @@ -41,7 +41,7 @@ |
41 | 41 | ||
42 | <div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch"> | 42 | <div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch"> |
43 | <div class="form-inline"> | 43 | <div class="form-inline"> |
44 | - <form action="/login" method="post"> | 44 | + <form action="/login_process" method="post"> |
45 | <label>ID</label> | 45 | <label>ID</label> |
46 | <input type="text" name="name" class="form-control" placeholder="홍길동" style="width:200px;"> | 46 | <input type="text" name="name" class="form-control" placeholder="홍길동" style="width:200px;"> |
47 |       | 47 |       | ... | ... |
db.json
0 → 100644
1 | module.exports = { | 1 | module.exports = { |
2 | - HTML:function(title,ch,line, body){ | 2 | + HTML:function(title,ch,line, body,logout){ |
3 | return ` | 3 | return ` |
4 | <!DOCTYPE html> | 4 | <!DOCTYPE html> |
5 | <html lang="en"> | 5 | <html lang="en"> |
... | @@ -31,6 +31,7 @@ module.exports = { | ... | @@ -31,6 +31,7 @@ module.exports = { |
31 | text-align: center; | 31 | text-align: center; |
32 | color: white; | 32 | color: white; |
33 | } | 33 | } |
34 | + ${logout} | ||
34 | 35 | ||
35 | </style> | 36 | </style> |
36 | ${line} | 37 | ${line} | ... | ... |
1 | var express = require('express') | 1 | var express = require('express') |
2 | var app = express() | 2 | var app = express() |
3 | var fs = require('fs'); | 3 | var fs = require('fs'); |
4 | -// var path = require('path'); | 4 | +var bodyParser = require('body-parser'); |
5 | -// var qs = require('querystring'); | 5 | +var helmet = require('helmet') |
6 | -// var sanitizeHtml = require('sanitize-html'); | 6 | +app.use(helmet()); |
7 | +var session = require('express-session'); | ||
8 | +var FileStore= require('session-file-store')(session); | ||
7 | var template = require('./lib/template.js'); | 9 | var template = require('./lib/template.js'); |
10 | +var url='https://api.edamam.com/api/food-database/parser'; | ||
11 | + | ||
12 | +var low =require('lowdb') | ||
13 | +var FileSync = require('lowdb/adapters/FileSync'); | ||
14 | +var adapter = new FileSync('db.json'); | ||
15 | +var db=low(adapter); | ||
16 | +db.defaults({users:[]}).write(); | ||
17 | + | ||
18 | + | ||
19 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
20 | +app.use(bodyParser.json()); | ||
21 | +app.use(session({ | ||
22 | + secret: 'asadlfkj!@#!@#dfgasdg', | ||
23 | + resave: false, | ||
24 | + saveUninitialized: true, | ||
25 | + store: new FileStore() | ||
26 | +})) | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
8 | 31 | ||
9 | app.use(express.static('data')); | 32 | app.use(express.static('data')); |
10 | app.get('/', function(request, response) { | 33 | app.get('/', function(request, response) { |
11 | - fs.readFile('./contents/main', function(error, body){ | 34 | + |
35 | + fs.readFile('./contents/main.html', function(error, body){ | ||
12 | var title = 'Health Care'; | 36 | var title = 'Health Care'; |
13 | var ch='15ch' | 37 | var ch='15ch' |
14 | - var html = template.HTML(title,ch,'',body); | 38 | + var html = template.HTML(title,ch,'',body,''); |
15 | response.send(html); | 39 | response.send(html); |
16 | }); | 40 | }); |
17 | }); | 41 | }); |
18 | 42 | ||
43 | + app.post('/login_process', function(request, response) { | ||
44 | + var post = request.body; | ||
45 | + var ID=post.ID; | ||
46 | + var password=post.pwd; | ||
47 | + var user = db.get('users').find({ID:ID,password:password}).value(); | ||
48 | + if(user){ | ||
49 | + request.session.is_logined = true; | ||
50 | + | ||
51 | + request.session.save(function(){ | ||
52 | + response.redirect('/InputPage') | ||
53 | + }); | ||
54 | + } | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + }); | ||
63 | + | ||
19 | app.get('/signup', function(request, response) { | 64 | app.get('/signup', function(request, response) { |
20 | - fs.readFile('./contents/signup', function(error, body){ | 65 | + fs.readFile('./contents/signup.html', function(error, body){ |
21 | var title = 'Sign Up Page'; | 66 | var title = 'Sign Up Page'; |
22 | var ch='5ch' | 67 | var ch='5ch' |
23 | - var html = template.HTML(title,ch,`<link rel="stylesheet" type="text/css" href="./a.css" />`,body); | 68 | + var html = template.HTML(title,ch,`<link rel="stylesheet" type="text/css" href="./a.css" />`,body,''); |
69 | + response.send(html); | ||
70 | + }); | ||
71 | + }); | ||
72 | + | ||
73 | + | ||
74 | + app.post('/signup_process', function(request, response) { | ||
75 | + var post = request.body; | ||
76 | + var ID=post.ID; | ||
77 | + var pwd=post.pwd; | ||
78 | + var age=post.age; | ||
79 | + var gender=post.gender; | ||
80 | + var height=post.height; | ||
81 | + var weight=post.weight; | ||
82 | + db.get('users').push({ | ||
83 | + ID:ID, | ||
84 | + password:pwd, | ||
85 | + age:age, | ||
86 | + gender:gender, | ||
87 | + height:height, | ||
88 | + weight:weight | ||
89 | + }).write(); | ||
90 | + request.session.is_logined = true; | ||
91 | + request.session.ID = ID; | ||
92 | + request.session.save(function(){ | ||
93 | + response.redirect('/InputPage') | ||
94 | + }); | ||
95 | + | ||
96 | + }); | ||
97 | + | ||
98 | + | ||
99 | + app.get('/InputPage', function(request, response){ | ||
100 | + fs.readFile('./contents/Input.html', function(error, body){ | ||
101 | + var title = 'Input Page'; | ||
102 | + var ch='5ch' | ||
103 | + var html = template.HTML(title,ch,``,body,`#logout{ | ||
104 | + position:absolute; | ||
105 | + right: 20ch; | ||
106 | + }`); | ||
24 | response.send(html); | 107 | response.send(html); |
25 | }); | 108 | }); |
26 | }); | 109 | }); |
27 | 110 | ||
111 | + app.get('/logout', function(request, response) { | ||
112 | + request.session.destroy(function(err){ | ||
113 | + response.redirect('/'); | ||
114 | + }) | ||
115 | + }); | ||
116 | + | ||
28 | app.listen(3000, function() { | 117 | app.listen(3000, function() { |
29 | console.log('Example app listening on port 3000!') | 118 | console.log('Example app listening on port 3000!') |
30 | }); | 119 | }); |
120 | + | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1559789773873} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment