Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김민규
/
rest_stop_list
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
min1925k@gmail.com
2022-06-01 16:24:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
776b1ea2cd59045f5179ef20e0874be46bb85540
776b1ea2
1 parent
5c886c7b
Login Signup Mod
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
76 additions
and
40 deletions
app/database/user_schema.js
app/routes/login.js
app/routes/signup.js
app/views/contact.html
app/views/faq.html
app/views/index.html
app/views/login.html
app/views/lpg.html
app/views/menu.html
app/views/post.ejs
app/views/postadd.ejs
app/views/signup.html
app/views/weather.html
app/database/user_schema.js
View file @
776b1ea
...
...
@@ -10,7 +10,7 @@ Schema.createSchema = function(mongoose) {
hashed_password
:
{
type
:
String
,
required
:
true
,
'default'
:
''
},
salt
:
{
type
:
String
,
required
:
true
},
name
:
{
type
:
String
,
index
:
'hashed'
,
'default'
:
''
},
email
:
{
type
:
Number
,
'default'
:
''
},
email
:
{
type
:
String
,
'default'
:
''
},
created_at
:
{
type
:
Date
,
index
:
{
unique
:
false
},
'default'
:
Date
.
now
},
updated_at
:
{
type
:
Date
,
index
:
{
unique
:
false
},
'default'
:
Date
.
now
}
});
...
...
app/routes/login.js
View file @
776b1ea
...
...
@@ -10,7 +10,6 @@ router.get('/',function(req,res){
});
router
.
post
(
'/process'
,
function
(
req
,
res
)
{
console
.
log
(
'/login/process 처리함'
);
var
paramId
=
req
.
body
.
id
||
req
.
query
.
id
;
var
paramPassword
=
req
.
body
.
password
||
req
.
query
.
password
;
...
...
@@ -39,21 +38,12 @@ router.post('/process', function(req, res) {
console
.
dir
(
docs
);
// 조회 결과에서 사용자 이름 확인
var
username
=
docs
[
0
].
name
;
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h1>로그인 성공</h1>'
);
res
.
write
(
'<div><p>사용자 아이디 : '
+
paramId
+
'</p></div>'
);
res
.
write
(
'<div><p>사용자 이름 : '
+
username
+
'</p></div>'
);
res
.
write
(
"<br><br><a href='/login'>다시 로그인하기</a>"
);
res
.
end
();
res
.
render
(
'login.html'
)
}
else
{
// 조회된 레코드가 없는 경우 실패 응답 전송
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h1>로그인 실패</h1>'
);
res
.
write
(
'<div><p>아이디와 패스워드를 다시 확인하십시오.</p></div>'
);
res
.
write
(
"<br><br><a href='/login'>다시 로그인하기</a>"
);
res
.
end
();
res
.
render
(
'/'
)
}
});
}
else
{
// 데이터베이스 객체가 초기화되지 않은 경우 실패 응답 전송
...
...
@@ -67,8 +57,6 @@ router.post('/process', function(req, res) {
//사용자를 인증하는 함수 : 아이디로 먼저 찾고 비밀번호를 그 다음에 비교하도록 함
var
authUser
=
function
(
database
,
id
,
password
,
callback
)
{
console
.
log
(
'authUser 호출됨.'
);
// 1. 아이디를 이용해 검색
database
.
UserModel
.
findById
(
id
,
function
(
err
,
results
)
{
if
(
err
)
{
...
...
@@ -80,7 +68,6 @@ var authUser = function(database, id, password, callback) {
console
.
dir
(
results
);
if
(
results
.
length
>
0
)
{
console
.
log
(
'아이디와 일치하는 사용자 찾음.'
);
// 2. 패스워드 확인 : 모델 인스턴스를 객체를 만들고 authenticate() 메소드 호출
var
user
=
new
database
.
UserModel
({
id
:
id
});
...
...
app/routes/signup.js
View file @
776b1ea
var
express
=
require
(
'express'
)
var
Conn
=
require
(
'../database/database'
)
var
router
=
express
.
Router
()
router
.
get
(
'/'
,
function
(
req
,
res
){
res
.
render
(
'signup.html'
)
});
router
.
post
(
'/process'
,
function
(
req
,
res
)
{
console
.
log
(
'/signup/process 처리함'
);
var
paramEmail
=
req
.
body
.
email
||
req
.
query
.
email
;
var
paramId
=
req
.
body
.
id
||
req
.
query
.
id
;
var
paramPassword
=
req
.
body
.
password
||
req
.
query
.
password
;
var
paramName
=
req
.
body
.
name
||
req
.
query
.
name
;
//GET, POST 모두 고려해서 둘 다 검사
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h1>Result form Express Server</h1>'
);
res
.
write
(
'<div><p>Param E-mail : '
+
paramEmail
+
'</p></div>'
);
res
.
write
(
'<div><p>Param id : '
+
paramId
+
'</p></div>'
);
res
.
write
(
'<div><p>Param password : '
+
paramPassword
+
'</p></div>'
);
res
.
write
(
"<br><br><a href ='/login.html'>로그인 페이지로 돌아가기</a>"
);
res
.
end
();
// 데이터베이스 객체 참조
var
database
=
req
.
app
.
get
(
'database'
);
// 데이터베이스 객체가 초기화된 경우, addUser 함수 호출하여 사용자 추가
if
(
database
.
db
)
{
addUser
(
database
,
paramId
,
paramPassword
,
paramName
,
paramEmail
,
function
(
err
,
addedUser
)
{
// 동일한 id로 추가하려는 경우 에러 발생 - 클라이언트로 에러 전송
if
(
err
)
{
console
.
error
(
'사용자 추가 중 에러 발생 : '
+
err
.
stack
);
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>사용자 추가 중 에러 발생</h2>'
);
res
.
write
(
'<p>'
+
err
.
stack
+
'</p>'
);
res
.
end
();
return
;
}
// 결과 객체 있으면 성공 응답 전송
if
(
addedUser
)
{
console
.
dir
(
addedUser
);
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>사용자 추가 성공</h2>'
);
res
.
write
(
"<br><br><a href='/login'>로그인하기</a>"
);
res
.
end
();
}
else
{
// 결과 객체가 없으면 실패 응답 전송
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>사용자 추가 실패</h2>'
);
res
.
write
(
"<br><br><a href='/signup'>다시 가입하기</a>"
);
res
.
end
();
}
});
}
else
{
// 데이터베이스 객체가 초기화되지 않은 경우 실패 응답 전송
res
.
writeHead
(
'200'
,
{
'Content-Type'
:
'text/html;charset=utf8'
});
res
.
write
(
'<h2>데이터베이스 연결 실패</h2>'
);
res
.
end
();
}
});
//사용자를 등록하는 함수
var
addUser
=
function
(
database
,
id
,
password
,
name
,
email
,
callback
)
{
// UserModel 인스턴스 생성
var
user
=
new
database
.
UserModel
({
"id"
:
id
,
"password"
:
password
,
"name"
:
name
,
"email"
:
email
});
// save()로 저장
user
.
save
(
function
(
err
)
{
if
(
err
)
{
callback
(
err
,
null
);
return
;
}
callback
(
null
,
user
);
});
}
module
.
exports
=
router
\ No newline at end of file
...
...
app/views/contact.html
View file @
776b1ea
...
...
@@ -26,7 +26,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/faq.html
View file @
776b1ea
...
...
@@ -26,7 +26,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/index.html
View file @
776b1ea
...
...
@@ -225,7 +225,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/login.html
View file @
776b1ea
...
...
@@ -28,7 +28,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/lpg.html
View file @
776b1ea
...
...
@@ -74,7 +74,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/menu.html
View file @
776b1ea
...
...
@@ -26,7 +26,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
app/views/post.ejs
View file @
776b1ea
...
...
@@ -32,7 +32,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
...
...
app/views/postadd.ejs
View file @
776b1ea
...
...
@@ -32,7 +32,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
...
...
app/views/signup.html
View file @
776b1ea
...
...
@@ -28,7 +28,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
@@ -62,6 +62,10 @@
<td><input
type=
"text"
name=
"email"
></td>
</tr>
<tr>
<td><label>
이름
</label></td>
<td><input
type=
"text"
name=
"name"
></td>
</tr>
<tr>
<td><label>
아이디
</label></td>
<td><input
type=
"text"
name=
"id"
></td>
</tr>
...
...
app/views/weather.html
View file @
776b1ea
...
...
@@ -28,7 +28,7 @@
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/menu"
>
휴게소 메뉴
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/weather"
>
날씨
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"/lpg"
>
LPG
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
faq.html"
>
FAQ
</a></li>
<li
class=
"nav-item"
><a
class=
"nav-link"
href=
"
/post"
>
Board
</a></li>
<li
class=
"nav-item dropdown"
>
<a
class=
"nav-link dropdown-toggle"
id=
"navbarDropdownBlog"
href=
"#"
role=
"button"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
Blog
</a>
<ul
class=
"dropdown-menu dropdown-menu-end"
aria-labelledby=
"navbarDropdownBlog"
>
...
...
Please
register
or
login
to post a comment