Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대철
/
CafeRecommend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최정민
2021-05-17 03:58:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4f06d11709bab77f76c995241e0f4afa88f2daab
4f06d117
1 parent
ce0803c6
FEAT : MYSQL DB와 연동하여 로그인
-
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
11 deletions
package-lock.json
package.json
routes/index.js
sessions/9anlK_hTbLco85V1W-mqJemF2Q8HR__9.json
sessions/KtkF-7vF5BubSnuzjkUN0L2pGZOTFBqC.json
sessions/MEbzXm6yVZ3x71k39o7JtR0-SirVibPV.json
sessions/XJXKp-DftiJonu8hbJenVUV1-DS8Za8A.json
sessions/Xzn1l_evsUAaiH_WklXuK499rZ-viTZb.json
views/login.ejs
package-lock.json
View file @
4f06d11
This diff is collapsed. Click to expand it.
package.json
View file @
4f06d11
...
...
@@ -6,6 +6,7 @@
"start"
:
"nodemon ./bin/www"
},
"dependencies"
:
{
"body-parser"
:
"^1.19.0"
,
"cookie-parser"
:
"~1.4.4"
,
"debug"
:
"~2.6.9"
,
"ejs"
:
"^3.1.6"
,
...
...
@@ -14,6 +15,7 @@
"google-auth-library"
:
"^7.0.4"
,
"http-errors"
:
"~1.6.3"
,
"morgan"
:
"~1.9.1"
,
"mysql"
:
"^2.18.1"
,
"nodemon"
:
"^2.0.7"
,
"session-file-store"
:
"^1.5.0"
}
...
...
routes/index.js
View file @
4f06d11
var
express
=
require
(
"express"
);
var
router
=
express
.
Router
();
var
bodyParser
=
require
(
'body-parser'
);
var
{
OAuth2Client
}
=
require
(
"google-auth-library"
);
var
CLIENT_ID
=
"94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"
;
var
client
=
new
OAuth2Client
(
CLIENT_ID
);
var
mysql
=
require
(
'mysql'
)
var
session
=
require
(
"express-session"
);
var
FileStore
=
require
(
"session-file-store"
)(
session
);
router
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
//url인코딩 x
router
.
use
(
bodyParser
.
json
());
//json방식으로 파
router
.
use
(
session
({
secret
:
"209"
,
// 암호화
...
...
@@ -14,7 +18,13 @@ router.use(
store
:
new
FileStore
(),
})
);
var
connection
=
mysql
.
createConnection
({
host
:
'localhost'
,
user
:
'root'
,
password
:
'g79465'
,
database
:
'caferecommend'
});
connection
.
connect
();
/* GET home page. */
router
.
get
(
"/"
,
function
(
req
,
res
,
next
)
{
res
.
render
(
"index"
,
{
...
...
@@ -44,16 +54,60 @@ router.post("/index", (req, res) => {
});
router
.
get
(
"/login"
,
checkAuthenticated
,
(
req
,
res
)
=>
{
let
user
=
req
.
user
;
req
.
session
.
user
=
user
;
res
.
render
(
"login"
,
{
user
:
req
.
session
.
user
});
var
sql
=
'SELECT * FROM USER WHERE EMAIL=?'
;
var
parameter
=
[
req
.
session
.
user
.
email
];
connection
.
query
(
sql
,
parameter
,
function
(
err
,
row
){
if
(
err
){
console
.
log
(
err
);
}
else
{
if
(
row
.
length
>
0
)
{
console
.
log
(
"이미 가입이 되어있는 아이디"
)
req
.
session
.
user
.
nickname
=
row
[
0
].
NICKNAME
;
req
.
session
.
user
.
age
=
row
[
0
].
AGE
;
req
.
session
.
user
.
gender
=
row
[
0
].
GENDER
;
return
res
.
render
(
'map'
,
{
user
:
req
.
session
.
user
})
}
else
{
return
res
.
render
(
"login"
,
{
user
:
req
.
session
.
user
,
message
:
'none'
});
}
}
});
});
router
.
post
(
"/login"
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
.
nickname
);
console
.
log
(
req
.
body
.
age
);
console
.
log
(
req
.
body
.
gender
);
return
res
.
render
(
"login"
,
{
user
:
req
.
session
.
user
});
var
sql
=
' SELECT * FROM USER WHERE NICKNAME=?'
;
var
parameter
=
[
req
.
body
.
nickname
];
connection
.
query
(
sql
,
parameter
,
function
(
err
,
row
){
if
(
err
){
console
.
log
(
err
);
}
if
(
row
.
length
>
0
){
console
.
log
(
'동일 닉네임있음'
);
return
res
.
render
(
"login"
,
{
user
:
req
.
session
.
user
,
message
:
'same nickname'
});
}
else
{
req
.
session
.
user
.
nickname
=
req
.
body
.
nickname
;
req
.
session
.
user
.
age
=
req
.
body
.
age
;
req
.
session
.
user
.
gender
=
req
.
body
.
gender
;
var
sql
=
'INSERT INTO USER(EMAIL, NAME, NICKNAME, AGE, GENDER) VALUES(?,?,?,?,?)'
;
var
parameter
=
[
req
.
session
.
user
.
email
,
req
.
session
.
user
.
name
,
req
.
session
.
user
.
nickname
,
req
.
session
.
user
.
age
,
req
.
session
.
user
.
gender
];
connection
.
query
(
sql
,
parameter
,
function
(
err
,
row
){
if
(
err
){
console
.
log
(
err
);
}
else
{
console
.
log
(
"새로운 user데이터 입력"
);
}
});
return
res
.
render
(
"map"
,
{
user
:
req
.
session
.
user
});
}
});
});
module
.
exports
=
router
;
...
...
@@ -69,12 +123,11 @@ function checkAuthenticated(req, res, next) {
const
payload
=
ticket
.
getPayload
();
user
.
name
=
payload
.
name
;
user
.
email
=
payload
.
email
;
user
.
picture
=
payload
.
picture
;
console
.
log
(
user
.
name
);
}
verify
()
.
then
(()
=>
{
req
.
user
=
user
;
req
.
session
.
user
.
name
=
user
.
name
;
req
.
session
.
user
.
email
=
user
.
email
;
next
();
})
.
catch
((
err
)
=>
{
...
...
@@ -83,5 +136,12 @@ function checkAuthenticated(req, res, next) {
}
router
.
get
(
"/map"
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
session
.
user
);
res
.
render
(
"map"
);
});
router
.
get
(
'/logout'
,
function
(
req
,
res
){
req
.
session
.
destroy
();
//세션비우기
res
.
redirect
(
'/'
);
});
\ No newline at end of file
...
...
sessions/9anlK_hTbLco85V1W-mqJemF2Q8HR__9.json
0 → 100644
View file @
4f06d11
{
"cookie"
:{
"originalMaxAge"
:
null
,
"expires"
:
null
,
"httpOnly"
:
true
,
"path"
:
"/"
},
"__lastAccess"
:
1621187236305
}
\ No newline at end of file
sessions/KtkF-7vF5BubSnuzjkUN0L2pGZOTFBqC.json
deleted
100644 → 0
View file @
ce0803c
{
"cookie"
:{
"originalMaxAge"
:
null
,
"expires"
:
null
,
"httpOnly"
:
true
,
"path"
:
"/"
},
"__lastAccess"
:
1620823546959
,
"user"
:{
"name"
:
"김대철[학생](소프트웨어융합대학 컴퓨터공학과)"
,
"email"
:
"kdc9619@khu.ac.kr"
,
"picture"
:
"https://lh3.googleusercontent.com/a/AATXAJyP14ipRboJZ8T5-oNS3sRp4CG8wKCEwVABQ5G_=s96-c"
}}
\ No newline at end of file
sessions/MEbzXm6yVZ3x71k39o7JtR0-SirVibPV.json
deleted
100644 → 0
View file @
ce0803c
{
"cookie"
:{
"originalMaxAge"
:
null
,
"expires"
:
null
,
"httpOnly"
:
true
,
"path"
:
"/"
},
"__lastAccess"
:
1620684562564
,
"user"
:{
"name"
:
"최정민[학생](소프트웨어융합대학 컴퓨터공학과)"
,
"email"
:
"cjm2021401@khu.ac.kr"
,
"picture"
:
"https://lh3.googleusercontent.com/a/AATXAJzFD3R6CaL2NpysVrfvdGqcQ83vh_wpbN_5hj-0=s96-c"
}}
\ No newline at end of file
sessions/XJXKp-DftiJonu8hbJenVUV1-DS8Za8A.json
0 → 100644
View file @
4f06d11
{
"cookie"
:{
"originalMaxAge"
:
null
,
"expires"
:
null
,
"httpOnly"
:
true
,
"path"
:
"/"
},
"__lastAccess"
:
1621186188104
}
\ No newline at end of file
sessions/Xzn1l_evsUAaiH_WklXuK499rZ-viTZb.json
0 → 100644
View file @
4f06d11
{
"cookie"
:{
"originalMaxAge"
:
null
,
"expires"
:
null
,
"httpOnly"
:
true
,
"path"
:
"/"
},
"__lastAccess"
:
1621191395860
,
"user"
:{
"name"
:
"최정민[학생](소프트웨어융합대학 컴퓨터공학과)"
,
"email"
:
"cjm2021401@khu.ac.kr"
,
"nickname"
:
"Mayf"
,
"age"
:
"25"
,
"gender"
:
"male"
},
"gender"
:
"male"
}
\ No newline at end of file
views/login.ejs
View file @
4f06d11
...
...
@@ -22,8 +22,15 @@
<input
type=
"submit"
value=
"Submit"
>
</form>
<a
href=
"/index"
onclick=
"signOut();"
>
Sign Out
</a>
<a
href=
"/logout"
onclick=
"signOut();"
>
Sign Out
</a>
<
%if (message=='same nickname'){%>
<script
type=
"text/javascript"
>
alert
(
"입력하신 NICKNAME은 사용하지 못합니다."
+
"다른 NICKNAME을 입력하여 주세요"
);
</script>
<
%}%>
</body>
<script>
...
...
Please
register
or
login
to post a comment