node js, mongodb 질문드립니다

조회수 482회

비밀번호 분실시 학번 이름 조회해서 db에 있는 이메일로 임시 비밀번호를 보내려고하는데 이메일 조회를 어떻게 해야할지 질문 드립니다 ㅠ

nodejs

models/user.js

User1.getUserByInfo = function (name, username, callback) {
  const query = { name: name, username: username };
  return User1.findOne(query, {email: 1}, callback);
}

routes/users.js

router.post('/sendmail', (req, res) => {
  const name = req.body.name;
  const username = req.body.username;
  const email = User.getUserByInfo(name, username)
... 

Angular

services/auth.service.ts

sendEmail(obj): Observable<Sendmail> {
  const sendMail = 'http://localhost:3000/sendmail';
    return this.http.post<Sendmail>(sendMail, obj, httpOptions)
  }

components/sendmail.compo.ts

 var login = {
          name: this.name,
          username: this.username,
          email: ???
        }

this.authService.sendEmail(login).subscribe(data => {
       this.flashMessage.show('가입한 이메일로 임시 비밀번호 메일을 보냈습니다', {cssClass: 'alert-success', timeout: 5000});
       let msg = data['message']
       alert(msg);
     }, error =>{
        console.log(error,"error");
     });

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)