Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최시원
/
Singer-Composer
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
choi
2021-11-17 15:07:58 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
f15df7da73409d95dc80c32278d7c63319db6849
f15df7da
2 parents
0cd29992
9532a386
Add the bulletin reading function
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
69 additions
and
33 deletions
public/main.html
public/register.html
readme.md
router/board/index.js
router/login/index.js
router/logout/index.js
router/main/main.js
router/register/index.js
views/list.ejs
views/main.ejs
views/register.ejs
public/main.html
View file @
f15df7d
...
...
@@ -45,11 +45,9 @@
<form
class=
"form-subscribe"
id=
"contactForm"
data-sb-form-api-token=
"API_TOKEN"
>
<!-- ID input-->
<div
class=
"row"
>
<div
class=
"col"
>
<input
class=
"form-control form-control-lg"
id=
"IDBelow"
type=
"text"
placeholder=
"ID"
data-sb-validations=
"required"
/>
<div
class=
"invalid-feedback text-white"
data-sb-feedback=
"IDBelow:required"
>
ID를 입력하세요.
</div>
<div
class=
"row"
>
<a
class=
"btn btn-primary"
href=
"/board/list"
>
임시게시판
</a>
</div>
<div
class=
"col-auto"
><button
class=
"btn btn-primary btn-lg disabled"
id=
"submitButton"
type=
"submit"
>
회원가입
</button></div>
</div>
<!-- Submit success message-->
<!---->
...
...
public/register.html
View file @
f15df7d
...
...
@@ -43,6 +43,11 @@
<div
class=
"invalid-feedback"
data-sb-feedback=
"passwordConfirm:required"
>
비밀번호 확인을 해주세요.
</div>
</div>
<div
class=
"form-floating mb-3"
>
<input
class=
"form-control"
name=
"nickname"
id=
"nickname"
type=
"text"
required
minlength=
'1'
maxlength=
'20'
placeholder=
"nickname"
data-sb-validations=
"required"
/>
<label
for=
"nickname"
>
닉네임
</label>
<div
class=
"invalid-feedback"
data-sb-feedback=
"nickname:required"
>
닉네임을 입력하세요.
</div>
</div>
<div
class=
"form-floating mb-3"
>
<select
class=
"form-select"
name=
"type"
id=
"type"
aria-label=
"사용자 유형"
>
<option
value=
"작곡가"
>
작곡가
</option>
<option
value=
"가수"
>
가수
</option>
...
...
readme.md
View file @
f15df7d
...
...
@@ -21,6 +21,19 @@ sql 사용 파일<br>
DB 구조(
*
ID, password, type) -> 형식에 맞게 추가
<br>
*
ID varchar(20), password varchar(20), type varchar(10) // type이 운영자인 경우 서버에서 변경
<br>
추가된 형식에 맞는 로그인 및 세션 등 변경
<br>
alter table userDB add nickname varchar(20) not null;
<br>
CREATE TABLE
`board`
(
`idx`
int(11) NOT NULL AUTO_INCREMENT,
`name`
varchar(50) NOT NULL,
`title`
varchar(50) NOT NULL,
`content`
mediumtext NOT NULL,
`regdate`
datetime NOT NULL,
`modidate`
datetime NOT NULL,
`passwd`
varchar(50) NOT NULL,
`hit`
int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (
`idx`
)
);
DB구조 - board에서 사용됨(
*
idx, name, title, content, regdate, modidate, passwd, hit)
<br>
*
idx int, name varchar(50), title varchar(50), content mediumtext, regdate datetime, modidate datetime, passwd varchar(50), hit int
<br>
...
...
@@ -31,3 +44,6 @@ LF 오류시 git config --global core.autocrlf true 입력<br><br>
최종 수정: 2021-11-17 06:01
<br>
최종 수정 내용: 게시판의 글쓰기 및 글 열람 기능 추가.
최종 수정: 2021-11-17 14:25
<br>
최종 수정 내용: 세션에 ID + 닉네임 전달기능 추가
수정 내용: 경로 지정 수정, 제목 추가, userDB, 회원가입에 nickname요소 추가
...
...
router/board/index.js
View file @
f15df7d
...
...
@@ -14,9 +14,10 @@ router.get('/list/:page', function(req, res, next) {
board
.
query
(
sql
,
function
(
err
,
rows
)
{
if
(
err
)
console
.
error
(
"err : "
+
err
);
var
id
=
req
.
user
;
if
(
!
id
)
id
=
"수정예정"
res
.
render
(
'list.ejs'
,
{
'ID'
:
id
,
title
:
'게시판 리스트'
,
rows
:
rows
})
var
id
=
req
.
user
.
ID
;
var
nickname
=
req
.
user
.
nickname
;
if
(
!
id
)
nickname
=
"손님"
// 수정 예정
res
.
render
(
'list.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
,
title
:
'게시판 리스트'
,
rows
:
rows
})
})
});
...
...
router/login/index.js
View file @
f15df7d
...
...
@@ -24,12 +24,14 @@ router.get('/', function(req, res){
})
passport
.
serializeUser
(
function
(
user
,
done
){
console
.
log
(
'passport session save: '
+
user
.
ID
)
done
(
null
,
user
.
ID
)
console
.
log
(
'passport session save: '
+
user
.
ID
+
'('
+
user
.
nickname
+
')'
)
done
(
null
,
user
)
});
passport
.
deserializeUser
(
function
(
ID
,
done
){
console
.
log
(
'passport session get ID: '
+
ID
)
done
(
null
,
ID
);
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
passport
.
deserializeUser
(
function
(
user
,
done
){
var
ID
=
user
.
ID
;
var
nickname
=
user
.
nickname
;
console
.
log
(
'passport session get ID: '
+
ID
+
'('
+
nickname
+
')'
)
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
})
passport
.
use
(
'local-login'
,
new
LocalStrategy
({
...
...
@@ -42,8 +44,8 @@ passport.use('local-login', new LocalStrategy({
if
(
rows
.
length
){
// database에 입력한 ID값이 있는가?
if
(
password
==
rows
[
0
].
password
){
// 비밀번호와 확인이 같은가?
console
.
log
(
"알림: "
+
ID
+
"
유저 로그인"
)
return
done
(
null
,
{
'ID'
:
ID
});
console
.
log
(
"알림: "
+
ID
+
"("
+
rows
[
0
].
nickname
+
")
유저 로그인"
)
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
rows
[
0
].
nickname
});
}
else
{
console
.
log
(
"알림: 잘못된 비밀번호입니다."
)
...
...
router/logout/index.js
View file @
f15df7d
...
...
@@ -3,7 +3,7 @@ var app = express()
var
router
=
express
.
Router
();
router
.
get
(
'/'
,
function
(
req
,
res
){
console
.
log
(
req
.
user
+
"
유저가 로그아웃합니다."
)
console
.
log
(
req
.
user
.
ID
+
"("
+
req
.
user
.
nickname
+
")
유저가 로그아웃합니다."
)
req
.
logout
();
req
.
session
.
save
(
function
(){
res
.
redirect
(
'/'
);
...
...
router/main/main.js
View file @
f15df7d
...
...
@@ -5,11 +5,12 @@ var path = require('path') // 상대경로
// main page는 login이 된 상태(세션정보가 있을때만) 접근이 가능하게 하자 -> info에 구현해놓음.
router
.
get
(
'/'
,
function
(
req
,
res
){
var
id
=
req
.
user
;
var
id
=
req
.
user
.
ID
;
if
(
!
id
)
res
.
sendFile
(
path
.
join
(
__dirname
,
"../../public/main.html"
))
if
(
id
){
console
.
log
(
req
.
user
,
'유저가 작업 중입니다.'
)
res
.
render
(
'main.ejs'
,
{
'ID'
:
id
});
var
nickname
=
req
.
user
.
nickname
;
console
.
log
(
req
.
user
.
ID
+
'('
+
nickname
+
') 유저가 작업 중입니다.'
)
res
.
render
(
'main.ejs'
,
{
'ID'
:
id
,
'nickname'
:
nickname
});
}
});
...
...
router/register/index.js
View file @
f15df7d
...
...
@@ -24,12 +24,14 @@ router.get('/', function(req, res){
})
passport
.
serializeUser
(
function
(
user
,
done
){
console
.
log
(
'passport session save: '
+
user
.
ID
)
done
(
null
,
user
.
ID
)
console
.
log
(
'passport session save: '
+
user
.
ID
+
'('
+
user
.
nickname
+
')'
)
done
(
null
,
user
)
});
passport
.
deserializeUser
(
function
(
ID
,
done
){
console
.
log
(
'passport session get ID: '
+
ID
)
done
(
null
,
ID
);
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
passport
.
deserializeUser
(
function
(
user
,
done
){
var
ID
=
user
.
ID
;
var
nickname
=
user
.
nickname
;
console
.
log
(
'passport session get ID: '
+
ID
+
'('
+
nickname
+
')'
)
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
nickname
});
// 세션에서 값을 뽑아서 페이지에 전달하는 역할
})
passport
.
use
(
'local-join'
,
new
LocalStrategy
({
...
...
@@ -37,6 +39,7 @@ passport.use('local-join', new LocalStrategy({
passwordField
:
'password'
,
pwcomField
:
'pw_com'
,
usertypeField
:
'type'
,
nicknameField
:
'nickname'
,
passReqToCallback
:
true
},
function
(
req
,
ID
,
password
,
done
){
var
query
=
connection
.
query
(
'select * from userDB where ID=?'
,
[
ID
],
function
(
err
,
rows
){
...
...
@@ -52,11 +55,20 @@ passport.use('local-join', new LocalStrategy({
return
done
(
null
,
false
,
{
message
:
'비밀번호가 일치하지 않습니다.'
})
}
else
{
var
sql
=
{
ID
:
ID
,
password
:
password
,
type
:
req
.
body
.
type
};
var
subqry
=
connection
.
query
(
'select * from userDB where nickname=?'
,
[
req
.
body
.
nickname
],
function
(
err
,
rows_
){
if
(
err
)
return
done
(
err
);
if
(
rows_
.
length
){
console
.
log
(
"알림: 중복된 닉네임입니다."
)
return
done
(
null
,
false
,
{
message
:
'중복된 닉네임입니다.'
})
}
else
{
var
sql
=
{
ID
:
ID
,
password
:
password
,
type
:
req
.
body
.
type
,
nickname
:
req
.
body
.
nickname
};
var
query
=
connection
.
query
(
'insert into userDB set ?'
,
sql
,
function
(
err
,
rows
){
if
(
err
)
throw
err
console
.
log
(
"알림: 사용자가 추가되었습니다.("
+
ID
+
")"
)
return
done
(
null
,
{
'ID'
:
ID
});
console
.
log
(
"알림: 사용자가 추가되었습니다.("
+
ID
+
", "
+
req
.
body
.
nickname
+
")"
)
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
req
.
body
.
nickname
});
})
}
})
}
}
...
...
views/list.ejs
View file @
f15df7d
...
...
@@ -12,7 +12,7 @@
<div
class=
"container"
>
<a
class=
"navbar-brand"
href=
"/main"
>
묵호의 놀이터
</a>
<div
class=
"user"
>
<a>
<
%=
ID
%> 님 안녕하세요
</section></a>
<a>
<
%=
nickname
%> 님 안녕하세요
</section></a>
<a
class=
"btn btn-primary"
href=
"/logout"
>
로그아웃
</a>
</div>
</div>
...
...
views/main.ejs
View file @
f15df7d
...
...
@@ -21,7 +21,7 @@
<div
class=
"container"
>
<a
class=
"navbar-brand"
href=
"/main"
>
묵호의 놀이터
</a>
<div
class=
"user"
>
<a>
<
%=
ID
%> 님 안녕하세요
</a>
<a>
<
%=
nickname
%> 님 안녕하세요
</a>
<a
class=
"btn btn-primary"
href=
"/logout"
>
로그아웃
</a>
</div>
</div>
...
...
@@ -45,11 +45,7 @@
<form
class=
"form-subscribe"
id=
"contactForm"
data-sb-form-api-token=
"API_TOKEN"
>
<!-- ID input-->
<div
class=
"row"
>
<div
class=
"col"
>
<input
class=
"form-control form-control-lg"
id=
"IDBelow"
type=
"text"
placeholder=
"ID"
data-sb-validations=
"required"
/>
<div
class=
"invalid-feedback text-white"
data-sb-feedback=
"IDBelow:required"
>
ID를 입력하세요.
</div>
</div>
<div
class=
"col-auto"
><button
class=
"btn btn-primary btn-lg disabled"
id=
"submitButton"
type=
"submit"
>
회원가입
</button></div>
<a
class=
"btn btn-primary"
href=
"/board/list"
>
임시게시판
</a>
</div>
<!-- Submit success message-->
<!---->
...
...
views/register.ejs
View file @
f15df7d
...
...
@@ -44,6 +44,11 @@
<div
class=
"invalid-feedback"
data-sb-feedback=
"passwordConfirm:required"
>
비밀번호 확인을 해주세요.
</div>
</div>
<div
class=
"form-floating mb-3"
>
<input
class=
"form-control"
name=
"nickname"
id=
"nickname"
type=
"text"
required
minlength=
'1'
maxlength=
'20'
placeholder=
"nickname"
data-sb-validations=
"required"
/>
<label
for=
"nickname"
>
닉네임
</label>
<div
class=
"invalid-feedback"
data-sb-feedback=
"nickname:required"
>
닉네임을 입력하세요.
</div>
</div>
<div
class=
"form-floating mb-3"
>
<select
class=
"form-select"
name=
"type"
id=
"type"
aria-label=
"사용자 유형"
>
<option
value=
"작곡가"
>
작곡가
</option>
<option
value=
"가수"
>
가수
</option>
...
...
Please
register
or
login
to post a comment