-
글쓴이글
-
2022년 4월 10일 10:27 #31488
냠냠냠참가자안녕하세요.
배운 코드 바탕으로 회원정보수정을 페이지를 만들고 있습니다.
글 수정과 비슷하게 들어가고 collection만 달라지는 것이라고 생각했는데, 오류페이지는 딱히 안 나오지만 db 들어가면 회원정보 수정이 안 되어있습니다.... 어디서 문제가 생기는지 모르겠습니다...
server.js 에는
//마이 페이지 내 정보 수정에 데이터 뿌리기
app.get('/mypage/:id', function(요청, 응답) {
db.collection('login').findOne({id : parseInt(요청.params.id)},function(에러, 결과){
if(에러){return console.log(에러)};
console.log(결과);
응답.render('mypage.ejs', {user : 결과});
});
});//마이 페이지 내정보수정
app.put('/mypage', function(요청, 응답){
var 수정할데이터 = {id : 요청.body.id}
if(db.collection('login').findOne({id : 요청.body.id})){
bcrypt.hash(요청.body.pw, saltRounds, function (err, hash) {
db.collection('login').updateOne(수정할데이터,{ $set : {email : 요청.body.email, pw : hash} },function(에러, 결과){
if(에러){return console.log(에러)};
console.log(결과);
console.log('회원 정보 수정 완료');
응답.send("<script>alert('회원 정보 수정이 완료되었습니다!'); window.location.replace('/mypage');</script>");
})
})
}
});이런 식으로 작성하였고,
mypage.ejs 에는
<h4 class="container mt-4 text-center"><strong> <%= 사용자.id %> 님 회원 정보 수정 </strong></h4>
<div class="container mt-3" style="width: 50%;">
<form action="/mypage?_method=PUT" method="POST">
<div class="form-group">
<label>이메일 <%= 사용자.email %></label>
<input type="email" value="<%= 사용자.email %>" class="form-control" name="email">
</div>
<div class="form-group">
<label>비밀번호</label>
<input id="pw" type="password" class="form-control" name="pw">
</div>
<div class="form-group">
<label>비밀번호 재확인</label>
<input id="pw_a" type="password" class="form-control" name="pwAgain">
</div><br>
<button type="submit" class="btn btn-outline-secondary">정보 수정</button>
</form>
</div>
이렇게 작성하였습니다.
콘솔에는
{
_id: new ObjectId("62495b9101106e828c96ff38"),
id: 'love',
pw: '$2b$10$dGbuJArd4wlGB6dWduCDGePlynIgQnauxvf8NwEOXrp7tlKL/5OP.'
}
{
acknowledged: true,
modifiedCount: 0,
upsertedId: null,
upsertedCount: 0,
matchedCount: 0
}
회원 정보 수정 완료
{
_id: new ObjectId("62495b9101106e828c96ff38"),
id: 'love',
pw: '$2b$10$dGbuJArd4wlGB6dWduCDGePlynIgQnauxvf8NwEOXrp7tlKL/5OP.'
}이렇게 출력되고 있습니다.
수정 완료라는 콘솔로그가 나와서 된 줄 알았는데 db 들어가서 확인해보니 정보가 바뀌지 않았습니다... 코드를 여기서 어떻게 수정을 해야 할까요?? 도움 부탁드립니다...
2022년 4월 10일 20:19 #31512
codingapple키 마스터var 수정할데이터 이런거부터 잘 들어오는지 출력해봅시다
없다면 프론트엔드에서 잘못보내거나 그런경우라 ejs파일 수정하면 됩니다
-
글쓴이글
- 답변은 로그인 후 가능합니다.