min1925k@gmail.com

Login Signup Mod

...@@ -10,7 +10,7 @@ Schema.createSchema = function(mongoose) { ...@@ -10,7 +10,7 @@ Schema.createSchema = function(mongoose) {
10 hashed_password: {type: String, required: true, 'default':''}, 10 hashed_password: {type: String, required: true, 'default':''},
11 salt: {type:String, required:true}, 11 salt: {type:String, required:true},
12 name: {type: String, index: 'hashed', 'default':''}, 12 name: {type: String, index: 'hashed', 'default':''},
13 - email: {type: Number, 'default': ''}, 13 + email: {type: String, 'default': ''},
14 created_at: {type: Date, index: {unique: false}, 'default': Date.now}, 14 created_at: {type: Date, index: {unique: false}, 'default': Date.now},
15 updated_at: {type: Date, index: {unique: false}, 'default': Date.now} 15 updated_at: {type: Date, index: {unique: false}, 'default': Date.now}
16 }); 16 });
......
...@@ -10,7 +10,6 @@ router.get('/',function(req,res){ ...@@ -10,7 +10,6 @@ router.get('/',function(req,res){
10 }); 10 });
11 11
12 router.post('/process', function(req, res) { 12 router.post('/process', function(req, res) {
13 - console.log('/login/process 처리함');
14 13
15 var paramId = req.body.id || req.query.id; 14 var paramId = req.body.id || req.query.id;
16 var paramPassword = req.body.password || req.query.password; 15 var paramPassword = req.body.password || req.query.password;
...@@ -39,21 +38,12 @@ router.post('/process', function(req, res) { ...@@ -39,21 +38,12 @@ router.post('/process', function(req, res) {
39 console.dir(docs); 38 console.dir(docs);
40 39
41 // 조회 결과에서 사용자 이름 확인 40 // 조회 결과에서 사용자 이름 확인
42 - var username = docs[0].name; 41 + res.render('login.html')
43 - 42 +
44 - res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
45 - res.write('<h1>로그인 성공</h1>');
46 - res.write('<div><p>사용자 아이디 : ' + paramId + '</p></div>');
47 - res.write('<div><p>사용자 이름 : ' + username + '</p></div>');
48 - res.write("<br><br><a href='/login'>다시 로그인하기</a>");
49 - res.end();
50 43
51 } else { // 조회된 레코드가 없는 경우 실패 응답 전송 44 } else { // 조회된 레코드가 없는 경우 실패 응답 전송
52 - res.writeHead('200', {'Content-Type':'text/html;charset=utf8'}); 45 + res.render('/')
53 - res.write('<h1>로그인 실패</h1>'); 46 +
54 - res.write('<div><p>아이디와 패스워드를 다시 확인하십시오.</p></div>');
55 - res.write("<br><br><a href='/login'>다시 로그인하기</a>");
56 - res.end();
57 } 47 }
58 }); 48 });
59 } else { // 데이터베이스 객체가 초기화되지 않은 경우 실패 응답 전송 49 } else { // 데이터베이스 객체가 초기화되지 않은 경우 실패 응답 전송
...@@ -67,8 +57,6 @@ router.post('/process', function(req, res) { ...@@ -67,8 +57,6 @@ router.post('/process', function(req, res) {
67 57
68 //사용자를 인증하는 함수 : 아이디로 먼저 찾고 비밀번호를 그 다음에 비교하도록 함 58 //사용자를 인증하는 함수 : 아이디로 먼저 찾고 비밀번호를 그 다음에 비교하도록 함
69 var authUser = function(database, id, password, callback) { 59 var authUser = function(database, id, password, callback) {
70 - console.log('authUser 호출됨.');
71 -
72 // 1. 아이디를 이용해 검색 60 // 1. 아이디를 이용해 검색
73 database.UserModel.findById(id, function(err, results) { 61 database.UserModel.findById(id, function(err, results) {
74 if (err) { 62 if (err) {
...@@ -80,7 +68,6 @@ var authUser = function(database, id, password, callback) { ...@@ -80,7 +68,6 @@ var authUser = function(database, id, password, callback) {
80 console.dir(results); 68 console.dir(results);
81 69
82 if (results.length > 0) { 70 if (results.length > 0) {
83 - console.log('아이디와 일치하는 사용자 찾음.');
84 71
85 // 2. 패스워드 확인 : 모델 인스턴스를 객체를 만들고 authenticate() 메소드 호출 72 // 2. 패스워드 확인 : 모델 인스턴스를 객체를 만들고 authenticate() 메소드 호출
86 var user = new database.UserModel({id:id}); 73 var user = new database.UserModel({id:id});
......
1 var express = require('express') 1 var express = require('express')
2 +var Conn = require('../database/database')
2 var router = express.Router() 3 var router = express.Router()
3 4
4 router.get('/',function(req,res){ 5 router.get('/',function(req,res){
5 res.render('signup.html') 6 res.render('signup.html')
6 }); 7 });
7 8
8 -
9 router.post('/process', function(req, res) { 9 router.post('/process', function(req, res) {
10 - console.log('/signup/process 처리함');
11 -
12 var paramEmail = req.body.email || req.query.email; 10 var paramEmail = req.body.email || req.query.email;
13 var paramId = req.body.id || req.query.id; 11 var paramId = req.body.id || req.query.id;
14 var paramPassword = req.body.password || req.query.password; 12 var paramPassword = req.body.password || req.query.password;
13 + var paramName = req.body.name || req.query.name;
15 //GET, POST 모두 고려해서 둘 다 검사 14 //GET, POST 모두 고려해서 둘 다 검사
16 - 15 + // 데이터베이스 객체 참조
17 - res.writeHead('200', { 'Content-Type': 'text/html;charset=utf8' }); 16 + var database = req.app.get('database');
18 - res.write('<h1>Result form Express Server</h1>'); 17 +
19 - res.write('<div><p>Param E-mail : ' + paramEmail + '</p></div>'); 18 + // 데이터베이스 객체가 초기화된 경우, addUser 함수 호출하여 사용자 추가
20 - res.write('<div><p>Param id : ' + paramId + '</p></div>'); 19 + if (database.db) {
21 - res.write('<div><p>Param password : ' + paramPassword + '</p></div>'); 20 + addUser(database, paramId, paramPassword, paramName, paramEmail, function(err, addedUser) {
22 - res.write("<br><br><a href ='/login.html'>로그인 페이지로 돌아가기</a>"); 21 + // 동일한 id로 추가하려는 경우 에러 발생 - 클라이언트로 에러 전송
23 - res.end(); 22 + if (err) {
23 + console.error('사용자 추가 중 에러 발생 : ' + err.stack);
24 +
25 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
26 + res.write('<h2>사용자 추가 중 에러 발생</h2>');
27 + res.write('<p>' + err.stack + '</p>');
28 + res.end();
29 +
30 + return;
31 + }
32 +
33 + // 결과 객체 있으면 성공 응답 전송
34 + if (addedUser) {
35 + console.dir(addedUser);
36 +
37 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
38 + res.write('<h2>사용자 추가 성공</h2>');
39 + res.write("<br><br><a href='/login'>로그인하기</a>");
40 + res.end();
41 + } else { // 결과 객체가 없으면 실패 응답 전송
42 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
43 + res.write('<h2>사용자 추가 실패</h2>');
44 + res.write("<br><br><a href='/signup'>다시 가입하기</a>");
45 + res.end();
46 + }
47 + });
48 + } else { // 데이터베이스 객체가 초기화되지 않은 경우 실패 응답 전송
49 + res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});
50 + res.write('<h2>데이터베이스 연결 실패</h2>');
51 + res.end();
52 + }
53 +
24 }); 54 });
25 - 55 +//사용자를 등록하는 함수
56 +var addUser = function(database, id, password, name, email, callback) {
57 +
58 + // UserModel 인스턴스 생성
59 + var user = new database.UserModel({"id":id, "password":password, "name":name,"email":email});
60 + // save()로 저장
61 + user.save(function(err) {
62 + if (err) {
63 + callback(err, null);
64 + return;
65 + }
66 +
67 + callback(null, user);
68 +
69 + });
70 +}
26 module.exports = router 71 module.exports = router
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
29 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 29 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
30 <li class="nav-item dropdown"> 30 <li class="nav-item dropdown">
31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
29 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 29 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
30 <li class="nav-item dropdown"> 30 <li class="nav-item dropdown">
31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
225 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 225 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
226 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 226 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
227 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 227 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
228 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 228 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
229 <li class="nav-item dropdown"> 229 <li class="nav-item dropdown">
230 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 230 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
231 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 231 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
31 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 31 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
32 <li class="nav-item dropdown"> 32 <li class="nav-item dropdown">
33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
74 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 74 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
75 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 75 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
76 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 76 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
77 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 77 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
78 <li class="nav-item dropdown"> 78 <li class="nav-item dropdown">
79 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 79 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
80 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 80 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 26 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 27 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 28 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
29 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 29 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
30 <li class="nav-item dropdown"> 30 <li class="nav-item dropdown">
31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 31 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 32 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
32 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 32 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
33 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 33 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
34 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 34 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
35 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 35 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
36 <li class="nav-item dropdown"> 36 <li class="nav-item dropdown">
37 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" 37 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button"
38 data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 38 data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
32 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 32 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
33 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 33 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
34 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 34 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
35 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 35 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
36 <li class="nav-item dropdown"> 36 <li class="nav-item dropdown">
37 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" 37 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button"
38 data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 38 data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
31 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 31 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
32 <li class="nav-item dropdown"> 32 <li class="nav-item dropdown">
33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
...@@ -62,6 +62,10 @@ ...@@ -62,6 +62,10 @@
62 <td><input type="text" name="email"></td> 62 <td><input type="text" name="email"></td>
63 </tr> 63 </tr>
64 <tr> 64 <tr>
65 + <td><label>이름</label></td>
66 + <td><input type="text" name="name"></td>
67 + </tr>
68 + <tr>
65 <td><label>아이디</label></td> 69 <td><label>아이디</label></td>
66 <td><input type="text" name="id"></td> 70 <td><input type="text" name="id"></td>
67 </tr> 71 </tr>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li> 28 <li class="nav-item"><a class="nav-link" href="/menu">휴게소 메뉴</a></li>
29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li> 29 <li class="nav-item"><a class="nav-link" href="/weather">날씨</a></li>
30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li> 30 <li class="nav-item"><a class="nav-link" href="/lpg">LPG</a></li>
31 - <li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li> 31 + <li class="nav-item"><a class="nav-link" href="/post">Board</a></li>
32 <li class="nav-item dropdown"> 32 <li class="nav-item dropdown">
33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a> 33 <a class="nav-link dropdown-toggle" id="navbarDropdownBlog" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Blog</a>
34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog"> 34 <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownBlog">
......