Showing
3 changed files
with
44 additions
and
2 deletions
... | @@ -68,11 +68,12 @@ app.post('/api/users/register', (req,res) => { | ... | @@ -68,11 +68,12 @@ app.post('/api/users/register', (req,res) => { |
68 | 68 | ||
69 | // 로그인 . | 69 | // 로그인 . |
70 | app.post('/api/users/login', (req ,res) => { | 70 | app.post('/api/users/login', (req ,res) => { |
71 | + console.log(req.body) | ||
71 | User.findOne({name : req.body.name}, (err, user) => { | 72 | User.findOne({name : req.body.name}, (err, user) => { |
72 | if (!user) { | 73 | if (!user) { |
73 | return res.json({ | 74 | return res.json({ |
74 | loginSuccess: false, | 75 | loginSuccess: false, |
75 | - message : "이름이 일치하는 사용자가 없습니다 !" | 76 | + message : "이름이 일치하는 사용자가 없습니다 !", |
76 | }) | 77 | }) |
77 | } | 78 | } |
78 | else if (req.body.password === user.password) { | 79 | else if (req.body.password === user.password) { | ... | ... |
... | @@ -5,6 +5,8 @@ | ... | @@ -5,6 +5,8 @@ |
5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
7 | <title>Main Page</title> | 7 | <title>Main Page</title> |
8 | + | ||
9 | + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | ||
8 | </head> | 10 | </head> |
9 | <body> | 11 | <body> |
10 | Main Page | 12 | Main Page |
... | @@ -13,5 +15,12 @@ | ... | @@ -13,5 +15,12 @@ |
13 | </div> | 15 | </div> |
14 | 16 | ||
15 | <script type="text/javascript" src="./main.js"></script> | 17 | <script type="text/javascript" src="./main.js"></script> |
18 | + <div> | ||
19 | + <input id = "name" type = "text" placeholder="이름"> | ||
20 | + <input id = "password" type = "text" placeholder="비밀번호"> | ||
21 | + <button type="submit" id = "button"> | ||
22 | + 로그인 | ||
23 | + </button> | ||
24 | + </div> | ||
16 | </body> | 25 | </body> |
17 | </html> | 26 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -7,4 +7,36 @@ function moveSquartPage() | ... | @@ -7,4 +7,36 @@ function moveSquartPage() |
7 | 7 | ||
8 | const movePage = document.getElementById("moveSquart") | 8 | const movePage = document.getElementById("moveSquart") |
9 | 9 | ||
10 | -movePage.addEventListener('click', moveSquartPage); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
10 | +movePage.addEventListener('click', moveSquartPage); | ||
11 | + | ||
12 | + | ||
13 | +$(document).ready(function(){ | ||
14 | + $('#button').click(function(){ | ||
15 | + let sendName = $('#name').val(); | ||
16 | + let sendPassword = $('#password').val(); | ||
17 | + | ||
18 | + let sendData = { | ||
19 | + "name" : sendName, | ||
20 | + "password" : sendPassword | ||
21 | + } | ||
22 | + | ||
23 | + $.ajax({ | ||
24 | + contentType : "application/json; charset=utf-8", | ||
25 | + type : 'post', | ||
26 | + url : 'api/users/login', | ||
27 | + data : JSON.stringify(sendData), | ||
28 | + dataType : 'JSON', | ||
29 | + | ||
30 | + success : function(datas) { | ||
31 | + if (datas.loginSuccess) | ||
32 | + { | ||
33 | + moveSquartPage() | ||
34 | + } | ||
35 | + else | ||
36 | + { | ||
37 | + alert(datas.message) | ||
38 | + } | ||
39 | + } | ||
40 | + }) | ||
41 | + }) | ||
42 | +}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment