Showing
12 changed files
with
511 additions
and
0 deletions
admin.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <title>CuBe!</title> | ||
5 | + <script src="./app.js"></script> | ||
6 | + </head> | ||
7 | + <body> | ||
8 | + | ||
9 | + <p type="text" name="관리자메뉴" maxlength=20 size=20 > 관리자 메뉴입니다. </p> | ||
10 | + | ||
11 | + <form action="/adminsee" method="post"> | ||
12 | + <tr> | ||
13 | + <td><input type="submit" value="상품메뉴"></td> | ||
14 | + </tr> | ||
15 | + | ||
16 | + </table> | ||
17 | + </form> | ||
18 | + <form action="/reg" method="post"> | ||
19 | + <table> | ||
20 | + <tr> | ||
21 | + <td>제품 이름 : </td> | ||
22 | + <td><input type="text" name="name"></td> | ||
23 | + </tr> | ||
24 | + <tr> | ||
25 | + <td>분류 : 1:음식, 2:의류, 3:전자제품, 4:가구, 5:문구 </td> | ||
26 | + <td><input type="text" name= "category"></td> | ||
27 | + </tr> | ||
28 | + <tr> | ||
29 | + <td>원가 : </td> | ||
30 | + <td><input type="text" name="cost"></td> | ||
31 | + </tr> | ||
32 | + <tr> | ||
33 | + <td>판매가 : </td> | ||
34 | + <td><input type="text" name="price"></td> | ||
35 | + </tr> | ||
36 | + <tr> | ||
37 | + <td>순이익 : </td> | ||
38 | + <td><input type="text" name="profit"></td> | ||
39 | + </tr> | ||
40 | + <tr> | ||
41 | + <td>제품설명 : </td> | ||
42 | + <td><input type="text" name="content"></td> | ||
43 | + </tr> | ||
44 | + <tr> | ||
45 | + <td>이미지 : </td> | ||
46 | + <td><input type="text" name="image"></td> | ||
47 | + </tr> | ||
48 | + <tr> | ||
49 | + <td><input type="submit" value="상품등록"></td> | ||
50 | + </tr> | ||
51 | + | ||
52 | + </table> | ||
53 | + </form> | ||
54 | + <form action="/handling" method="post"> | ||
55 | + <tr> | ||
56 | + <td>배송할 주문 : </td> | ||
57 | + <td><input type="text" name="id"></td> | ||
58 | + </tr> | ||
59 | + <tr> | ||
60 | + <td><input type="submit" value="주문처리"></td> | ||
61 | + </tr> | ||
62 | + </form> | ||
63 | +<form action="/" method="get"> | ||
64 | + <tr> | ||
65 | + <td><input type="submit" value="처음화면으로"></td> | ||
66 | + </tr> | ||
67 | + | ||
68 | + </table> | ||
69 | +</form> | ||
70 | + </body> | ||
71 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app.js
0 → 100644
This diff is collapsed. Click to expand it.
cf.js
0 → 100644
1 | +var mysql = require('mysql'); | ||
2 | +var db_info = { | ||
3 | + host: 'localhost', | ||
4 | + port: '3306', | ||
5 | + user: 'ggalsrn', | ||
6 | + password: 'dkswjswlcla1.', | ||
7 | + database: 'shoppingmall' | ||
8 | +} | ||
9 | + | ||
10 | +module.exports = { | ||
11 | + init: function () { | ||
12 | + return mysql.createConnection(db_info); | ||
13 | + }, | ||
14 | + connect: function(conn) { | ||
15 | + conn.connect(function(err) { | ||
16 | + if(err) console.error('mysql connection error : ' + err); | ||
17 | + else console.log('mysql is connected successfully!'); | ||
18 | + }); | ||
19 | + } | ||
20 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
cust.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <title>CuBe!</title> | ||
5 | + <script src="./app.js"></script> | ||
6 | + </head> | ||
7 | + <body> | ||
8 | + <div type ="text" id="temp"></div> | ||
9 | + <form action="/see" method="post"> | ||
10 | + <tr> | ||
11 | + <td><input type="submit" value="상품메뉴"></td> | ||
12 | + </tr> | ||
13 | + | ||
14 | + </table> | ||
15 | + </form> | ||
16 | + | ||
17 | + <form action="/check" method="post"> | ||
18 | + <tr> | ||
19 | + <td><input type="submit" value="주문내역확인"></td> | ||
20 | + </tr> | ||
21 | + <tr> | ||
22 | + <td><input type="text" name= "usrid" placeholder="주문한사용자 id"></td> | ||
23 | + </tr> | ||
24 | + | ||
25 | + </table> | ||
26 | +</form> | ||
27 | +<form action="/" method="get"> | ||
28 | + <tr> | ||
29 | + <td><input type="submit" value="처음화면으로"></td> | ||
30 | + </tr> | ||
31 | + | ||
32 | +</table> | ||
33 | +</form> | ||
34 | + </body> | ||
35 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
fail.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <title>CuBe!</title> | ||
5 | + <script src="./app.js"></script> | ||
6 | + </head> | ||
7 | + <body> | ||
8 | + | ||
9 | + <p type="text" name="실패" maxlength=20 size=20 > 실패 </p> | ||
10 | + | ||
11 | + <div type ="text" id="temp"></div> | ||
12 | + <form action="/" method="get"> | ||
13 | + <tr> | ||
14 | + <td><input type="submit" value="처음화면으로"></td> | ||
15 | + </tr> | ||
16 | + | ||
17 | + </table> | ||
18 | + </form> | ||
19 | + <form action="/cust" method="get"> | ||
20 | + <tr> | ||
21 | + <td><input type="submit" value="메뉴로"></td> | ||
22 | + </tr> | ||
23 | + | ||
24 | + </table> | ||
25 | +</form> | ||
26 | + </body> | ||
27 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
index.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <title>CuBe!</title> | ||
5 | + <!--<script src="./app.js" type="text/javascript"></script>--> | ||
6 | + </head> | ||
7 | + <body> | ||
8 | + | ||
9 | + <script src="./app.js" type="text/javascript"></script> | ||
10 | + | ||
11 | + | ||
12 | + <a href="./join.html"><input type="button" value="회원가입"></a> | ||
13 | + | ||
14 | + <form action="/login" method="post"> | ||
15 | + <table> | ||
16 | + <tr> | ||
17 | + <td>ID : </td> | ||
18 | + <td><input type="text" name="id"></td> | ||
19 | + </tr> | ||
20 | + <tr> | ||
21 | + <td>비번 : </td> | ||
22 | + <td><input type="password" name="password"></td> | ||
23 | + </tr> | ||
24 | + <tr> | ||
25 | + <td><input type="submit" value="로그인"></td> | ||
26 | + </tr> | ||
27 | + </table> | ||
28 | + </form> | ||
29 | + | ||
30 | + <!--<button type="button" value="로그인" onclick="login()">홀롤롤로</button> | ||
31 | + <a href="./login"><button type="button" value="로그인">로그인</button></a> | ||
32 | + | ||
33 | + | ||
34 | + <div type ="text" id="pass">hi</div> | ||
35 | + <script> | ||
36 | + function login(){ | ||
37 | + document.getElementById('pass').innerHTML = "not hi" | ||
38 | + } | ||
39 | + </script> | ||
40 | + --> | ||
41 | + </body> | ||
42 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
join.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <title>CuBe!</title> | ||
5 | + <script src="./app.js"></script> | ||
6 | + </head> | ||
7 | + <body><!-- | ||
8 | + <p> | ||
9 | + <div type="text" name="회원가입" placeholder="회원가입" maxlength=20 size=20 ></div> | ||
10 | + </p> --> | ||
11 | + | ||
12 | + <form action="/signup" method="post"> | ||
13 | + <table> | ||
14 | + <tr> | ||
15 | + <td>아이디 : </td> | ||
16 | + <td><input type="text" name="id"></td> | ||
17 | + </tr> | ||
18 | + <tr> | ||
19 | + <td>비번 : </td> | ||
20 | + <td><input type="password" name="password"></td> | ||
21 | + </tr> | ||
22 | + <tr> | ||
23 | + <td>이름 : </td> | ||
24 | + <td><input type="text" name= "name"></td> | ||
25 | + </tr> | ||
26 | + <tr> | ||
27 | + <td>이메일 : </td> | ||
28 | + <td><input type="text" name="email"></td> | ||
29 | + </tr> | ||
30 | + <tr> | ||
31 | + <td>우편번호 : </td> | ||
32 | + <td><input type="text" name="address_num"></td> | ||
33 | + </tr> | ||
34 | + <tr> | ||
35 | + <td>주소 : </td> | ||
36 | + <td><input type="text" name="address"></td> | ||
37 | + </tr> | ||
38 | + <tr> | ||
39 | + <td>핸드폰번호 : </td> | ||
40 | + <td><input type="text" name="phone"></td> | ||
41 | + </tr> | ||
42 | + <tr> | ||
43 | + <td>관리자 가입코드 : </td> | ||
44 | + <td><input type="text" name="code"></td> | ||
45 | + </tr> | ||
46 | + <tr> | ||
47 | + <td><input type="submit" value="가입"></td> | ||
48 | + </tr> | ||
49 | + </table> | ||
50 | + </form> | ||
51 | + </body> | ||
52 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
line.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +const request = require('request'); | ||
3 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
4 | +const TOKEN = 'rQFBQXVZqeF1uFJSoPwloR8avp6Gkxssb2jNJdAFtfK' | ||
5 | + | ||
6 | +const fs = require('fs'); | ||
7 | +const path = require('path'); | ||
8 | +const HTTPS = require('https'); | ||
9 | +const domain = "localhost:80" | ||
10 | +const sslport = 23023; | ||
11 | +const bodyParser = require('body-parser'); | ||
12 | + | ||
13 | +let session = require('express-session'); | ||
14 | +const { text } = require('body-parser'); | ||
15 | +var app = express(); | ||
16 | +app.use(bodyParser.json()); | ||
17 | + | ||
18 | +var User = new Array(); | ||
19 | +/* | ||
20 | +app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) | ||
21 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
22 | +*/ | ||
23 | +var db_config = require(__dirname+ '/cf.js'); | ||
24 | +var conn = db_config.init(); | ||
25 | + | ||
26 | +db_config.connect(conn); | ||
27 | + | ||
28 | +app.set('views', __dirname + '/views'); | ||
29 | +app.set('view engine', 'ejs'); | ||
30 | + | ||
31 | + | ||
32 | +var ordernum = 0; | ||
33 | +var sql = 'SELECT * FROM item_order'; | ||
34 | +conn.query(sql, function (err, rows, fields) { | ||
35 | + if(err) { | ||
36 | + console.log('query is not excuted. select fail...\n' + err) | ||
37 | + } | ||
38 | + else { | ||
39 | + ordernum = rows.length; | ||
40 | + } | ||
41 | +}); | ||
42 | +function SL(text){ | ||
43 | +for(let j =0; j < text.length; j++){ | ||
44 | + if(text[j] = '-'){ | ||
45 | + return [text.slice(0,j),text.slice(j+1)] | ||
46 | + } | ||
47 | + else return; | ||
48 | +} | ||
49 | +} | ||
50 | +function Message(Message){ | ||
51 | + request.post( | ||
52 | + { | ||
53 | + url: TARGET_URL, | ||
54 | + headers: { | ||
55 | + 'Authorization': `Bearer ${TOKEN}` | ||
56 | + }, | ||
57 | + json: { | ||
58 | + "replyToken":replyToken, | ||
59 | + "messages":[ | ||
60 | + { | ||
61 | + "type":"text", | ||
62 | + "text":Message | ||
63 | + } | ||
64 | + ] | ||
65 | + } | ||
66 | + },(error, response, body) => { | ||
67 | + console.log(body) | ||
68 | + }); | ||
69 | + return console.log(Message); | ||
70 | +} | ||
71 | + | ||
72 | + | ||
73 | +function purchase(z, text){ | ||
74 | + let found = false; | ||
75 | + if(text == '0'){ | ||
76 | + User[z].state = null; | ||
77 | + return; | ||
78 | + } | ||
79 | + var tx; | ||
80 | + if (! (tx = SL(text))) return Message("잘못된 입력입니다."); | ||
81 | + for( let i= 0; i < items.length; i++){ | ||
82 | + if(tx[0] == items[i].id){ | ||
83 | + found= true; | ||
84 | + var table = 'item_order'; | ||
85 | + var sql = `INSERT INTO `+ table + ` VALUES(?,?,?,?,?)`; | ||
86 | + var params = [ordernum++, items[i].id, tx[1], 0, User[z].id]; | ||
87 | + console.log(sql); | ||
88 | + conn.query(sql, params, function(err) { | ||
89 | + if(err) { | ||
90 | + console.log('query is not excuted. insert fail...\n' + err); | ||
91 | + Message('주문에 실패했습니다') | ||
92 | + return ; | ||
93 | + } | ||
94 | + else { | ||
95 | + console.log('주문성공') | ||
96 | + User[z].state = null; | ||
97 | + } | ||
98 | + }); | ||
99 | + | ||
100 | + } | ||
101 | + } | ||
102 | + if (!found){ | ||
103 | + Message("존재하지 않는 상품입니다"); | ||
104 | + return; | ||
105 | + } | ||
106 | +} | ||
107 | +var items = ''; | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | ||
112 | +app.post('/hook', function(req, res) { | ||
113 | + var eventObj = req.body.events[0]; | ||
114 | + var text = eventObj.message.text; | ||
115 | + var replyToken = eventObj.replyToken; | ||
116 | + var cur_user = eventObj.source.userId; | ||
117 | + console.log(req.body) | ||
118 | + console.log(cur_user); | ||
119 | + | ||
120 | + var Cus = false; | ||
121 | + var z = 0 | ||
122 | + for( z = 0; z < User.length; z++){ | ||
123 | + if(cur_user == User[z].id){ | ||
124 | + Cus = true; | ||
125 | + break; | ||
126 | + } | ||
127 | + } | ||
128 | + if( text == '회원가입') { | ||
129 | + for( var i = 0; i < User.length; i++){ | ||
130 | + if(cur_user == User[i]){ | ||
131 | + Message('회원가입이 이미 된 고객입니다') | ||
132 | + return; | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + User.push([{"id" : cur_user},{"state" : null} ]); | ||
137 | + } | ||
138 | + if(!Cus) { | ||
139 | + Message('회원가입을 진행 후 쇼핑해주세요') | ||
140 | + } | ||
141 | + if(User[z].state != null){ | ||
142 | + switch(User[z].state){ | ||
143 | + case '상품구매': | ||
144 | + purchase(z,text) | ||
145 | + } | ||
146 | + } | ||
147 | + console.log('start'); | ||
148 | + if( text == '상품구매') { | ||
149 | + var Message ='번호-갯수를 입력하시면(ex:5번을 5개 구매 = 5-5) 구매를\n, 0을 누르시면 취소입니다.\n' | ||
150 | + User[z].state = '상품구매' | ||
151 | + for(let i=0;i<items.length;i++){ | ||
152 | + Message += items[i].id +'. '+ items[i].name + '\n' | ||
153 | + } | ||
154 | + Message(Message); | ||
155 | + | ||
156 | + | ||
157 | + } | ||
158 | +}); | ||
159 | + | ||
160 | +try { | ||
161 | + | ||
162 | +var sql = 'SELECT * FROM item'; | ||
163 | +conn.query(sql, function (err, rows, fields) { | ||
164 | + if(err) { | ||
165 | + console.log('query is not excuted. select fail...\n' + err) | ||
166 | + } | ||
167 | + else { | ||
168 | + items = rows; | ||
169 | + } | ||
170 | +}); | ||
171 | + const option = { | ||
172 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
173 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
174 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
175 | + }; | ||
176 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
177 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
178 | + }); | ||
179 | + | ||
180 | + | ||
181 | + } catch (error) { | ||
182 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
183 | + console.log(error); | ||
184 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "app", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "body-parser": "^1.17.1", | ||
13 | + "ejs": "^3.1.6", | ||
14 | + "express": "^4.15.2", | ||
15 | + "express-session": "^1.15.2", | ||
16 | + "jsdom": "^19.0.0", | ||
17 | + "mysql": "^2.18.1", | ||
18 | + "oracledb": "^5.3.0", | ||
19 | + "request": "^2.88.2" | ||
20 | + } | ||
21 | +} |
shop1.sql
0 → 100644
shoppingmall.sql
0 → 100644
1 | +create table cust( | ||
2 | + id varchar(35) primary key, | ||
3 | + pwd varchar(12), | ||
4 | + name varchar(4), | ||
5 | + email varchar(40), | ||
6 | + address_num int, | ||
7 | + signdate timestamp default Now(), | ||
8 | + address varchar(40), | ||
9 | + phone varchar(15), | ||
10 | + useyn int default 1, -- 활동 : 1, 탈퇴 : 0 | ||
11 | + isadmin int default 0 -- 관리자 : 1, 회원 : 0 | ||
12 | +); | ||
13 | +create table emp( | ||
14 | + id varchar(35) , | ||
15 | + pwd varchar(12), | ||
16 | + name varchar(4), | ||
17 | + email varchar(40), | ||
18 | + phone varchar(15), | ||
19 | + primary key (id), | ||
20 | + FOREIGN KEY (id) REFERENCES cust(id) | ||
21 | +); | ||
22 | +create table item( | ||
23 | + id varchar(40), | ||
24 | + name varchar(20), | ||
25 | + category int, | ||
26 | + cost int, | ||
27 | + price int, | ||
28 | + profit int, | ||
29 | + content varchar(1000), | ||
30 | + image varchar(100), | ||
31 | + useyn int default 1, -- 판매 1, 미판매 0 | ||
32 | + signdate timestamp default Now(), | ||
33 | + primary key (id) | ||
34 | +); | ||
35 | +create table item_order( | ||
36 | + id int, | ||
37 | + item_id varchar(40), | ||
38 | + count int, | ||
39 | + complete int default 0,-- 주문 처리 후 0, 주문 해결완료(배송완료) 1 | ||
40 | + cust_id varchar(35), | ||
41 | + primary key (id), | ||
42 | + FOREIGN KEY (item_id) REFERENCES item(id), | ||
43 | + FOREIGN KEY (cust_id) REFERENCES cust(id) | ||
44 | +); | ||
45 | +/* | ||
46 | +insert into users | ||
47 | +values ('U26c8ad1695d48e6b4bcccd4e6d25f3d9', | ||
48 | +'124578','민구','ggalsrn@naver.com','17117',default ,'0288',default,default) | ||
49 | +*/ | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment