강민구

shoppingmall

<!DOCTYPE html>
<html>
<head>
<title>CuBe!</title>
<script src="./app.js"></script>
</head>
<body>
<p type="text" name="관리자메뉴" maxlength=20 size=20 > 관리자 메뉴입니다. </p>
<form action="/adminsee" method="post">
<tr>
<td><input type="submit" value="상품메뉴"></td>
</tr>
</table>
</form>
<form action="/reg" method="post">
<table>
<tr>
<td>제품 이름 : </td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>분류 : 1:음식, 2:의류, 3:전자제품, 4:가구, 5:문구 </td>
<td><input type="text" name= "category"></td>
</tr>
<tr>
<td>원가 : </td>
<td><input type="text" name="cost"></td>
</tr>
<tr>
<td>판매가 : </td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td>순이익 : </td>
<td><input type="text" name="profit"></td>
</tr>
<tr>
<td>제품설명 : </td>
<td><input type="text" name="content"></td>
</tr>
<tr>
<td>이미지 : </td>
<td><input type="text" name="image"></td>
</tr>
<tr>
<td><input type="submit" value="상품등록"></td>
</tr>
</table>
</form>
<form action="/handling" method="post">
<tr>
<td>배송할 주문 : </td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td><input type="submit" value="주문처리"></td>
</tr>
</form>
<form action="/" method="get">
<tr>
<td><input type="submit" value="처음화면으로"></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
This diff is collapsed. Click to expand it.
var mysql = require('mysql');
var db_info = {
host: 'localhost',
port: '3306',
user: 'ggalsrn',
password: 'dkswjswlcla1.',
database: 'shoppingmall'
}
module.exports = {
init: function () {
return mysql.createConnection(db_info);
},
connect: function(conn) {
conn.connect(function(err) {
if(err) console.error('mysql connection error : ' + err);
else console.log('mysql is connected successfully!');
});
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>CuBe!</title>
<script src="./app.js"></script>
</head>
<body>
<div type ="text" id="temp"></div>
<form action="/see" method="post">
<tr>
<td><input type="submit" value="상품메뉴"></td>
</tr>
</table>
</form>
<form action="/check" method="post">
<tr>
<td><input type="submit" value="주문내역확인"></td>
</tr>
<tr>
<td><input type="text" name= "usrid" placeholder="주문한사용자 id"></td>
</tr>
</table>
</form>
<form action="/" method="get">
<tr>
<td><input type="submit" value="처음화면으로"></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>CuBe!</title>
<script src="./app.js"></script>
</head>
<body>
<p type="text" name="실패" maxlength=20 size=20 > 실패 </p>
<div type ="text" id="temp"></div>
<form action="/" method="get">
<tr>
<td><input type="submit" value="처음화면으로"></td>
</tr>
</table>
</form>
<form action="/cust" method="get">
<tr>
<td><input type="submit" value="메뉴로"></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>CuBe!</title>
<!--<script src="./app.js" type="text/javascript"></script>-->
</head>
<body>
<script src="./app.js" type="text/javascript"></script>
<a href="./join.html"><input type="button" value="회원가입"></a>
<form action="/login" method="post">
<table>
<tr>
<td>ID : </td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>비번 : </td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="로그인"></td>
</tr>
</table>
</form>
<!--<button type="button" value="로그인" onclick="login()">홀롤롤로</button>
<a href="./login"><button type="button" value="로그인">로그인</button></a>
<div type ="text" id="pass">hi</div>
<script>
function login(){
document.getElementById('pass').innerHTML = "not hi"
}
</script>
-->
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>CuBe!</title>
<script src="./app.js"></script>
</head>
<body><!--
<p>
<div type="text" name="회원가입" placeholder="회원가입" maxlength=20 size=20 ></div>
</p> -->
<form action="/signup" method="post">
<table>
<tr>
<td>아이디 : </td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>비번 : </td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>이름 : </td>
<td><input type="text" name= "name"></td>
</tr>
<tr>
<td>이메일 : </td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>우편번호 : </td>
<td><input type="text" name="address_num"></td>
</tr>
<tr>
<td>주소 : </td>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td>핸드폰번호 : </td>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<td>관리자 가입코드 : </td>
<td><input type="text" name="code"></td>
</tr>
<tr>
<td><input type="submit" value="가입"></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'rQFBQXVZqeF1uFJSoPwloR8avp6Gkxssb2jNJdAFtfK'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "localhost:80"
const sslport = 23023;
const bodyParser = require('body-parser');
let session = require('express-session');
const { text } = require('body-parser');
var app = express();
app.use(bodyParser.json());
var User = new Array();
/*
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
app.use(bodyParser.urlencoded({ extended: false }));
*/
var db_config = require(__dirname+ '/cf.js');
var conn = db_config.init();
db_config.connect(conn);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
var ordernum = 0;
var sql = 'SELECT * FROM item_order';
conn.query(sql, function (err, rows, fields) {
if(err) {
console.log('query is not excuted. select fail...\n' + err)
}
else {
ordernum = rows.length;
}
});
function SL(text){
for(let j =0; j < text.length; j++){
if(text[j] = '-'){
return [text.slice(0,j),text.slice(j+1)]
}
else return;
}
}
function Message(Message){
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":Message
}
]
}
},(error, response, body) => {
console.log(body)
});
return console.log(Message);
}
function purchase(z, text){
let found = false;
if(text == '0'){
User[z].state = null;
return;
}
var tx;
if (! (tx = SL(text))) return Message("잘못된 입력입니다.");
for( let i= 0; i < items.length; i++){
if(tx[0] == items[i].id){
found= true;
var table = 'item_order';
var sql = `INSERT INTO `+ table + ` VALUES(?,?,?,?,?)`;
var params = [ordernum++, items[i].id, tx[1], 0, User[z].id];
console.log(sql);
conn.query(sql, params, function(err) {
if(err) {
console.log('query is not excuted. insert fail...\n' + err);
Message('주문에 실패했습니다')
return ;
}
else {
console.log('주문성공')
User[z].state = null;
}
});
}
}
if (!found){
Message("존재하지 않는 상품입니다");
return;
}
}
var items = '';
app.post('/hook', function(req, res) {
var eventObj = req.body.events[0];
var text = eventObj.message.text;
var replyToken = eventObj.replyToken;
var cur_user = eventObj.source.userId;
console.log(req.body)
console.log(cur_user);
var Cus = false;
var z = 0
for( z = 0; z < User.length; z++){
if(cur_user == User[z].id){
Cus = true;
break;
}
}
if( text == '회원가입') {
for( var i = 0; i < User.length; i++){
if(cur_user == User[i]){
Message('회원가입이 이미 된 고객입니다')
return;
}
}
User.push([{"id" : cur_user},{"state" : null} ]);
}
if(!Cus) {
Message('회원가입을 진행 후 쇼핑해주세요')
}
if(User[z].state != null){
switch(User[z].state){
case '상품구매':
purchase(z,text)
}
}
console.log('start');
if( text == '상품구매') {
var Message ='번호-갯수를 입력하시면(ex:5번을 5개 구매 = 5-5) 구매를\n, 0을 누르시면 취소입니다.\n'
User[z].state = '상품구매'
for(let i=0;i<items.length;i++){
Message += items[i].id +'. '+ items[i].name + '\n'
}
Message(Message);
}
});
try {
var sql = 'SELECT * FROM item';
conn.query(sql, function (err, rows, fields) {
if(err) {
console.log('query is not excuted. select fail...\n' + err)
}
else {
items = rows;
}
});
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
};
HTTPS.createServer(option, app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"ejs": "^3.1.6",
"express": "^4.15.2",
"express-session": "^1.15.2",
"jsdom": "^19.0.0",
"mysql": "^2.18.1",
"oracledb": "^5.3.0",
"request": "^2.88.2"
}
}
create table users(
id varchar2(20) primary key,
pwd varchar2(20),
name varchar2(20),
email varchar2(40),
zip_code varchar2(7),
address varchar2(100),
phone varchar2(20),
useyn number default 1, -- 활동 : 1, 탈퇴 : 2
regdate date default sysdate);
create table cust(
id varchar(35) primary key,
pwd varchar(12),
name varchar(4),
email varchar(40),
address_num int,
signdate timestamp default Now(),
address varchar(40),
phone varchar(15),
useyn int default 1, -- 활동 : 1, 탈퇴 : 0
isadmin int default 0 -- 관리자 : 1, 회원 : 0
);
create table emp(
id varchar(35) ,
pwd varchar(12),
name varchar(4),
email varchar(40),
phone varchar(15),
primary key (id),
FOREIGN KEY (id) REFERENCES cust(id)
);
create table item(
id varchar(40),
name varchar(20),
category int,
cost int,
price int,
profit int,
content varchar(1000),
image varchar(100),
useyn int default 1, -- 판매 1, 미판매 0
signdate timestamp default Now(),
primary key (id)
);
create table item_order(
id int,
item_id varchar(40),
count int,
complete int default 0,-- 주문 처리 후 0, 주문 해결완료(배송완료) 1
cust_id varchar(35),
primary key (id),
FOREIGN KEY (item_id) REFERENCES item(id),
FOREIGN KEY (cust_id) REFERENCES cust(id)
);
/*
insert into users
values ('U26c8ad1695d48e6b4bcccd4e6d25f3d9',
'124578','민구','ggalsrn@naver.com','17117',default ,'0288',default,default)
*/
\ No newline at end of file