For the login
view, Listing 26.12 implements a simple login form that allows you to specify a username and password to use to create an authenticated session. The form includes text and password <input>
elements. The form method is POST
, to include the username
and password
fields in the POST
body for the route. Notice that the <%=msg>
EJS script element is included to display the message if one exists on the session. Figure 26.3 shows the rendered login page.
01 <!doctype html>
02 <html>
03 <head>
04 <title>User Login and Sessions</title>
05 <link rel="stylesheet" type="text/css"
06 href="/static/css/styles.css" />
07 </head>
08 <body>
09 <div class="form-container">
10 <p class="form-header">Login</p>
11 <form method="POST">
12 <label>Username:</label>
13 <input type="text" name="username"><br>
14 <label>Password:</label>
15 <input type="password" name="password"><br>
16 <input type="submit" value="Login">
17 </form>
18 </div>
19 <a href="/signup">Sign Up</a>
20 <hr><%= msg %>
21 </body>
22 </html>