Showing
13 changed files
with
92 additions
and
53 deletions
... | @@ -5,20 +5,19 @@ let cardEnUS=[] | ... | @@ -5,20 +5,19 @@ let cardEnUS=[] |
5 | let cardKoKR=[] | 5 | let cardKoKR=[] |
6 | 6 | ||
7 | 7 | ||
8 | - | 8 | +//카드 덱 ID와 카드 정보를 받아와, 카드별로 dbfId랑 매칭 시킨 후, card 테이블에 추가 |
9 | +//return: 없음 | ||
9 | exports.AddCards=(deckId,cards)=>{ | 10 | exports.AddCards=(deckId,cards)=>{ |
10 | 11 | ||
11 | - fs.readFile('cardskoKR.json',(err,data)=>{ | ||
12 | - if (err) throw err | ||
13 | - cardKoKR=JSON.parse(data) | ||
14 | - }) | ||
15 | - | ||
16 | return new Promise((resolve,reject)=>{ | 12 | return new Promise((resolve,reject)=>{ |
13 | + //전체 카드 읽어 오기 | ||
17 | fs.readFile('cardsenUS.json',(err,data)=>{ | 14 | fs.readFile('cardsenUS.json',(err,data)=>{ |
18 | if (err) throw err | 15 | if (err) throw err |
19 | cardEnUS=JSON.parse(data) | 16 | cardEnUS=JSON.parse(data) |
17 | + //mysql 연결 | ||
20 | mysql.getConnection((err,connection)=>{ | 18 | mysql.getConnection((err,connection)=>{ |
21 | if(err) throw err | 19 | if(err) throw err |
20 | + //카드별로 dbfId 찾기 | ||
22 | for (let i=0;i<cards.length;i++) { | 21 | for (let i=0;i<cards.length;i++) { |
23 | let cardCost = cards[i].cardCost | 22 | let cardCost = cards[i].cardCost |
24 | let cardName = cards[i].cardName | 23 | let cardName = cards[i].cardName |
... | @@ -27,12 +26,13 @@ exports.AddCards=(deckId,cards)=>{ | ... | @@ -27,12 +26,13 @@ exports.AddCards=(deckId,cards)=>{ |
27 | for (let i = 0; i < cardEnUS.length; i++) { | 26 | for (let i = 0; i < cardEnUS.length; i++) { |
28 | if (cardEnUS[i].name === cardName) { | 27 | if (cardEnUS[i].name === cardName) { |
29 | cardId = cardEnUS[i].dbfId | 28 | cardId = cardEnUS[i].dbfId |
29 | + //single quote 처리 | ||
30 | cardName=cardName.replace('\'','\'\'') | 30 | cardName=cardName.replace('\'','\'\'') |
31 | break | 31 | break |
32 | } | 32 | } |
33 | } | 33 | } |
34 | + //카드 추가 | ||
34 | connection.query(`insert into card (deckId,cardId,cardCost,cardName,cardNum) values (\'${deckId}\',\'${cardId}\',\'${cardCost}\',\'${cardName}\',\'${cardNum}\')`, (err, results, fields) => { | 35 | connection.query(`insert into card (deckId,cardId,cardCost,cardName,cardNum) values (\'${deckId}\',\'${cardId}\',\'${cardCost}\',\'${cardName}\',\'${cardNum}\')`, (err, results, fields) => { |
35 | - // | ||
36 | if (err) throw err | 36 | if (err) throw err |
37 | }) | 37 | }) |
38 | } | 38 | } | ... | ... |
1 | const mysql=require('../../database/mysql') | 1 | const mysql=require('../../database/mysql') |
2 | 2 | ||
3 | +//덱 ID를 바탕으로 해당 덱에 속해있는 모든 카드 반환 | ||
4 | +//return: json array | ||
3 | exports.GetCardId=(deckId)=>{ | 5 | exports.GetCardId=(deckId)=>{ |
4 | return new Promise((resolve,reject)=>{ | 6 | return new Promise((resolve,reject)=>{ |
5 | mysql.getConnection((err,connection)=>{ | 7 | mysql.getConnection((err,connection)=>{ | ... | ... |
... | @@ -5,9 +5,13 @@ const fs=require('fs') | ... | @@ -5,9 +5,13 @@ const fs=require('fs') |
5 | const ejs=require('ejs') | 5 | const ejs=require('ejs') |
6 | let globalMulligan | 6 | let globalMulligan |
7 | let globalDecks | 7 | let globalDecks |
8 | + | ||
9 | +//result.ejs 렌더링 전 수행됨. 현재 덱 ID와 상대 직업을 가지고 상대의 점유율 상위 3개 덱과, 내 덱의 추천 멀리건 출력 | ||
10 | +//return : 렌더링 된 result.ejs | ||
8 | exports.GetResult=(req,res)=>{ | 11 | exports.GetResult=(req,res)=>{ |
9 | const deckId=req.session.deckId | 12 | const deckId=req.session.deckId |
10 | const opponentClass=req.session.opponentClass | 13 | const opponentClass=req.session.opponentClass |
14 | + //덱 ID와 상대 직업 정보 체크 | ||
11 | const DataCheck=()=>{ | 15 | const DataCheck=()=>{ |
12 | return new Promise((resolve,reject)=>{ | 16 | return new Promise((resolve,reject)=>{ |
13 | if (!deckId || !opponentClass){ | 17 | if (!deckId || !opponentClass){ |
... | @@ -19,13 +23,15 @@ exports.GetResult=(req,res)=>{ | ... | @@ -19,13 +23,15 @@ exports.GetResult=(req,res)=>{ |
19 | resolve() | 23 | resolve() |
20 | }) | 24 | }) |
21 | } | 25 | } |
26 | + //현재 덱ID를 바탕으로 카드정보 가져오기 | ||
22 | const GetCardId=()=>{ | 27 | const GetCardId=()=>{ |
23 | return getCardId.GetCardId(deckId) | 28 | return getCardId.GetCardId(deckId) |
24 | } | 29 | } |
25 | - | 30 | + //가져온 카드 정보를 바탕으로, hsreplay.net에서, 덱 검색하기, 검색한 결과의 html을 반환 |
26 | const GetMulContent=(cardIds)=>{ | 31 | const GetMulContent=(cardIds)=>{ |
27 | cardIds=JSON.stringify(cardIds) | 32 | cardIds=JSON.stringify(cardIds) |
28 | cardIds=JSON.parse(cardIds) | 33 | cardIds=JSON.parse(cardIds) |
34 | + //검색을 위한 쿼리스트링 | ||
29 | let idInQuery=cardIds[0].cardId | 35 | let idInQuery=cardIds[0].cardId |
30 | for(let i=1;i<cardIds.length ;i++){ | 36 | for(let i=1;i<cardIds.length ;i++){ |
31 | idInQuery+= '%2C'+cardIds[i].cardId | 37 | idInQuery+= '%2C'+cardIds[i].cardId |
... | @@ -50,7 +56,7 @@ exports.GetResult=(req,res)=>{ | ... | @@ -50,7 +56,7 @@ exports.GetResult=(req,res)=>{ |
50 | resolve(asyncFunc()) | 56 | resolve(asyncFunc()) |
51 | }) | 57 | }) |
52 | } | 58 | } |
53 | - | 59 | + //검색한 html을 가지고, 검색결과로 부터 덱의 url 파싱 |
54 | const GetDeckHref=(content)=>{ | 60 | const GetDeckHref=(content)=>{ |
55 | return new Promise((resolve,reject)=>{ | 61 | return new Promise((resolve,reject)=>{ |
56 | const $=cheerio.load(content) | 62 | const $=cheerio.load(content) |
... | @@ -60,6 +66,7 @@ exports.GetResult=(req,res)=>{ | ... | @@ -60,6 +66,7 @@ exports.GetResult=(req,res)=>{ |
60 | resolve(deckHref) | 66 | resolve(deckHref) |
61 | }) | 67 | }) |
62 | } | 68 | } |
69 | + //덱의 url을 이용, 해당 덱의 정보를 나타내는 페이지 불러온 후 html로 반환 | ||
63 | const GetDeckContent=(href)=>{ | 70 | const GetDeckContent=(href)=>{ |
64 | return new Promise((resolve,reject)=>{ | 71 | return new Promise((resolve,reject)=>{ |
65 | const asyncFunc=async ()=>{ | 72 | const asyncFunc=async ()=>{ |
... | @@ -81,6 +88,7 @@ exports.GetResult=(req,res)=>{ | ... | @@ -81,6 +88,7 @@ exports.GetResult=(req,res)=>{ |
81 | resolve(asyncFunc()) | 88 | resolve(asyncFunc()) |
82 | }) | 89 | }) |
83 | } | 90 | } |
91 | + //받아온 html에서 카드 이름과 멀리건 부분 추출 | ||
84 | const GetMulligan=(content)=>{ | 92 | const GetMulligan=(content)=>{ |
85 | return new Promise((resolve,reject)=>{ | 93 | return new Promise((resolve,reject)=>{ |
86 | const $=cheerio.load(content) | 94 | const $=cheerio.load(content) |
... | @@ -90,17 +98,20 @@ exports.GetResult=(req,res)=>{ | ... | @@ -90,17 +98,20 @@ exports.GetResult=(req,res)=>{ |
90 | for(let i=0;i<cardNames.length;i++){ | 98 | for(let i=0;i<cardNames.length;i++){ |
91 | let cardName=$(cardNames[i]).text() | 99 | let cardName=$(cardNames[i]).text() |
92 | let cardWinRate=$(cardWinRates[6*i]).text() | 100 | let cardWinRate=$(cardWinRates[6*i]).text() |
101 | + //문자 삭제하고, 멀리건의 승률이 숫자로만 나타나도록 | ||
93 | cardWinRate=cardWinRate.replace('▼','') | 102 | cardWinRate=cardWinRate.replace('▼','') |
94 | cardWinRate=cardWinRate.replace('▲','') | 103 | cardWinRate=cardWinRate.replace('▲','') |
95 | cardWinRate=cardWinRate.replace('%','') | 104 | cardWinRate=cardWinRate.replace('%','') |
96 | cards.push({cardName:cardName,cardWinRate:cardWinRate}) | 105 | cards.push({cardName:cardName,cardWinRate:cardWinRate}) |
97 | } | 106 | } |
107 | + //카드를 멀리건 승률 순서대로 정렬 | ||
98 | cards.sort((a,b)=>{ | 108 | cards.sort((a,b)=>{ |
99 | return a.cardWinRate<b.cardWinRate ? 1:-1 | 109 | return a.cardWinRate<b.cardWinRate ? 1:-1 |
100 | }) | 110 | }) |
101 | resolve(cards) | 111 | resolve(cards) |
102 | }) | 112 | }) |
103 | } | 113 | } |
114 | + //상대 직업을 가지고 hsreplay.net에서 검색, html로 반환 | ||
104 | const GetOppContent=()=>{ | 115 | const GetOppContent=()=>{ |
105 | return new Promise((resolve,reject)=>{ | 116 | return new Promise((resolve,reject)=>{ |
106 | const asyncFunc=async ()=>{ | 117 | const asyncFunc=async ()=>{ |
... | @@ -122,7 +133,7 @@ exports.GetResult=(req,res)=>{ | ... | @@ -122,7 +133,7 @@ exports.GetResult=(req,res)=>{ |
122 | resolve(asyncFunc()) | 133 | resolve(asyncFunc()) |
123 | }) | 134 | }) |
124 | } | 135 | } |
125 | - | 136 | + //받아온 html로부터 덱의 이름, 게임 횟수 추출 |
126 | const GetDeckInfo=(content)=>{ | 137 | const GetDeckInfo=(content)=>{ |
127 | return new Promise((resolve,reject)=>{ | 138 | return new Promise((resolve,reject)=>{ |
128 | const $=cheerio.load(content) | 139 | const $=cheerio.load(content) | ... | ... |
1 | const mysql=require('../../database/mysql') | 1 | const mysql=require('../../database/mysql') |
2 | - | 2 | +//덱 추가 |
3 | +//return: 없음 | ||
3 | exports.AddDeck=(deckOwner,deckTitle,deckCode)=>{ | 4 | exports.AddDeck=(deckOwner,deckTitle,deckCode)=>{ |
4 | return new Promise((resolve,reject)=> { | 5 | return new Promise((resolve,reject)=> { |
5 | mysql.getConnection((err, connection) => { | 6 | mysql.getConnection((err, connection) => { |
... | @@ -7,7 +8,7 @@ exports.AddDeck=(deckOwner,deckTitle,deckCode)=>{ | ... | @@ -7,7 +8,7 @@ exports.AddDeck=(deckOwner,deckTitle,deckCode)=>{ |
7 | connection.query(`insert into deck (deckOwner,deckTitle,deckCode) values (\'${deckOwner}\',\'${deckTitle}\',\'${deckCode}\');`, (err, results, fields) => { | 8 | connection.query(`insert into deck (deckOwner,deckTitle,deckCode) values (\'${deckOwner}\',\'${deckTitle}\',\'${deckCode}\');`, (err, results, fields) => { |
8 | if (err) throw err | 9 | if (err) throw err |
9 | connection.release() | 10 | connection.release() |
10 | - resolve(results) | 11 | + resolve() |
11 | }) | 12 | }) |
12 | }) | 13 | }) |
13 | }) | 14 | }) | ... | ... |
... | @@ -2,6 +2,8 @@ const request=require('request') | ... | @@ -2,6 +2,8 @@ const request=require('request') |
2 | const iconv=require('iconv-lite') | 2 | const iconv=require('iconv-lite') |
3 | const charset=require('charset') | 3 | const charset=require('charset') |
4 | 4 | ||
5 | +//덱 추가시 deck.codes로부터 덱 코드가 의미하는 덱 정보 페이지 크롤링 | ||
6 | +//return: html | ||
5 | exports.Crawl=(deckCode)=>{ | 7 | exports.Crawl=(deckCode)=>{ |
6 | return new Promise((resolve,reject)=>{ | 8 | return new Promise((resolve,reject)=>{ |
7 | request({ | 9 | request({ | ... | ... |
1 | const mysql=require('../../database/mysql') | 1 | const mysql=require('../../database/mysql') |
2 | 2 | ||
3 | +//덱의 주인과 덱 이름을 가지고 DeckId값 반환 | ||
4 | +//return: deckId | ||
3 | exports.GetDeckId=(deckOwner,deckTitle)=>{ | 5 | exports.GetDeckId=(deckOwner,deckTitle)=>{ |
4 | return new Promise((resolve,reject)=>{ | 6 | return new Promise((resolve,reject)=>{ |
5 | mysql.getConnection((err,connection)=>{ | 7 | mysql.getConnection((err,connection)=>{ |
6 | if (err) throw err | 8 | if (err) throw err |
7 | connection.query(`select * from deck where deckOwner=\'${deckOwner}\' and deckTitle=\'${deckTitle}\'`,(err,results,field)=>{ | 9 | connection.query(`select * from deck where deckOwner=\'${deckOwner}\' and deckTitle=\'${deckTitle}\'`,(err,results,field)=>{ |
8 | if (err) throw err | 10 | if (err) throw err |
9 | - //console.log('result in getDeckId'+results[0]) | ||
10 | connection.release() | 11 | connection.release() |
11 | resolve(results[0].id) | 12 | resolve(results[0].id) |
12 | }) | 13 | }) | ... | ... |
... | @@ -4,13 +4,16 @@ const addCards=require('../card/addCards') | ... | @@ -4,13 +4,16 @@ const addCards=require('../card/addCards') |
4 | const addDeck=require('./addDeck') | 4 | const addDeck=require('./addDeck') |
5 | const getDeckId=require('./getDeckId') | 5 | const getDeckId=require('./getDeckId') |
6 | 6 | ||
7 | +//새로운 덱 추가 | ||
8 | +//return : response status code | ||
7 | exports.NewDeck=(req,res)=>{ | 9 | exports.NewDeck=(req,res)=>{ |
8 | const deckOwner=req.session.sid | 10 | const deckOwner=req.session.sid |
11 | + //덱 이름이 주어지지 않았다면 시간으로 저장 | ||
9 | const deckTitle=req.body.deckTitle || new Date() | 12 | const deckTitle=req.body.deckTitle || new Date() |
10 | let deckCode=req.body.deckCode | 13 | let deckCode=req.body.deckCode |
11 | let cards=[] | 14 | let cards=[] |
12 | 15 | ||
13 | - | 16 | + //덱 코드가 입력 되었는지 체크 |
14 | const DataCheck=()=>{ | 17 | const DataCheck=()=>{ |
15 | return new Promise((resolve,reject)=>{ | 18 | return new Promise((resolve,reject)=>{ |
16 | if(!deckCode){ | 19 | if(!deckCode){ |
... | @@ -22,32 +25,39 @@ exports.NewDeck=(req,res)=>{ | ... | @@ -22,32 +25,39 @@ exports.NewDeck=(req,res)=>{ |
22 | else resolve() | 25 | else resolve() |
23 | }) | 26 | }) |
24 | } | 27 | } |
28 | + //덱 코드를 가지고 deck.codes 크롤링, 성공시 html을 reolve해줌 | ||
25 | const CrawlPage=()=>{ | 29 | const CrawlPage=()=>{ |
26 | return crawler.Crawl(deckCode) | 30 | return crawler.Crawl(deckCode) |
27 | } | 31 | } |
32 | + //받아온 html로부터 덱을 구성하는 카드정보 추출 | ||
28 | const DeckCrawl=(result)=>{ | 33 | const DeckCrawl=(result)=>{ |
29 | const $=cheerio.load(result) | 34 | const $=cheerio.load(result) |
35 | + //카드의 코스트 배열 | ||
30 | let cardCosts=$('div.hs-tile-info').children('.hs-tile-info-left.mdc-list-item__start-detail') | 36 | let cardCosts=$('div.hs-tile-info').children('.hs-tile-info-left.mdc-list-item__start-detail') |
37 | + //카드의 이름 배열 | ||
31 | let cardNames=$('div.hs-tile-info').find('span').find('span') | 38 | let cardNames=$('div.hs-tile-info').find('span').find('span') |
39 | + //카드가 들어간 개수 배열 | ||
32 | let cardNums=$('div.hs-tile-info').children('.hs-tile-info-right.mdc-list-item__end-detail') | 40 | let cardNums=$('div.hs-tile-info').children('.hs-tile-info-right.mdc-list-item__end-detail') |
33 | 41 | ||
34 | for(let i=0;i<cardNames.length;i++) { | 42 | for(let i=0;i<cardNames.length;i++) { |
35 | let cardCost=$(cardCosts[i]).text() | 43 | let cardCost=$(cardCosts[i]).text() |
36 | let cardName=$(cardNames[i]).text() | 44 | let cardName=$(cardNames[i]).text() |
37 | let cardNum=$(cardNums[i]).text() | 45 | let cardNum=$(cardNums[i]).text() |
46 | + //카드의 개수가 1개라면, 웹에서는 카드의 개수를 공백으로 표현함. | ||
47 | + //카드의 개수가 1개가 아니라 2개여도 양 옆 공백이 상당하기 때문에, | ||
48 | + //trim()을 우선 사용하고, 결과에 대해서 문자열을 다듬음 | ||
38 | if(cardNum.trim()==='') | 49 | if(cardNum.trim()==='') |
39 | cardNum='1' | 50 | cardNum='1' |
40 | else | 51 | else |
41 | cardNum=cardNum.trim() | 52 | cardNum=cardNum.trim() |
42 | cards.push({cardCost: cardCost, cardName: cardName, cardNum: cardNum}) | 53 | cards.push({cardCost: cardCost, cardName: cardName, cardNum: cardNum}) |
43 | } | 54 | } |
44 | - //console.log(cards) | ||
45 | } | 55 | } |
46 | - | 56 | + //deck 테이블에 새로운 row 추가 |
47 | const AddDeck=()=>{ | 57 | const AddDeck=()=>{ |
48 | const asyncAddDeck=async ()=>{ | 58 | const asyncAddDeck=async ()=>{ |
49 | try{ | 59 | try{ |
50 | - const results=await addDeck.AddDeck(deckOwner,deckTitle,deckCode) | 60 | + await addDeck.AddDeck(deckOwner,deckTitle,deckCode) |
51 | } | 61 | } |
52 | catch (err) { | 62 | catch (err) { |
53 | throw err | 63 | throw err |
... | @@ -55,7 +65,7 @@ exports.NewDeck=(req,res)=>{ | ... | @@ -55,7 +65,7 @@ exports.NewDeck=(req,res)=>{ |
55 | } | 65 | } |
56 | return asyncAddDeck() | 66 | return asyncAddDeck() |
57 | } | 67 | } |
58 | - | 68 | + //카드를 추가하기 위해 방금 추가한 덱 id를 가져옴 |
59 | const GetId=()=>{ | 69 | const GetId=()=>{ |
60 | const asyncGetDeckId=async ()=>{ | 70 | const asyncGetDeckId=async ()=>{ |
61 | try{ | 71 | try{ |
... | @@ -68,6 +78,7 @@ exports.NewDeck=(req,res)=>{ | ... | @@ -68,6 +78,7 @@ exports.NewDeck=(req,res)=>{ |
68 | } | 78 | } |
69 | return asyncGetDeckId() | 79 | return asyncGetDeckId() |
70 | } | 80 | } |
81 | + //card 테이블에 새로운 여러개의 row 추가 | ||
71 | const AddCards=(deckId)=>{ | 82 | const AddCards=(deckId)=>{ |
72 | return addCards.AddCards(deckId,cards) | 83 | return addCards.AddCards(deckId,cards) |
73 | } | 84 | } | ... | ... |
1 | const mysql=require('../../database/mysql') | 1 | const mysql=require('../../database/mysql') |
2 | - | 2 | +//사용자의 아이디를 가지고 유저 검색, |
3 | +//return: 사용자가 있으면, 사용자 정보 | ||
4 | +// 사용자가 없으면, 없음 | ||
3 | exports.findById=(userId)=>{ | 5 | exports.findById=(userId)=>{ |
4 | return new Promise((resolve,reject)=>{ | 6 | return new Promise((resolve,reject)=>{ |
5 | mysql.getConnection((err,connection)=>{ | 7 | mysql.getConnection((err,connection)=>{ | ... | ... |
1 | const findById=require('./findById') | 1 | const findById=require('./findById') |
2 | const bcrypt=require('bcrypt-nodejs') | 2 | const bcrypt=require('bcrypt-nodejs') |
3 | 3 | ||
4 | +//입력한 아이디와 비밀번호를 가지고 로그인 | ||
4 | exports.Login=(req,res)=>{ | 5 | exports.Login=(req,res)=>{ |
5 | const userId=req.body.userId | 6 | const userId=req.body.userId |
6 | const password=req.body.password | 7 | const password=req.body.password |
7 | - | 8 | + //아이디와 비밀번호가 존재 하는지 체크 |
8 | const DataCheck=()=>{ | 9 | const DataCheck=()=>{ |
9 | return new Promise((resolve,reject)=>{ | 10 | return new Promise((resolve,reject)=>{ |
10 | if(!userId || !password){ | 11 | if(!userId || !password){ |
... | @@ -16,7 +17,7 @@ exports.Login=(req,res)=>{ | ... | @@ -16,7 +17,7 @@ exports.Login=(req,res)=>{ |
16 | else resolve() | 17 | else resolve() |
17 | }) | 18 | }) |
18 | } | 19 | } |
19 | - | 20 | + //이 아이디로 등록된 사용자가 있는 지 체크 |
20 | const IdCheck=()=>{ | 21 | const IdCheck=()=>{ |
21 | let user={} | 22 | let user={} |
22 | const findUser= async ()=>{ | 23 | const findUser= async ()=>{ |
... | @@ -30,7 +31,7 @@ exports.Login=(req,res)=>{ | ... | @@ -30,7 +31,7 @@ exports.Login=(req,res)=>{ |
30 | } | 31 | } |
31 | return findUser() | 32 | return findUser() |
32 | } | 33 | } |
33 | - | 34 | + //해당 유저의 비밀번호와 입력된 비밀번호가 같은 지 체크 |
34 | const PwCheck=(user)=>{ | 35 | const PwCheck=(user)=>{ |
35 | if (user[0]==null){ | 36 | if (user[0]==null){ |
36 | return Promise.reject({ | 37 | return Promise.reject({ |
... | @@ -38,6 +39,7 @@ exports.Login=(req,res)=>{ | ... | @@ -38,6 +39,7 @@ exports.Login=(req,res)=>{ |
38 | message:'id wrong' | 39 | message:'id wrong' |
39 | }) | 40 | }) |
40 | } | 41 | } |
42 | + //암호화 모듈을 사용했기 때문에, 서로 비교하는 함수를 써야함 | ||
41 | if(bcrypt.compareSync(password,user[0].password)){ | 43 | if(bcrypt.compareSync(password,user[0].password)){ |
42 | req.session.sid=userId | 44 | req.session.sid=userId |
43 | req.session.save(()=>{ | 45 | req.session.save(()=>{ | ... | ... |
1 | const findById=require('./findById') | 1 | const findById=require('./findById') |
2 | const mysql=require('../../database/mysql') | 2 | const mysql=require('../../database/mysql') |
3 | const bcrypt=require('bcrypt-nodejs') | 3 | const bcrypt=require('bcrypt-nodejs') |
4 | - | 4 | +//입력된 아이디와 비밀번호를 가지고 회원가입. |
5 | +//비밀번호 확인은 프론트 단에서 이루어 졌음. | ||
6 | +//return: response status code | ||
5 | exports.SignUp=(req,res)=>{ | 7 | exports.SignUp=(req,res)=>{ |
6 | const userId=req.body.userId | 8 | const userId=req.body.userId |
7 | const password=req.body.password | 9 | const password=req.body.password |
10 | + //아이디와 비밀번호가 존재하는 지 체크 | ||
8 | const DataCheck=()=>{ | 11 | const DataCheck=()=>{ |
9 | return new Promise((resolve,reject)=>{ | 12 | return new Promise((resolve,reject)=>{ |
10 | if(!userId || !password){ | 13 | if(!userId || !password){ |
... | @@ -16,6 +19,7 @@ exports.SignUp=(req,res)=>{ | ... | @@ -16,6 +19,7 @@ exports.SignUp=(req,res)=>{ |
16 | else resolve() | 19 | else resolve() |
17 | }) | 20 | }) |
18 | } | 21 | } |
22 | + //해당 아이디로 등록한 회원이 있는 지 체크 | ||
19 | const UserCheck=()=>{ | 23 | const UserCheck=()=>{ |
20 | let user={} | 24 | let user={} |
21 | const findUser=async ()=>{ | 25 | const findUser=async ()=>{ |
... | @@ -29,7 +33,7 @@ exports.SignUp=(req,res)=>{ | ... | @@ -29,7 +33,7 @@ exports.SignUp=(req,res)=>{ |
29 | } | 33 | } |
30 | return findUser() | 34 | return findUser() |
31 | } | 35 | } |
32 | - | 36 | + //아이디가 중복되지 않았다면 회원가입 진행 |
33 | const SignUp=(user)=>{ | 37 | const SignUp=(user)=>{ |
34 | if(user[0]!=null){ | 38 | if(user[0]!=null){ |
35 | return Promise.reject({ | 39 | return Promise.reject({ |
... | @@ -37,6 +41,7 @@ exports.SignUp=(req,res)=>{ | ... | @@ -37,6 +41,7 @@ exports.SignUp=(req,res)=>{ |
37 | message:'User Already Exists' | 41 | message:'User Already Exists' |
38 | }) | 42 | }) |
39 | } | 43 | } |
44 | + //비밀번호는 암호화 하여 데이터베이스에 저장 | ||
40 | const hash=bcrypt.hashSync(password,bcrypt.genSaltSync(10),null) | 45 | const hash=bcrypt.hashSync(password,bcrypt.genSaltSync(10),null) |
41 | mysql.getConnection((err,connection)=>{ | 46 | mysql.getConnection((err,connection)=>{ |
42 | if(err) throw err | 47 | if(err) throw err | ... | ... |
... | @@ -45,7 +45,7 @@ | ... | @@ -45,7 +45,7 @@ |
45 | <span class="icon-bar"></span> | 45 | <span class="icon-bar"></span> |
46 | <span class="icon-bar"></span> | 46 | <span class="icon-bar"></span> |
47 | </button> | 47 | </button> |
48 | - <a class="navbar-brand" href="/">Who Are You?</a> | 48 | + <a class="navbar-brand" href="/main">Who Are You?</a> |
49 | </div> | 49 | </div> |
50 | <div class="navbar-collapse collapse" id="navbar" aria-expanded="false" style="height: 1px;"> | 50 | <div class="navbar-collapse collapse" id="navbar" aria-expanded="false" style="height: 1px;"> |
51 | <ul class="nav navbar-nav"> | 51 | <ul class="nav navbar-nav"> | ... | ... |
... | @@ -18,32 +18,6 @@ | ... | @@ -18,32 +18,6 @@ |
18 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | 18 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
19 | <script> | 19 | <script> |
20 | $(document).ready(function(){ | 20 | $(document).ready(function(){ |
21 | - let mulligan,opponentDecks | ||
22 | - $.ajax({ | ||
23 | - type:'GET', | ||
24 | - url:'/api/card/getmulligan', | ||
25 | - success:function(result){ | ||
26 | - mulligan=result | ||
27 | - $('#yourMulligan').add('<ul>') | ||
28 | - for(let i=0;i<mulligan.length;i++){ | ||
29 | - $('#yourMulligan').add(`<li><h4>카드 이름:${mulligan[i]['cardName']}</h4><br><h5>멀리건 승률:${mulligan[i]['cardWinRate']}</h5></li>`) | ||
30 | - } | ||
31 | - $('#yourMulligan').add('</ul>') | ||
32 | - } | ||
33 | - }) | ||
34 | - $.ajax({ | ||
35 | - type:'GET', | ||
36 | - url:'/api/card/getopponent', | ||
37 | - success:function(result){ | ||
38 | - opponentDecks=result | ||
39 | - $('#opponentDecks').add('<ul>') | ||
40 | - for(let i=0;i<opponentDecks.length;i++){ | ||
41 | - $('#opponentDecks').add(`<li><h4>덱 이름:${opponentDecks[i]['deckTitle']}</h4><br><h5>30일간 플레이 수:${opponentDecks[i]['deckGame']}</h5></li>`) | ||
42 | - } | ||
43 | - $('#opponentDecks').add('</ul>') | ||
44 | - } | ||
45 | - }) | ||
46 | - | ||
47 | $('#logoutButton').click(function(){ | 21 | $('#logoutButton').click(function(){ |
48 | $.ajax({ | 22 | $.ajax({ |
49 | type:'POST', | 23 | type:'POST', |
... | @@ -91,11 +65,37 @@ | ... | @@ -91,11 +65,37 @@ |
91 | <br> | 65 | <br> |
92 | <br> | 66 | <br> |
93 | <h3 class="form-signin-heading">상대편의 주요 덱</h3> | 67 | <h3 class="form-signin-heading">상대편의 주요 덱</h3> |
94 | - <div id="opponentDecks"></div> | 68 | + <div id="opponentDecks"> |
69 | + <table class="table" style="text-align: center;"> | ||
70 | + <thead> | ||
71 | + <td>덱 이름</td> | ||
72 | + <td>플레이 수</td> | ||
73 | + </thead> | ||
74 | + <tbody> | ||
75 | + <tr> | ||
76 | + <td><a class="list-group-item">덱이름1</a></td> | ||
77 | + <td><a class="list-group-item">10000</a></td> | ||
78 | + </tr> | ||
79 | + </tbody> | ||
80 | + </table> | ||
81 | + </div> | ||
95 | <br> | 82 | <br> |
96 | <br> | 83 | <br> |
97 | <h3 class="form-signin-heading">내 덱의 추천 멀리건</h3> | 84 | <h3 class="form-signin-heading">내 덱의 추천 멀리건</h3> |
98 | - <div id="yourMulligan"></div> | 85 | + <div id="yourMulligan"> |
86 | + <table class="table" style="text-align: center;"> | ||
87 | + <thead> | ||
88 | + <td>카드 이름</td> | ||
89 | + <td>멀리건 승률</td> | ||
90 | + </thead> | ||
91 | + <tbody> | ||
92 | + <tr> | ||
93 | + <td><a class="list-group-item">카드이름1</a></td> | ||
94 | + <td><a class="list-group-item">59.8</a></td> | ||
95 | + </tr> | ||
96 | + </tbody> | ||
97 | + </table> | ||
98 | + </div> | ||
99 | <br> | 99 | <br> |
100 | <br> | 100 | <br> |
101 | <div class="row"> | 101 | <div class="row"> | ... | ... |
-
Please register or login to post a comment