-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from wave-lab/feature_yj
[Update signup]
- Loading branch information
Showing
6 changed files
with
193 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const pool = require('../../module/pool.js'); | ||
const nodemailer = require('nodemailer'); | ||
const smtpPool = require('nodemailer-smtp-pool'); | ||
|
||
const returnCode = require('../../model/returnCode'); | ||
const returnMessage = require('../../../config/returnMessage'); | ||
const responseUtil = require('../../module/responseUtil'); | ||
|
||
//인증번호 값 | ||
const rand = Math.floor(Math.random() * 1000000)+100000; | ||
|
||
//유효한 email인지 확인 | ||
router.get('/', async (req, res, next) => { | ||
const selectEmailQuery = 'SELECT email FROM user WHERE email = ?'; | ||
const selectEmailResult = await pool.queryParam_Arr(selectEmailQuery, req.body.email); | ||
|
||
if(selectEmailResult[0] == null){ | ||
console.log('이메일 일치 없음'); | ||
|
||
const config = { | ||
mailer: { | ||
service: 'Gmail', | ||
host: 'localhost', | ||
port: '465', | ||
user: '[email protected]', | ||
password: 'k1207417', | ||
} | ||
}; | ||
|
||
const from = 'WAVE'; | ||
const to = req.body.email; | ||
const subject = 'WAVE 회원가입 인증 메일입니다'; | ||
const html = '<p>인증번호는 '+ rand + ' 입니다.\n 인증번호 창에 입력해주세요.'; | ||
|
||
const mailOptions = { | ||
from, | ||
to, | ||
subject, | ||
html | ||
}; | ||
|
||
const transporter = nodemailer.createTransport(smtpPool({ | ||
service: config.mailer.service, | ||
host: config.mailer.host, | ||
port: config.mailer.port, | ||
auth: { | ||
user: config.mailer.user, | ||
pass: config.mailer.password, | ||
}, | ||
tls: { | ||
rejectUnauthorize: false, | ||
}, | ||
maxConnections: 5, | ||
maxMessages: 10, | ||
})); | ||
|
||
transporter.sendMail(mailOptions, (err, res) => { | ||
if (err) { | ||
console.log('failed... => ', err); | ||
res.status(200).send(responseUtil.successFalse(returnCode.BAD_REQUEST, returnMessage.SEND_EMAIL_FAIL)); | ||
} else { | ||
console.log('succeed... => ', res); | ||
res.status(200).send(responseUtil.successTrue(returnCode.OK, returnMessage.SEND_EMAIL)); | ||
} | ||
transporter.close(); | ||
}); | ||
res.status(200).send(responseUtil.successTrue(returnCode.OK, returnMessage.EMAIL_CHECK_SUCCESS)); | ||
}else{ | ||
console.log('중복 이메일 존재'); | ||
res.status(200).send(responseUtil.successFalse(returnCode.DB_ERROR, returnMessage.DUPLICATED_EMAIL_FAIL)); | ||
} | ||
}); | ||
|
||
//인증번호 확인 | ||
router.get('/authentication', async(req, res, next) =>{ | ||
const user_rand = String(req.body.code); | ||
if(user_rand == rand){ | ||
console.log('인증 성공'); | ||
res.status(200).send(responseUtil.successTrue(returnCode.OK, returnMessage.AUTHENTICATION_SAME)); | ||
}else{ | ||
console.log('인증 실패'); | ||
res.status(200).send(responseUtil.successFalse(returnCode.BAD_REQUEST, returnMessage.AUTHENTICATION_FALSE)); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const pool = require('../../module/pool.js'); | ||
|
||
const returnCode = require('../../model/returnCode'); | ||
const returnMessage = require('../../../config/returnMessage'); | ||
const responseUtil = require('../../module/responseUtil'); | ||
|
||
//nickname 중복 체크 | ||
router.get('/', async (req, res, next) => { | ||
const selectNicknameQuery = 'SELECT nickname FROM user WHERE nickname = ?'; | ||
const selectNicknameResult = await pool.queryParam_Arr(selectNicknameQuery, req.body.nickname); | ||
|
||
if(selectNicknameResult[0] == null){ // 닉네임 중복이 없을 때 | ||
console.log('닉네임 사용 가능'); | ||
res.status(200).send(responseUtil.successTrue(returnCode.OK, returnMessage.NICKNAME_CHECK_SUCCESS)); | ||
}else{ // 닉네임이 중복될 때 | ||
console.log('닉네임 중복'); | ||
res.status(200).send(responseUtil.successFalse(returnCode.DB_ERROR, returnMessage.DUPLICATED_NICKNAME_FAIL)); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,84 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const db = require('../../module/pool.js'); | ||
const nodemailer = require('nodemailer'); | ||
const smtpPool = require('nodemailer-smtp-pool'); | ||
const hash = require('../../../config/hashKey'); | ||
//var smtpTransport = require('nodemailer-smtp-transport'); | ||
|
||
const pool = require('../../module/pool.js'); | ||
const hash = require('../../../config/hashKey').key; | ||
const crypto = require('crypto-promise'); | ||
const upload = require('../../../config/multer'); | ||
|
||
const returnCode = require('../../model/returnCode'); | ||
const returnMessage = require('../../../config/returnMessage'); | ||
const responseUtil = require('../../module/responseUtil'); | ||
|
||
//인증번호 값 | ||
const rand = Math.floor(Math.random() * 1000000)+100000; | ||
//salt 값 | ||
const hashKey = hash.key; | ||
|
||
//회원가입 | ||
router.post('/', async (req, res, next) => { | ||
|
||
const QUERY = 'insert into USER set ?'; | ||
let newUser = signup.new(req.body); | ||
let inserted = await db.execute2(QUERY, newUser); | ||
|
||
if (inserted == undefined) { | ||
res.status(405).send({ | ||
message: 'please check email' | ||
}); | ||
} else { | ||
await myIntro.create({ | ||
user_idx: inserted.insertId, | ||
intro_contents: "", | ||
intro_img_url: [] | ||
}); | ||
res.status(201).send({ | ||
message: "success" | ||
}); | ||
} | ||
}); | ||
const playlist = require('../../model/schema/playlist'); | ||
const myPlaylist = require('../../model/schema/myPlaylist'); | ||
|
||
//회원가입 | ||
router.post('/', async (req, res, next) => { | ||
const selectEmailQuery = 'SELECT nickname FROM user WHERE nickname = ?' | ||
const selectEmailResult = await db.queryParam_Arr(selectEmailQuery, req.body.nickname); | ||
const signupQuery = 'INSERT INTO user (email, password, nickname, profileImg, comment) VALUES (?, ?, ?, ?, ?)'; | ||
|
||
if (selectEmailResult[0] == null) { // 해당 이메일로 가입한 유저가 없을 시 | ||
console.log("일치 없음"); | ||
const buf = await crypto.randomBytes(64); | ||
const salt = buf.toString('base64'); | ||
const hashedPw = await crypto.pbkdf2(req.body.user_pw.toString(), salt, 1000, 32, 'SHA512'); | ||
router.post('/', upload.single('profileImg'), async (req, res, next) => { | ||
const hashedPw = await crypto.pbkdf2(req.body.password.toString('utf8'), hash, 1000, 32, 'SHA512'); | ||
const profileImg = req.file.location; | ||
|
||
const signupResult = await db.queryParam_Arr(signupQuery, [req.body.user_id, req.body.user_name, hashedPw.toString('base64'), salt]); | ||
if (!signupResult) { | ||
res.status(200).send(defaultRes.successFalse(statusCode.DB_ERROR, resMessage.SIGNUP_FAIL)); | ||
} else { //쿼리문이 성공했을 때 | ||
res.status(200).send(defaultRes.successTrue(statusCode.OK, resMessage.SIGNUP_SUCCESS)); | ||
} | ||
} else {// 이미 존재 | ||
console.log("이미 존재"); | ||
res.status(200).send(responseUtil.successFalse(returnCode.OK, returnMessage.DUPLICATED_ID_FAIL)); | ||
} | ||
const signupQuery = 'INSERT INTO user (email, password, nickname, profileImg, comment) VALUES (?, ?, ?, ?, ?)'; | ||
const signupResult = await pool.queryParam_Arr(signupQuery, [req.body.email, hashedPw.toString('base64'), req.body.nickname, profileImg, req.body.comment]); | ||
|
||
if (!signupResult) { | ||
res.status(200).send(responseUtil.successFalse(returnCode.DB_ERROR, returnMessage.SIGNUP_FAIL)); | ||
} else { //쿼리문이 성공했을 때 | ||
|
||
}); | ||
const bodylen = req.body.genre.length; | ||
console.log(bodylen); | ||
|
||
const selectUserIdxQuery = 'SELECT userIdx FROM user WHERE (email = ?)'; | ||
const selectUserIdxResult = await pool.queryParam_Arr(selectUserIdxQuery, [req.body.email]); | ||
console.log(selectUserIdxResult[0]); | ||
const selectedUserIdx = selectUserIdxResult[0].userIdx; | ||
|
||
//유효한 email인지 확인 | ||
router.get('/email-verify', async (req, res, next) => { | ||
if(selectUserIdxResult[0]==null){ | ||
console.log('해당 유저 정보 없음'); | ||
res.status(200).send(responseUtil.successFalse(returnCode.DB_ERROR, returnMessage.NULL_VALUE)); | ||
}else{ | ||
for (i=0; i<bodylen; i++){ | ||
const userGenreQuery = 'INSERT INTO user_genre (userIdx, genreIdx) VALUES (?,?)'; | ||
const userGenreResult = await pool.queryParam_Arr(userGenreQuery, [selectedUserIdx, req.body.genre[i]]); | ||
if(!userGenreResult){ | ||
console.log('장르 삽입 실패'); | ||
res.status(200).send(responseUtil.successFalse(returnCode.DB_ERROR, returnMessage.GENRE_FAIL)); | ||
}else{ | ||
console.log('장르 삽입 성공'); | ||
} | ||
} | ||
|
||
const selectEmailQuery = 'SELECT email FROM user WHERE email = ?'; | ||
const selectEmailResult = await db.queryParam_Arr(selectEmailQuery, req.body.email); | ||
|
||
if(selectEmailResult[0] == null){ | ||
console.log('이메일 일치 없음'); | ||
//const hashedPw = await crypto.pbkdf2(req.body.password.toString(), salt, 1000, 32, 'SHA512'); | ||
const config = { | ||
mailer: { | ||
service: 'Gmail', | ||
host: 'localhost', | ||
port: '465', | ||
user: '[email protected]', | ||
password: 'k1207417', | ||
const defaultPlaylistName = ['history','like','rateReady','rated','upload','hits']; | ||
const defaultPlaylistComment = ["최근 재생곡","좋아요","평가 대기곡","평가한 곡","업로드한 곡","적중 곡"]; | ||
const defaultPlaylistIdx = new Array(); | ||
//const getUserIdxQuery = 'SELECT FROM user WHERE email = ?'; | ||
//const signUpUserIdx = await pool.queryParam_Arr(getUserIdxQuery, [req.body.email]); | ||
for (var i = 0; i < 6; i++) { | ||
await playlist.create({ | ||
playlistName: defaultPlaylistName[i], | ||
playlistComment: defaultPlaylistComment[i], | ||
userIdx: selectedUserIdx, | ||
songList: null | ||
}) | ||
} | ||
}; | ||
|
||
const from = 'WAVE'; | ||
const to = req.body.email; | ||
const subject = 'WAVE 회원가입 인증 메일입니다'; | ||
const html = '<p>인증번호는 '+ rand + ' 입니다.\n 인증번호 창에 입력해주세요.'; | ||
|
||
const mailOptions = { | ||
from, | ||
to, | ||
subject, | ||
html | ||
}; | ||
|
||
const transporter = nodemailer.createTransport(smtpPool({ | ||
service: config.mailer.service, | ||
host: config.mailer.host, | ||
port: config.mailer.port, | ||
auth: { | ||
user: config.mailer.user, | ||
pass: config.mailer.password, | ||
}, | ||
tls: { | ||
rejectUnauthorize: false, | ||
}, | ||
maxConnections: 5, | ||
maxMessages: 10, | ||
})); | ||
|
||
transporter.sendMail(mailOptions, (err, res) => { | ||
if (err) { | ||
console.log('failed... => ', err); | ||
} else { | ||
console.log('succeed... => ', res, rand); | ||
console.log('플레이리스트 목록 생성 완료'); | ||
for(var i = 0 ; i < 6; i++) { | ||
//const defaultPlaylistIdx = new Array(); | ||
defaultPlaylistIdx[i] = (await playlist.find({"userIdx" : selectedUserIdx}))[i]._id; | ||
} | ||
transporter.close(); | ||
}); | ||
}else{ | ||
console.log('중복 이메일 존재'); | ||
res.status(200).send(defaultRes.successFalse(returnCode.DB_ERROR, resMessage.SIGNUP_FAIL)); | ||
} | ||
}); | ||
console.log('플레이리스트 블록 2 완료'); | ||
|
||
//인증번호 확인 | ||
router.get('/authentication', async(req, res, next) =>{ | ||
const user_rand = String(req.body.authentication); | ||
if(user_rand == rand){ | ||
console.log('인증 성공'); | ||
}else{ | ||
console.log('인증 실패'); | ||
await myPlaylist.create({ | ||
userIdx : selectedUserIdx, | ||
historyPlaylist : defaultPlaylistIdx[0], | ||
likePlaylist : defaultPlaylistIdx[1], | ||
rateReadyPlaylist : defaultPlaylistIdx[2], | ||
ratedPlaylist : defaultPlaylistIdx[3], | ||
uploadPlaylist : defaultPlaylistIdx[4], | ||
hitsPlaylist : defaultPlaylistIdx[5] | ||
}) | ||
console.log('플레이리스트 블록 3 완료'); | ||
res.status(200).send(responseUtil.successTrue(returnCode.OK, returnMessage.SIGNUP_SUCCESS)); | ||
} | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports = { | ||
g1: '발라드', | ||
g1: 'Ballad', | ||
g2: 'POP', | ||
g3: '힙합', | ||
g4: '락', | ||
g5: '댄스' | ||
} | ||
g3: 'Hiphop', | ||
g4: 'Rock', | ||
g5: 'Dance' | ||
} |