Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e9f5801
✨ feat: ν† μŠ€νŠΈ λ©”μ‹œμ§€ ν‘œμ‹œ ν•¨μˆ˜ μΆ”κ°€
vvzvvv Oct 6, 2025
1fcfdcd
✨ feat: 둜그인 νŽ˜μ΄μ§€μ˜ 였λ₯˜ μ•Œλ¦Ό 방식을 ν† μŠ€νŠΈ λ©”μ‹œμ§€λ‘œ κ°œμ„ 
vvzvvv Oct 6, 2025
f441a79
🎨 css: user.css μœ„μΉ˜ λ³€κ²½ 및 ν† μŠ€νŠΈ λ©”μ‹œμ§€ κ΄€λ ¨ css μΆ”κ°€
vvzvvv Oct 6, 2025
b0db16b
πŸš“ fix: user.css 경둜 μˆ˜μ • (users/user.css -> user.css)
vvzvvv Oct 6, 2025
8dbf399
✨ feat: μƒνƒœμ½”λ“œ 및 응닡 λ©”μ‹œμ§€ μΆ”κ°€ μž‘μ„±
vvzvvv Oct 6, 2025
225d938
πŸ”¨ refactor: 둜그인 λ‘œμ§μ— μƒμˆ˜ 적용 및 μ½”λ“œ 클린업
vvzvvv Oct 6, 2025
dae00fb
πŸ”₯ remove: μ˜μ‚¬ κ°€μž…μ‹œ μ—…λ‘œλ“œν•œ μΈμ¦μ„œ 이미지 파일 μ‚­μ œ
vvzvvv Oct 11, 2025
157d257
βš™οΈ setting: .gitignore에 μ—…λ‘œλ“œ 파일 경둜 μΆ”κ°€
vvzvvv Oct 11, 2025
6d30be1
✨ feat: ν™˜μž/μ˜μ‚¬ κ°€μž… νŽ˜μ΄μ§€μ˜ μ•Œλ¦Όμ„ alertμ—μ„œ showToast둜 λ³€κ²½
vvzvvv Oct 11, 2025
c159d54
πŸ”₯ remove: join.ejs μ‚­μ œ
vvzvvv Oct 11, 2025
de33b55
✨ feat: νšŒμ›κ°€μž… 및 ν”„λ‘œν•„ μˆ˜μ • κ΄€λ ¨ λ©”μ‹œμ§€ μƒμˆ˜ μˆ˜μ • 및 μΆ”κ°€
vvzvvv Oct 11, 2025
a542d6e
✨ feat: νšŒμ›κ°€μž… λ‘œμ§μ—μ„œ 응닡 λ©”μ‹œμ§€λ₯Ό μƒμˆ˜λ‘œ λ³€κ²½ 및 μƒνƒœ μ½”λ“œ κ°œμ„ 
vvzvvv Oct 11, 2025
73ce4cf
πŸ”¨ refactor: 이메일 쀑볡 확인 λ‘œμ§μ—μ„œ μƒνƒœ μ½”λ“œ 및 응닡 λ©”μ‹œμ§€ μƒμˆ˜ν™”
vvzvvv Oct 11, 2025
a6b9143
πŸ”¨ refactor: λΉ„λ°€λ²ˆν˜Έ λ³€κ²½ λ‘œμ§μ— μƒμˆ˜ 적용 및 μ½”λ“œ κ°œμ„ 
vvzvvv Oct 11, 2025
376d74d
πŸ”¨ refactor: λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ° λ‘œμ§μ— μƒμˆ˜ 적용 및 μ½”λ“œ κ°œμ„ 
vvzvvv Oct 11, 2025
464729b
chore: cleaning code
vvzvvv Feb 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
node_modules
server-system-425608-fa659756e648.json
yarn.lock
yarn.lock
uploads/*
20 changes: 16 additions & 4 deletions constants/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@ module.exports = {
// νšŒμ›κ°€μž…
CREATED_USER: 'νšŒμ› κ°€μž… 성곡',
DELETE_USER: 'νšŒμ› νƒˆν‡΄ 성곡',
ALREADY_EMAIL: '이미 μ‚¬μš©μ€‘μΈ μ΄λ©”μΌμž…λ‹ˆλ‹€.',
NON_AVAILABLE_EMAIL: '이미 μ‚¬μš©μ€‘μΈ μ΄λ©”μΌμž…λ‹ˆλ‹€.',
AVAILABLE_EMAIL: 'μ‚¬μš© κ°€λŠ₯ν•œ μ΄λ©”μΌμž…λ‹ˆλ‹€.',
DIFFRERENT_PASSWORD: 'λΉ„λ°€λ²ˆν˜Έμ™€ λΉ„λ°€λ²ˆν˜Έ 확인이 μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

DIFFRERENT_PASSWORD에 μ˜€νƒ€κ°€ μžˆμŠ΅λ‹ˆλ‹€. DIFFERENT_PASSWORD둜 μˆ˜μ •ν•˜λŠ” 것이 μ’‹κ² μŠ΅λ‹ˆλ‹€.

Suggested change
DIFFRERENT_PASSWORD: 'λΉ„λ°€λ²ˆν˜Έμ™€ λΉ„λ°€λ²ˆν˜Έ 확인이 μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€',
DIFFERENT_PASSWORD: 'λΉ„λ°€λ²ˆν˜Έμ™€ λΉ„λ°€λ²ˆν˜Έ 확인이 μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€',

SIGNUP_OK: 'κ°€μž… κ°€λŠ₯ν•©λ‹ˆλ‹€',
SIGNUP_NOT_OK: 'κ°€μž… λΆˆκ°€λŠ₯ν•©λ‹ˆλ‹€',
NO_LICENSE: 'μ˜μ‚¬λ©΄ν—ˆμ¦μ΄ ν•„μš”ν•©λ‹ˆλ‹€.',

// 둜그인
LOGIN_SUCCESS: '둜그인 성곡',
LOGIN_FAIL: '둜그인 μ‹€νŒ¨',
ALREADY_LOGIN: '이미 둜그인 μ€‘μž…λ‹ˆλ‹€.',
NEED_LOGIN: '둜그인이 ν•„μš”ν•œ μ„œλΉ„μŠ€ μž…λ‹ˆλ‹€.',
NO_USER: 'μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” νšŒμ›μž…λ‹ˆλ‹€.',
MISS_MATCH_PW: 'λΉ„λ°€λ²ˆν˜Έκ°€ λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€.',
INVALID_EMAIL: '이메일 ν˜•μ‹μ„ ν™•μΈν•΄μ£Όμ„Έμš”.',
WRONG_INPUT: '아이디 λ˜λŠ” λΉ„λ°€λ²ˆν˜Έλ₯Ό 잘λͺ» μž…λ ₯ν–ˆμŠ΅λ‹ˆλ‹€.',

// λ‘œκ·Έμ•„μ›ƒ
LOGOUT_SUCCESS: 'λ‘œκ·Έμ•„μ›ƒ 성곡',
LOGOUT_FAIL: 'λ‘œκ·Έμ•„μ›ƒ μ‹€νŒ¨',

// ν”„λ‘œν•„ 쑰회
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: 'μœ μ € μˆ˜μ • 성곡',
Expand Down
3 changes: 2 additions & 1 deletion constants/statusCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
15 changes: 7 additions & 8 deletions controllers/user/emailCheckingPOST.js
Original file line number Diff line number Diff line change
@@ -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 }});

Expand All @@ -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
});
}
Expand Down
18 changes: 8 additions & 10 deletions controllers/user/joinDoctorPOST.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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
});
}
Expand Down
10 changes: 6 additions & 4 deletions controllers/user/joinPatientPOST.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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});
}

// μƒˆλ‘œμš΄ μ‚¬μš©μž νšŒμ›κ°€μž…
Expand All @@ -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 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

μƒˆλ‘œμš΄ ν™˜μž λ¦¬μ†ŒμŠ€κ°€ μƒμ„±λ˜μ—ˆμœΌλ―€λ‘œ, HTTP μƒνƒœ μ½”λ“œλ‘œ 200 OK λŒ€μ‹  201 Createdλ₯Ό λ°˜ν™˜ν•˜λŠ” 것이 RESTful API 섀계 원칙에 더 λΆ€ν•©ν•©λ‹ˆλ‹€. joinDoctorPOST.jsμ—μ„œλ„ 201 Createdλ₯Ό μ‚¬μš©ν•˜κ³  μžˆμœΌλ―€λ‘œ 일관성을 μœ„ν•΄ μˆ˜μ •ν•˜λŠ” 것을 ꢌμž₯ν•©λ‹ˆλ‹€.

Suggested change
return res.status(statusCode.OK).send({ message: responseMessage.CREATED_USER });
return res.status(statusCode.CREATED).send({ message: responseMessage.CREATED_USER });

}
} catch (err) {
res.status(500).send({
Expand Down
30 changes: 13 additions & 17 deletions controllers/user/loginPOST.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,28 +17,25 @@ 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});
}

// ν™˜μžκ°€ λ‘œκ·ΈμΈν•œ 경우
if (findPatient) {
// νŒ¨μŠ€μ›Œλ“œ 일치 μ—¬λΆ€ 확인
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"
});
Expand All @@ -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
});
}
}
Expand Down
24 changes: 10 additions & 14 deletions controllers/user/passwordPUT.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

λ‹€λ₯Έ API 응닡과 일관성을 μœ μ§€ν•˜κΈ° μœ„ν•΄, λ¬Έμžμ—΄ λŒ€μ‹  JSON 객체 ν˜•νƒœλ‘œ 응닡을 λ³΄λ‚΄λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

Suggested change
return res.status(statusCode.BAD_REQUEST).send(responseMessage.DIFFRERENT_PASSWORD);
return res.status(statusCode.BAD_REQUEST).send({ message: responseMessage.DIFFRERENT_PASSWORD });

}

try {
Expand All @@ -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") {
Expand All @@ -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 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

catch λΈ”λ‘μ—μ„œ ν•˜λ“œμ½”λ”©λœ μƒνƒœ μ½”λ“œ 500을 μ‚¬μš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. 일관성을 μœ„ν•΄ statusCode.INTERNAL_SERVER_ERROR μƒμˆ˜λ₯Ό μ‚¬μš©ν•˜λ„λ‘ μˆ˜μ •ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

Suggested change
res.status(500).send({ message: responseMessage.FAIL_UPDATE_PASSWORD });
res.status(statusCode.INTERNAL_SERVER_ERROR).send({ message: responseMessage.FAIL_UPDATE_PASSWORD });

}
};

Expand Down
26 changes: 11 additions & 15 deletions controllers/user/passwordResetLinkPOST.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
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 λ°μ΄ν„°λ² μ΄μŠ€μ—μ„œ μ‘΄μž¬ν•˜λŠ” ν™˜μž 이메일인지 확인
const findPatient = await db.user.findOne({ where: { email: email } });
// 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 = '';
Expand All @@ -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파일 μ‚¬μš©)
Expand All @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions public/javascripts/toast.js
Original file line number Diff line number Diff line change
@@ -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);
}
Loading