김용재

회원가입, 로그인 구현 완료 사용자 정보 db에 저장

<h1 style="width: 100%; text-align: center; font-size: 40px;">오늘은 얼마나 먹었어요?</h1>
<form action="/logout" method="get">
<input id ="logout" type="submit" value="Logout" class="btn btn-default" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;">
</form>
<br><br><br>
<div id = "input-ing" style="width:100%; text-align: center;">
<form action="/starting" method="post">
<div class="form-inline">
<p style="text-decoration-line: underline; font-weight:bold;">오늘 먹은 것들을 적어주세요!</p>
<input type="text" style="width:30%; height:130px;" placeholder="ex) coffee and croissant">
<br><br><br><br>
<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;">
</div>
</form>
</div>
\ No newline at end of file
......@@ -5,15 +5,15 @@
<div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch">
<div class="form-inline">
<form action="/login" method="post">
<form action="/login_process" method="post">
<label>ID</label>
<input type="text" name="name" class="form-control" placeholder="홍길동" style="width:200px;">
<input type="text" name="ID" class="form-control" placeholder="홍길동" style="width:200px;">
&nbsp &nbsp&nbsp&nbsp
<label>Password</label>
<input type="password" name="birth" class="form-control" placeholder="*******" style="width:200px;">
<input type="password" name="pwd" class="form-control" placeholder="*******" style="width:200px;">
<br><br><br>
<input type="submit" value="Login" class="btn btn-default" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;">
<input type="submit" value="login" style=" width:100px;font-weight: bold; font-size: 18px; background-color: white;">
</form>
<br><br>
<form action="/signup" method="get">
......
......@@ -4,7 +4,7 @@
<br><br><br>
<div id = "signup-ing" style="width:100%; text-align: center;">
<form action="/starting" method="post">
<form action="/signup_process" method="post">
<div class="form-inline">
<div class="input-area">
<span class="input-label">
......@@ -17,10 +17,10 @@
<div class="input-area">
<span class="input-label">
<label name="Password">Password</label>
<label name="pwd">Password</label>
</span>
<span class="input-box">
<input type="text" name="Password" >
<input type="text" name="pwd" >
</span>
</div>
......@@ -35,12 +35,13 @@
<div class="input-area">
<span class="input-label">
<label name="male/female">성별</label>
<label name="gender">성별</label>
</span>
<select id="male/female" style="width: 200px; ">
<option>성별 선택</option>
<option>남자</option>
<option>여자</option>
<select name="gender" style="width: 200px; ">
<optgroup label="성별 선택">
<option value="male">남자</option>
<option value="female">여자</option>
</optgroup>
</select>
</div>
......
......@@ -41,7 +41,7 @@
<div id = "login-ing" style="width:100%; text-align: center; margin-top: 5ch">
<div class="form-inline">
<form action="/login" method="post">
<form action="/login_process" method="post">
<label>ID</label>
<input type="text" name="name" class="form-control" placeholder="홍길동" style="width:200px;">
&nbsp &nbsp&nbsp&nbsp
......
{
"users": [
{
"ID": "yooh3574",
"password": "123",
"age": "123",
"gender": "male",
"height": "123",
"weight": "123"
}
]
}
\ No newline at end of file
module.exports = {
HTML:function(title,ch,line, body){
HTML:function(title,ch,line, body,logout){
return `
<!DOCTYPE html>
<html lang="en">
......@@ -31,6 +31,7 @@ module.exports = {
text-align: center;
color: white;
}
${logout}
</style>
${line}
......
var express = require('express')
var app = express()
var fs = require('fs');
// var path = require('path');
// var qs = require('querystring');
// var sanitizeHtml = require('sanitize-html');
var bodyParser = require('body-parser');
var helmet = require('helmet')
app.use(helmet());
var session = require('express-session');
var FileStore= require('session-file-store')(session);
var template = require('./lib/template.js');
var url='https://api.edamam.com/api/food-database/parser';
var low =require('lowdb')
var FileSync = require('lowdb/adapters/FileSync');
var adapter = new FileSync('db.json');
var db=low(adapter);
db.defaults({users:[]}).write();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(session({
secret: 'asadlfkj!@#!@#dfgasdg',
resave: false,
saveUninitialized: true,
store: new FileStore()
}))
app.use(express.static('data'));
app.get('/', function(request, response) {
fs.readFile('./contents/main', function(error, body){
fs.readFile('./contents/main.html', function(error, body){
var title = 'Health Care';
var ch='15ch'
var html = template.HTML(title,ch,'',body);
var html = template.HTML(title,ch,'',body,'');
response.send(html);
});
});
app.post('/login_process', function(request, response) {
var post = request.body;
var ID=post.ID;
var password=post.pwd;
var user = db.get('users').find({ID:ID,password:password}).value();
if(user){
request.session.is_logined = true;
request.session.save(function(){
response.redirect('/InputPage')
});
}
});
app.get('/signup', function(request, response) {
fs.readFile('./contents/signup', function(error, body){
fs.readFile('./contents/signup.html', function(error, body){
var title = 'Sign Up Page';
var ch='5ch'
var html = template.HTML(title,ch,`<link rel="stylesheet" type="text/css" href="./a.css" />`,body);
var html = template.HTML(title,ch,`<link rel="stylesheet" type="text/css" href="./a.css" />`,body,'');
response.send(html);
});
});
app.post('/signup_process', function(request, response) {
var post = request.body;
var ID=post.ID;
var pwd=post.pwd;
var age=post.age;
var gender=post.gender;
var height=post.height;
var weight=post.weight;
db.get('users').push({
ID:ID,
password:pwd,
age:age,
gender:gender,
height:height,
weight:weight
}).write();
request.session.is_logined = true;
request.session.ID = ID;
request.session.save(function(){
response.redirect('/InputPage')
});
});
app.get('/InputPage', function(request, response){
fs.readFile('./contents/Input.html', function(error, body){
var title = 'Input Page';
var ch='5ch'
var html = template.HTML(title,ch,``,body,`#logout{
position:absolute;
right: 20ch;
}`);
response.send(html);
});
});
app.get('/logout', function(request, response) {
request.session.destroy(function(err){
response.redirect('/');
})
});
app.listen(3000, function() {
console.log('Example app listening on port 3000!')
});
\ No newline at end of file
});
\ No newline at end of file
......
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1559789773873}
\ No newline at end of file