처음 만드는 Node.js + MySQL 회원관리 미니실습노트

login.ejs 회원가입 완료 메시지

· 1 views

회원가입이 성공적으로 이루어지면 로그인 페이지로 이동합니다.
msg=success라는 쿼리스트링 값을 함께 전달합니다.

로그인 페이지(login.ejs)에서 그 값을 감지해 "회원가입이 완료되었습니다."라는 안내 문구를 표시합니다.

▼ Code

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>로그인</title>
    <link rel="stylesheet" href="/static/common​.css" />
  </head>

  <body>
    <h2>로그인</h2>

    <form method="post">
      <input name="userid" placeholder="아이디" required />
      <br />
      <input name="pwd" type="password" placeholder="비밀번호" required />
      <br />
      <button type="submit">로그인</b​utton>
      <button type="button" onclick="location.hr​ef='/member/register​'">회원가입</button>
    </form>

    <% if (typeof msg !== 'undefined' && msg === 'fail') { %>
    <p style="color: red">로그인에 실패했습니다.</p>
    <% } else if (typeof msg !== 'undefined' && msg === 'logout') { %>
    <p style="color: red">로그아웃이 완료되었습니다.</p>
    <% } else if (typeof msg !== 'undefined' && msg === 'success') { %>
    <p style="color: red">회원가입이 완료되었습니다.</p>
    <% } %>
  </body>
</html>

▼ Explain

<% } else if (typeof msg !== 'undefined' && msg === 'success') { %>
앞서 작성한 로그인 실패(msg=fail)와 로그아웃 완료(msg=logout) 조건문 뒤에 이어지는 분기입니다.
msg 값이 'success'일 때만 이 코드가 실행됩니다.

<p style="color: red">회원가입이 완료되었습니다.</p>
안내 문구를 화면에 출력합니다.

댓글

아직 댓글이 없습니다.