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
Mukho
2021-11-17 14:27:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c8a6686340ba6d8458a3d532746be7b195e1f6b9
c8a66863
1 parent
14f02619
Add nickname and Update session
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
25 deletions
public/register.html
readme.md
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/register.html
View file @
c8a6686
...
...
@@ -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 @
c8a6686
...
...
@@ -20,9 +20,23 @@ 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`
)
);
LF 오류시 git config --global core.autocrlf true 입력
<br><br>
최종 수정: 2021-11-16 18:54
<br>
최종 수정 내용: 경로 지정 수정
\ No newline at end of file
최종 수정: 2021-11-17 14:25
<br>
최종 수정 내용: 세션에 ID + 닉네임 전달기능 추가
수정 내용: 경로 지정 수정, 제목 추가, userDB, 회원가입에 nickname요소 추가
\ No newline at end of file
...
...
router/login/index.js
View file @
c8a6686
...
...
@@ -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 @
c8a6686
...
...
@@ -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 @
c8a6686
...
...
@@ -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 @
c8a6686
...
...
@@ -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
query
=
connection
.
query
(
'insert into userDB set ?'
,
sql
,
function
(
err
,
rows
){
if
(
err
)
throw
err
console
.
log
(
"알림: 사용자가 추가되었습니다.("
+
ID
+
")"
)
return
done
(
null
,
{
'ID'
:
ID
});
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
+
", "
+
req
.
body
.
nickname
+
")"
)
return
done
(
null
,
{
'ID'
:
ID
,
'nickname'
:
req
.
body
.
nickname
});
})
}
})
}
}
...
...
views/list.ejs
View file @
c8a6686
...
...
@@ -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 @
c8a6686
...
...
@@ -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>
...
...
views/register.ejs
View file @
c8a6686
...
...
@@ -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