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
dckat
2021-05-17 15:24:48 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
9cc39958f9e7e55e24e22c61bd28dac8fa13ac5f
9cc39958
2 parents
2f004d1d
725445bd
카페 리스트 API 호출
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
132 additions
and
11 deletions
README.md
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
README.md
0 → 100644
View file @
9cc3995
###초기설정
>####데이터 베이스 설정
> <pre><code>
>CREATE TABLE USER(
>ID int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
>EMAIL varchar(64) NOT NULL UNIQUE,
>NAME varchar(64) NOT NULL,
>NICKNAME varchar(32) UNIQUE,
>AGE varchar(32),
>GENDER varchar(32)
>);
</code>
</pre>
###commit 형식
<pre><code>
##### 제목 - 50자 이내로 요약!
### [커밋 타입]: [작업내용]
##### 본문 - 한 줄에 최대 72 글자까지만 입력하기
# 1. 무엇을 수정했는지
# 2. 왜 수정했는지
# 꼬릿말은 아래에 작성: ex) #이슈 번호
-
# [커밋 타입] 리스트
# feat : 기능 (새로운 기능)
# fix : 버그 (버그 수정)
# refactor : 리팩토링
# style : 스타일 (코드 형식, 세미콜론 추가: 비즈니스 로직에 변경 없음)
# docs : 문서 (문서 추가, 수정, 삭제)
# test : 테스트 (테스트 코드 추가, 수정, 삭제: 비즈니스 로직에 변경 없음)
# chore : 기타 변경사항 (빌드 스크립트 수정 등)
# post : 블로그 포스트 추가 (신규 포스트 작성 및 수정)
# ------------------
# [체크리스트]
# 제목 첫 글자는 대문자로 작성했나요?
</code>
</pre>
package-lock.json
View file @
9cc3995
This diff is collapsed. Click to expand it.
package.json
View file @
9cc3995
...
...
@@ -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"
,
"request"
:
"^2.88.2"
,
"session-file-store"
:
"^1.5.0"
...
...
routes/index.js
View file @
9cc3995
var
express
=
require
(
"express"
);
var
router
=
express
.
Router
();
var
request
=
require
(
"request"
);
var
bodyParser
=
require
(
'body-parser'
);
var
{
OAuth2Client
}
=
require
(
"google-auth-library"
);
var
querystring
=
require
(
"querystring"
);
...
...
@@ -8,8 +10,11 @@ var querystring = require("querystring");
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"
,
// 암호화
...
...
@@ -18,7 +23,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"
,
{
...
...
@@ -48,16 +59,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
});
}
});
});
router
.
get
(
"/cafe"
,
(
req
,
res
)
=>
{
...
...
@@ -104,15 +159,28 @@ 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
)
=>
{
res
.
redirect
(
"/index"
);
});
}
<<<<<<<
HEAD
=======
router
.
get
(
"/map"
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
session
.
user
);
res
.
render
(
"map"
);
});
router
.
get
(
'/logout'
,
function
(
req
,
res
){
req
.
session
.
destroy
();
//세션비우기
res
.
redirect
(
'/'
);
});
>>>>>>>
725445
bde095435f47f8bc948873818794f00365
...
...
sessions/9anlK_hTbLco85V1W-mqJemF2Q8HR__9.json
0 → 100644
View file @
9cc3995
{
"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 @
2f004d1
{
"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 @
2f004d1
{
"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 @
9cc3995
{
"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 @
9cc3995
{
"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 @
9cc3995
...
...
@@ -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