+ + +
diff --git a/.gitignore b/.gitignore index 8f32b40..7f24107 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env node_modules server-system-425608-fa659756e648.json -yarn.lock \ No newline at end of file +yarn.lock +uploads/* \ No newline at end of file diff --git a/constants/responseMessage.js b/constants/responseMessage.js index 7b64999..31ce1a3 100644 --- a/constants/responseMessage.js +++ b/constants/responseMessage.js @@ -6,10 +6,12 @@ module.exports = { // 회원가입 CREATED_USER: '회원 가입 성공', DELETE_USER: '회원 탈퇴 성공', - ALREADY_EMAIL: '이미 사용중인 이메일입니다.', + NON_AVAILABLE_EMAIL: '이미 사용중인 이메일입니다.', + AVAILABLE_EMAIL: '사용 가능한 이메일입니다.', DIFFRERENT_PASSWORD: '비밀번호와 비밀번호 확인이 일치하지 않습니다', SIGNUP_OK: '가입 가능합니다', SIGNUP_NOT_OK: '가입 불가능합니다', + NO_LICENSE: '의사면허증이 필요합니다.', // 로그인 LOGIN_SUCCESS: '로그인 성공', @@ -17,8 +19,8 @@ module.exports = { ALREADY_LOGIN: '이미 로그인 중입니다.', NEED_LOGIN: '로그인이 필요한 서비스 입니다.', NO_USER: '존재하지 않는 회원입니다.', - MISS_MATCH_PW: '비밀번호가 맞지 않습니다.', INVALID_EMAIL: '이메일 형식을 확인해주세요.', + WRONG_INPUT: '아이디 또는 비밀번호를 잘못 입력했습니다.', // 로그아웃 LOGOUT_SUCCESS: '로그아웃 성공', @@ -26,8 +28,18 @@ module.exports = { // 프로필 조회 READ_PROFILE_SUCCESS: '프로필 조회 성공', - - // 유저 + + // 프로필 수정 + SUCCESS_UPDATE_PASSWORD: '비밀번호 변경이 완료되었습니다.', + FAIL_UPDATE_PASSWORD: '비밀번호 변경에 실패하였습니다.', + + // 비밀번호 초기화 + NOT_FOUND_EMAIL: '등록된 이메일이 아닙니다.\n이메일을 확인해주세요.', + SEND_PASSWORD_RESET_LINK_SUCCESS: '입력하신 이메일로 비밀번호 초기화 링크를 전송하였습니다.', + SEND_PASSWORD_RESET_LINK_FAIL: '링크 전송에 실패하였습니다.\n다시 시도해주세요.', + + + // 유저 READ_ONE_USER_SUCCESS: '유저 조회 성공', READ_ALL_USERS_SUCCESS: '모든 유저 조회 성공', UPDATE_ONE_USER_SUCCESS: '유저 수정 성공', diff --git a/constants/statusCode.js b/constants/statusCode.js index 06b03d1..fe04390 100644 --- a/constants/statusCode.js +++ b/constants/statusCode.js @@ -6,7 +6,8 @@ module.exports = { UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, + CONFLICT: 409, INTERNAL_SERVER_ERROR: 500, SERVICE_UNAVAILABLE: 503, DB_ERROR: 600, - }; \ No newline at end of file +}; \ No newline at end of file diff --git a/controllers/test/testGET.js b/controllers/test/testGET.js index 8e7eb54..c0dd8fd 100644 --- a/controllers/test/testGET.js +++ b/controllers/test/testGET.js @@ -11,7 +11,7 @@ module.exports = async (req, res) => { for(var test of result){ testList.push(test.get(0)); } - console.log(testList); + return testList[0]; } catch(err) { diff --git a/controllers/user/emailCheckingPOST.js b/controllers/user/emailCheckingPOST.js index db2543d..5ca801a 100644 --- a/controllers/user/emailCheckingPOST.js +++ b/controllers/user/emailCheckingPOST.js @@ -1,11 +1,10 @@ +const responseMessage = require('../../constants/responseMessage'); +const statusCode = require('../../constants/statusCode'); const db = require('../../models/index'); - const emailCheck = async (req, res) => { try { const { email } = req.body; - console.log(req.body.email); - // 이미 등록된 환자인지 확인 const findUser = await db.user.findOne({ where: { email: email }}); @@ -14,17 +13,17 @@ const emailCheck = async (req, res) => { // 기존 등록된 이메일인 경우 if (findUser || findDoctor) { - return res.status(404).send({ - message: "기존 등록된 사용자입니다." + return res.status(statusCode.CONFLICT).send({ + message: responseMessage.NON_AVAILABLE_EMAIL }); } // 기존 등록된 이메일이 아닌 경우 - res.status(200).send({ - message: "회원가입 가능한 이메일입니다." + res.status(statusCode.OK).send({ + message: responseMessage.AVAILABLE_EMAIL }); } catch (err) { - res.status(500).send({ + res.status(statusCode.INTERNAL_SERVER_ERROR).send({ message: err.message }); } diff --git a/controllers/user/joinDoctorPOST.js b/controllers/user/joinDoctorPOST.js index 9e23d61..d101ad7 100644 --- a/controllers/user/joinDoctorPOST.js +++ b/controllers/user/joinDoctorPOST.js @@ -1,24 +1,24 @@ -const db = require('../../models/index'); -const dotenv = require('dotenv'); const path = require('path'); +const dotenv = require('dotenv'); +const db = require('../../models/index'); +const responseMessage = require('../../constants/responseMessage'); +const statusCode = require('../../constants/statusCode'); dotenv.config(); - const join = async (req, res) => { try { const { name, email, password, passwordCheck, license_number } = req.body; // 비밀번호 일치여부 검증 로직 if (password !== passwordCheck) { - return res.status(409).send({message: "비밀번호가 일치하지 않습니다.\n다시 입력해주세요."}); + return res.status(statusCode.CONFLICT).send({message: responseMessage.DIFFRERENT_PASSWORD}); } if (!req.file) { - return res.status(400).send({ message: "의사면허증을 업로드 해주세요." }); + return res.status(statusCode.BAD_REQUEST).send({ message: responseMessage.NO_LICENSE }); } const licenseFilePath = req.file.path; - //console.log("licenseFilePath: ", licenseFilePath); // 새로운 사용자 회원가입 const newDoctor = await db.doctor.create({ @@ -28,13 +28,11 @@ const join = async (req, res) => { license_number: license_number, license: licenseFilePath }); - - console.log("licenseFilePath: ", licenseFilePath); - return res.status(200).send({ message: "회원가입 되었습니다.\n로그인 해주세요."}); + return res.status(statusCode.CREATED).send({ message: responseMessage.CREATED_USER }); } catch (err) { - res.status(500).send({ + res.status(statusCode.INTERNAL_SERVER_ERROR).send({ message: err.message }); } diff --git a/controllers/user/joinPatientPOST.js b/controllers/user/joinPatientPOST.js index cc3bfe6..cca5c95 100644 --- a/controllers/user/joinPatientPOST.js +++ b/controllers/user/joinPatientPOST.js @@ -1,5 +1,7 @@ -const db = require('../../models/index'); const dotenv = require('dotenv'); +const db = require('../../models/index'); +const responseMessage = require('../../constants/responseMessage'); +const statusCode = require('../../constants/statusCode'); dotenv.config(); @@ -10,7 +12,7 @@ const join = async (req, res) => { // 비밀번호 일치여부 검증 로직 if (password !== passwordCheck) { - return res.status(409).send({message: "비밀번호가 일치하지 않습니다.\n다시 입력해주세요."}); + return res.status(statusCode.CONFLICT).send({message: responseMessage.DIFFRERENT_PASSWORD}); } // 새로운 사용자 회원가입 @@ -20,8 +22,8 @@ const join = async (req, res) => { email: email, password: password }); - - return res.status(200).send({ message: "회원가입 되었습니다.\n로그인 해주세요."}); + + return res.status(statusCode.OK).send({ message: responseMessage.CREATED_USER }); } } catch (err) { res.status(500).send({ diff --git a/controllers/user/loginPOST.js b/controllers/user/loginPOST.js index 5a355bd..d6d3617 100644 --- a/controllers/user/loginPOST.js +++ b/controllers/user/loginPOST.js @@ -1,10 +1,11 @@ const bcrypt = require('bcrypt'); - const dotenv = require('dotenv'); const jwt = require('jsonwebtoken'); -dotenv.config(); +const db = require('../../models/index'); +const responseMessage = require('../../constants/responseMessage'); +const statusCode = require('../../constants/statusCode'); -var db = require('../../models/index'); +dotenv.config(); const login = async(req, res, next) => { try { @@ -16,12 +17,9 @@ const login = async(req, res, next) => { // doctor 데이터베이스에서 존재하는 의사 이메일인지 확인 const findDoctor = await db.doctor.findOne({ where: {email: email} }); - console.log(findPatient); - console.log(findDoctor); - // 환자, 의사 둘다 찾지 못한 경우 if (findPatient === null && findDoctor === null) { - return res.status(404).send({message: "존재하지 않는 사용자입니다.\n회원가입을 해주세요."}); + return res.status(statusCode.NOT_FOUND).send({message: responseMessage.WRONG_INPUT}); } // 환자가 로그인한 경우 @@ -29,15 +27,15 @@ const login = async(req, res, next) => { // 패스워드 일치 여부 확인 const isPasswordValid = await bcrypt.compare(password, findPatient.password); if (!isPasswordValid) { - return res.status(401).send({message: "비밀번호가 일치하지 않습니다.\n다시 입력해주세요."}); + return res.status(statusCode.UNAUTHORIZED).send({message: responseMessage.WRONG_INPUT}); } // 토큰 생성하고 응답에 토큰 담아서 보내줌 const secretKey = process.env.MY_SECRET; const token = jwt.sign({userId: findPatient.user_id, user: "patient" }, secretKey); - return res.status(200).send({ - message: "환자 로그인 되었습니다.", // 추후 "로그인 되었습니다"로 수정 필요 + return res.status(statusCode.OK).send({ + message: responseMessage.LOGIN_SUCCESS, token: token, user: "patient" }); @@ -50,25 +48,23 @@ const login = async(req, res, next) => { // 패스워드 일치 여부 확인 const isPasswordValid = await bcrypt.compare(password, findDoctor.password); if (!isPasswordValid) { - return res.status(401).send({message: "비밀번호가 일치하지 않습니다.\n다시 입력해주세요."}); + return res.status(statusCode.UNAUTHORIZED).send({message: responseMessage.WRONG_INPUT}); } // 토큰 생성하고 응답에 토큰 담아서 보내줌 const secretKey = process.env.MY_SECRET; const token = jwt.sign({doctorId: findDoctor.doctor_id, user: "doctor" }, secretKey); - - console.log("token: ", token); - return res.status(200).send({ - message: "의사 로그인 되었습니다.", // 추후 "로그인 되었습니다"로 수정 필요 + return res.status(statusCode.OK).send({ + message: responseMessage.LOGIN_SUCCESS, token: token, user: "doctor" }); } } catch(err) { - res.status(500).send({ - message: "나중에 다시 시도해주세요." + res.status(statusCode.INTERNAL_SERVER_ERROR).send({ + message: responseMessage.INTERNAL_SERVER_ERROR }); } } diff --git a/controllers/user/passwordPUT.js b/controllers/user/passwordPUT.js index a2309a5..bf6e041 100644 --- a/controllers/user/passwordPUT.js +++ b/controllers/user/passwordPUT.js @@ -1,6 +1,7 @@ -const db = require('../../models/index'); const bcrypt = require('bcrypt'); - +const db = require('../../models/index'); +const statusCode = require('../../constants/statusCode'); +const responseMessage = require('../../constants/responseMessage'); // 토큰을 위한 모듈 const jwt = require('jsonwebtoken'); @@ -12,12 +13,10 @@ const changePassword = async function (req, res) { const { newPassword, doubleCheckNewPassword } = req.body; const authHeader = req.headers.authorization; const token = authHeader.split(' ')[1]; - - console.log(token); // 비밀번호 더블체크 로직 if (newPassword !== doubleCheckNewPassword) { - return res.status(400).send('비밀번호 불일치'); + return res.status(statusCode.BAD_REQUEST).send(responseMessage.DIFFRERENT_PASSWORD); } try { @@ -28,10 +27,8 @@ const changePassword = async function (req, res) { const user = decode.user; // 환자인지 의사인지 구분 - console.log(email); - console.log(user); - - const hashedNewPassword = await bcrypt.hash(newPassword, 10); + const saltRounds = 10; + const hashedNewPassword = await bcrypt.hash(newPassword, saltRounds); // 환자 이메일인 경우 if (user == "patient") { @@ -51,19 +48,18 @@ const changePassword = async function (req, res) { }, ); } - // 비밀번호 변경 후 토큰 데이터베이스에 저장되어 있는 토큰 삭제 const passwordToken = await db.passwordToken.findOne({ where: { email: email } }); - console.log(passwordToken); + await passwordToken.destroy(); - res.status(200).send({ - message: "비밀번호 변경이 완료되었습니다.", + res.status(statusCode.OK).send({ + message: responseMessage.SUCCESS_UPDATE_PASSWORD, token: token }); } catch (error) { - res.status(500).send({ message: "비밀번호 변경이 실패하였습니다.\n나중에 다시 시도해주세요."}); + res.status(500).send({ message: responseMessage.FAIL_UPDATE_PASSWORD }); } }; diff --git a/controllers/user/passwordResetLinkPOST.js b/controllers/user/passwordResetLinkPOST.js index fbc872f..0f6a03c 100644 --- a/controllers/user/passwordResetLinkPOST.js +++ b/controllers/user/passwordResetLinkPOST.js @@ -1,17 +1,19 @@ -const smtpTransport = require("../../emailVerificationConfig"); - const jwt = require('jsonwebtoken'); -require('dotenv').config(); -const secretKey = process.env.MY_SECRET; +const dotenv = require('dotenv'); +dotenv.config(); const db = require('../../models/index'); +const smtpTransport = require("../../emailVerificationConfig"); +const statusCode = require('../../constants/statusCode'); +const responseMessage = require('../../constants/responseMessage'); + +const secretKey = process.env.MY_SECRET; const findPassword = async function (req, res) { const { email } = req.body; try { - /* 등록된 이메일인지 확인 */ // user 데이터베이스에서 존재하는 환자 이메일인지 확인 @@ -19,13 +21,9 @@ const findPassword = async function (req, res) { // doctor 데이터베이스에서 존재하는 의사 이메일인지 확인 const findDoctor = await db.doctor.findOne({ where: { email: email } }); - console.log(findPatient); - console.log(findDoctor); - // 환자, 의사 둘다 찾지 못한 경우 if (findPatient === null && findDoctor === null) { - console.log("등록된 이메일이 아닙니다."); - return res.status(404).send({ message: "등록된 이메일이 아닙니다.\n이메일을 확인해주세요." }); + return res.status(statusCode.NOT_FOUND).send({ message: responseMessage.NOT_FOUND_EMAIL }); } let token = ''; @@ -40,8 +38,6 @@ const findPassword = async function (req, res) { token = jwt.sign({ email: email, user: "doctor" }, secretKey); } - console.log(token); - await db.passwordToken.create({ email, token }); // db에 resetToken 모델 생성해야 함 const resetLink = `http://localhost:3000/user/password/change?token=${token}`; // 서버 url 수정(.env파일 사용) @@ -55,11 +51,11 @@ const findPassword = async function (req, res) { await smtpTransport.sendMail(emailOptions); - res.status(200).send({ - message: "입력하신 이메일로 비밀번호 초기화 링크를 전송하였습니다.", + res.status(statusCode.OK).send({ + message: responseMessage.SEND_PASSWORD_RESET_LINK_SUCCESS, }); } catch (error) { - res.status(500).send({message: "링크 전송 실패이 실패하였습니다.\n나중에 다시 시도해주세요."}); + res.status(statusCode.INTERNAL_SERVER_ERROR).send({message: responseMessage.SEND_PASSWORD_RESET_LINK_FAIL}); } finally { smtpTransport.close(); } diff --git a/public/javascripts/toast.js b/public/javascripts/toast.js new file mode 100644 index 0000000..26c4595 --- /dev/null +++ b/public/javascripts/toast.js @@ -0,0 +1,9 @@ +function showToast(message) { + const toast = document.getElementById('toast'); + toast.textContent = message; + toast.style.display = 'block'; + + setTimeout(() => { + toast.style.display = 'none'; + }, 2000); +} \ No newline at end of file diff --git a/public/stylesheets/users/user.css b/public/stylesheets/user.css similarity index 97% rename from public/stylesheets/users/user.css rename to public/stylesheets/user.css index 57b3c10..cc4804a 100644 --- a/public/stylesheets/users/user.css +++ b/public/stylesheets/user.css @@ -14,7 +14,6 @@ width: 40rem; } - /* 회원가입할때 환자인지 의사인지 선택하는 버튼 관련 CSS */ @@ -48,6 +47,7 @@ text-decoration: none; } + .user .right { display: inline-block; @@ -62,8 +62,6 @@ margin-bottom: 10.1rem; } - - .user .form { width: 50rem; margin: 0 auto; @@ -81,10 +79,6 @@ text-decoration: none; } - - - - .user .text_input { background-color: #F5F5F5; box-shadow: 0.5rem 0.5rem 5px rgb(114, 114, 114); @@ -188,4 +182,11 @@ a:visited { color: inherit; +} + +.toast { + text-align: center; + color: red; + font-size: 20px; + margin-top: 25px; } \ No newline at end of file diff --git a/uploads/certification-1723561847400-421066323.png b/uploads/certification-1723561847400-421066323.png deleted file mode 100644 index e151d2a..0000000 Binary files a/uploads/certification-1723561847400-421066323.png and /dev/null differ diff --git a/uploads/certification-1723698197419-797421853.png b/uploads/certification-1723698197419-797421853.png deleted file mode 100644 index 67b1e4e..0000000 Binary files a/uploads/certification-1723698197419-797421853.png and /dev/null differ diff --git a/views/user/changePassword.ejs b/views/user/changePassword.ejs index 945da76..522e270 100644 --- a/views/user/changePassword.ejs +++ b/views/user/changePassword.ejs @@ -1,6 +1,6 @@ - + <%-include('../header.ejs') %> diff --git a/views/user/doctorJoin.ejs b/views/user/doctorJoin.ejs index 797a31f..4139539 100644 --- a/views/user/doctorJoin.ejs +++ b/views/user/doctorJoin.ejs @@ -1,6 +1,6 @@ - + <%-include('../header.ejs') %> @@ -67,13 +67,21 @@ + +
+ + + + diff --git a/views/user/emailVerification.ejs b/views/user/emailVerification.ejs index 2efe0d8..dadcae5 100644 --- a/views/user/emailVerification.ejs +++ b/views/user/emailVerification.ejs @@ -1,6 +1,6 @@ - + <%-include('../header.ejs') %> @@ -20,10 +20,6 @@ -
-
-
-