Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jeongmin Seo
/
favorite_restaurant
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Jeongmin Seo
2022-06-09 01:01:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7a407bce61f04e77de86caa02b91be8af2abe9fe
7a407bce
1 parent
90f2955a
Update login and signup response
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
84 deletions
login_main/app/package-lock.json
login_main/app/package.json
login_main/app/src/models/User.js
login_main/app/src/models/UserStorage.js
login_main/app/src/public/js/home/register.js
login_main/app/src/routes/home/home.ctrl.js
login_main/app/src/routes/home/restaurant.route.js
login_main/app/package-lock.json
View file @
7a407bc
...
...
@@ -19,6 +19,19 @@
"kuler"
:
"^2.0.0"
}
},
"@types/mysql"
:
{
"version"
:
"2.15.21"
,
"resolved"
:
"https://registry.npmjs.org/@types/mysql/-/mysql-2.15.21.tgz"
,
"integrity"
:
"sha512-NPotx5CVful7yB+qZbWtXL2fA4e7aEHkihHLjklc6ID8aq7bhguHgeIoC1EmSNTAuCgI6ZXrjt2ZSaXnYX0EUg=="
,
"requires"
:
{
"@types/node"
:
"*"
}
},
"@types/node"
:
{
"version"
:
"17.0.41"
,
"resolved"
:
"https://registry.npmjs.org/@types/node/-/node-17.0.41.tgz"
,
"integrity"
:
"sha512-xA6drNNeqb5YyV5fO3OAEsnXLfO7uF0whiOfPTz5AeDo8KeZFmODKnvwPymMNO8qE/an8pVY/O50tig2SQCrGw=="
},
"accepts"
:
{
"version"
:
"1.3.8"
,
"resolved"
:
"https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz"
,
...
...
@@ -334,9 +347,9 @@
"integrity"
:
"sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
},
"denque"
:
{
"version"
:
"
2.0
.1"
,
"resolved"
:
"https://registry.npmjs.org/denque/-/denque-
2.0
.1.tgz"
,
"integrity"
:
"sha512-
tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ
=="
"version"
:
"
1.5
.1"
,
"resolved"
:
"https://registry.npmjs.org/denque/-/denque-
1.5
.1.tgz"
,
"integrity"
:
"sha512-
XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw
=="
},
"depd"
:
{
"version"
:
"2.0.0"
,
...
...
@@ -928,13 +941,14 @@
}
},
"mysql2"
:
{
"version"
:
"2.
3.3
"
,
"resolved"
:
"https://registry.npmjs.org/mysql2/-/mysql2-2.
3.3
.tgz"
,
"integrity"
:
"sha512-
wxJUev6LgMSgACDkb/InIFxDprRa6T95+VEoR+xPvtngtccNH2dGjEB/fVZ8yg1gWv1510c9CvXuJHi5zUm0ZA
=="
,
"version"
:
"2.
2.0
"
,
"resolved"
:
"https://registry.npmjs.org/mysql2/-/mysql2-2.
2.0
.tgz"
,
"integrity"
:
"sha512-
3DvnvXihGiFrq6oaMjGN+gR/oreZA5cA1bI7/yBAvReo2W2I6cHd8vfX/9mk9FQEebubxqB/4VAlIJTlnYUEEg
=="
,
"requires"
:
{
"denque"
:
"^2.0.1"
,
"@types/mysql"
:
"^2.15.7"
,
"denque"
:
"^1.4.1"
,
"generate-function"
:
"^2.3.1"
,
"iconv-lite"
:
"^0.6.
3
"
,
"iconv-lite"
:
"^0.6.
2
"
,
"long"
:
"^4.0.0"
,
"lru-cache"
:
"^6.0.0"
,
"named-placeholders"
:
"^1.1.2"
,
...
...
login_main/app/package.json
View file @
7a407bc
...
...
@@ -17,7 +17,7 @@
"jsonwebtoken"
:
"^8.5.1"
,
"method-override"
:
"^3.0.0"
,
"mysql"
:
"^2.18.1"
,
"mysql2"
:
"^2.
0
.0"
,
"mysql2"
:
"^2.
2
.0"
,
"regex-email"
:
"^1.0.2"
,
"request"
:
"^2.88.2"
,
"winston"
:
"^3.2.1"
,
...
...
login_main/app/src/models/User.js
View file @
7a407bc
...
...
@@ -14,7 +14,6 @@ class User {
const
client
=
this
.
body
;
try
{
const
connection
=
await
pool
.
getConnection
(
async
(
conn
)
=>
conn
);
try
{
const
{
id
,
password
}
=
await
UserStorage
.
getUserInfo
(
connection
,
client
.
id
);
// console.log(id, password);
...
...
@@ -39,19 +38,19 @@ class User {
async
register
()
{
const
client
=
this
.
body
;
try
{
const
connection
=
await
pool
.
getConnection
(
async
(
conn
)
=>
conn
);
// console.log(client);
try
{
const
response
=
await
UserStorage
.
save
(
connection
,
client
);
// console.log(response);
// console.log(
"테스트2 : ",
response);
return
response
;
}
catch
(
err
)
{
return
{
success
:
false
,
msg
:
err
};
}
finally
{
connection
.
release
();
}
}
catch
(
err
)
{
console
.
log
(
err
);
return
{
success
:
false
,
msg
:
err
};
}
finally
{
connection
.
release
();
}
}
catch
(
err
)
{
logger
.
error
(
`usersaving DB Connection error\n:
${
JSON
.
stringify
(
err
)}
`
);
return
false
;
...
...
login_main/app/src/models/UserStorage.js
View file @
7a407bc
'use strict'
;
const
{
pool
}
=
require
(
"../config/db"
);
//for DB CRUD
const
pool
=
require
(
"../config/db"
);
class
UserStorage
{
constructor
(
body
)
{
this
.
body
=
body
;
// this.connection = await pool.getConnection(async (conn) => conn);
}
// static getUsers(isAll, ...fields) {}
static
async
getUserInfo
(
connection
,
id
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -14,23 +19,28 @@ class UserStorage {
if
(
err
)
reject
(
`
${
err
}
`
);
// console.log(data[0]);
resolve
(
data
[
0
]);
pool
.
releaseConnection
(
conn
);
});
});
}
static
async
save
(
connection
,
userInfo
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
query
=
"INSERT INTO users(id, name, password) VALUES(?, ?, ?);"
;
connection
.
query
(
query
,
[
userInfo
.
id
,
userInfo
.
name
,
userInfo
.
password
],
(
err
,
data
)
=>
{
if
(
err
)
reject
(
`
${
err
}
`
);
// console.log(data[0]);
resolve
({
success
:
true
});
}
);
});
static
async
save
(
connection
,
userInfo
)
{
const
query
=
"INSERT INTO users(id, name, password) VALUES(?, ?, ?);"
;
try
{
const
[
rows
]
=
await
connection
.
query
({
sql
:
query
,
timeout
:
30000
,
values
:
[
userInfo
.
id
,
userInfo
.
name
,
userInfo
.
password
]
});
// console.log(fields);
if
(
rows
.
affectedRows
)
{
return
{
success
:
true
};
}
else
{
return
{
success
:
false
};
}
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
}
...
...
login_main/app/src/public/js/home/register.js
View file @
7a407bc
...
...
@@ -8,7 +8,7 @@ const id = document.querySelector("#id"),
registerBtn
.
addEventListener
(
"click"
,
register
);
function
register
()
{
async
function
register
()
{
if
(
!
id
.
value
)
{
return
alert
(
"아이디를 입력해주세요."
)
}
...
...
@@ -27,28 +27,23 @@ function register() {
}
const
req
=
{
id
:
id
.
value
,
name
:
name
.
value
,
password
:
password
.
value
,
id
:
id
.
value
,
name
:
name
.
value
,
password
:
password
.
value
,
};
fetch
(
"/register"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
},
body
:
JSON
.
stringify
(
req
),
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
res
)
=>
{
if
(
res
.
success
)
{
//성공하면 이동
location
.
href
=
"/login"
;
}
else
{
alert
(
res
.
msg
);
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"회원가입 중 에러 발생"
);
console
.
log
(
"id : "
,
req
.
id
);
try
{
const
response
=
await
fetch
(
"/register"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
},
body
:
JSON
.
stringify
(
req
),
});
console
.
log
(
"테스트 : "
,
response
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
}
\ No newline at end of file
...
...
login_main/app/src/routes/home/home.ctrl.js
View file @
7a407bc
...
...
@@ -31,6 +31,8 @@ const process = {
register
:
async
(
req
,
res
)
=>
{
const
user
=
new
User
(
req
.
body
);
const
response
=
await
user
.
register
();
// console.log(res.json(response));
// console.log(res.json(response).statusCode); => 이거도 잘 찍혔음.
return
res
.
json
(
response
);
},
...
...
@@ -39,23 +41,6 @@ const process = {
// const response = await restaurant.restaurants();
// return res.json(response);
// },
// const id = req.body.id,
// password = req.body.password;
// const users = UserStorage.getUsers("id", "password");
// // console.log(UserStorage.getUsers("id", "password","name"));
// const response = {};
// if (users.id.includes(id)) {
// const idx = users.id.indexOf(id);
// if (users.password[idx] === password) {
// response.success = true;
// return res.json(response);
// }
// }
// response.success = false;
// response.msg = "로그인에 실패하였습니다."
// return res.json(response);
};
module
.
exports
=
{
...
...
login_main/app/src/routes/home/restaurant.route.js
View file @
7a407bc
module
.
exports
=
function
(
app
)
{
//controller갖고있는 모듈 생성
const
index
=
require
(
"../../models/Restaurant"
);
// const user = require("../../models/User");
const
jwtMiddleware
=
require
(
"../../config/jwtMiddleware"
);
// 식당 목록 조회
app
.
get
(
"/restaurants"
,
index
.
readRestaurants
);
// const express = require("express");
// const router = express.Router();
// const ctrl = require("./home.ctrl");
// router.get("/", ctrl.output.hello);
// router.get("/login", ctrl.output.login);
// router.get("/register", ctrl.output.register);
// router.post("/login", ctrl.process.login);
// router.post("/register", ctrl.process.register);
// module.exports = router;
};
\ No newline at end of file
...
...
Please
register
or
login
to post a comment