Login Required

Rendering Pages for Sign up and Sign in

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 294:- Rendering Pages for Sign up and Sign in

To render pages for Sign up and Sign in, we need to create a new route in our routes directory and define two new controller functions to handle GET requests for the respective pages.

First, we need to create a new file auth.js in the routes directory and define our routes in it.

javascriptCopy code

const express = require('express'); const router = express.Router(); const authController = require('../controllers/authController'); // Sign up page router.get('/signup', authController.signup_get); // Sign in page router.get('/signin', authController.signin_get); module.exports = router;

Here, we have defined two routes /signup and /signin and specified the corresponding controller functions signup_get and signin_get from authController.

Next, we need to create authController.js in the controllers directory and define the two controller functions.

javascriptCopy code

const signup_get = (req, res) => {  res.render('signup'); }; const signin_get = (req, res) => {  res.render('signin'); }; module.exports = {  signup_get,  signin_get, };

Here, we have defined two controller functions signup_get and signin_get to render the signup.ejs and signin.ejs views respectively.

Finally, we need to create signup.ejs and signin.ejs views in the views directory with the necessary HTML and EJS code to render the pages.

For example, the signup.ejs view could look like this:

htmlCopy code

<!DOCTYPE html> <html>  <head>    <meta charset="utf-8" />    <title>Sign Up</title>  </head>  <body>    <h1>Sign Up</h1>    <form action="/signup" method="POST">      <label for="username">Username:</label>      <input type="text" id="username" name="username" required />      <br />      <label for="password">Password:</label>      <input type="password" id="password" name="password" required />      <br />      <button type="submit">Sign Up</button>    </form>  </body> </html>

Similarly, the signin.ejs view could look like this:

htmlCopy code

<!DOCTYPE html> <html>  <head>    <meta charset="utf-8" />    <title>Sign In</title>  </head>  <body>    <h1>Sign In</h1>    <form action="/signin" method="POST">      <label for="username">Username:</label>      <input type="text" id="username" name="username" required />      <br />      <label for="password">Password:</label>      <input type="password" id="password" name="password" required />      <br />      <button type="submit">Sign In</button>    </form>  </body> </html>

With these files in place, we can now navigate to localhost:3000/signup and localhost:3000/signin in the browser to see the rendered pages for Sign up and Sign in.

34 Manual Authentication
🎬 10 videos

Course Certificate

Complete 100% to unlock your certificate

Sponsored

Course Discussion

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 8:09 AM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 5:26 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 7:59 AM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support