Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in a nodejs program . landing.hbs Landing Sign in this is a land ---------------------- server.js var express = require('express'); var exphbs = require('express-handlebars'); var app

in a nodejs program .

landing.hbs

Landing

Sign in

this is a land

----------------------

server.js

var express = require('express'); var exphbs = require('express-handlebars'); var app = express(); //app.engine('.hbs', exphbs({extname: '.hbs'})); //app.set('view engine', '.hbs'); app.engine('hbs', exphbs({defaultLayout: false, extname:'.hbs',})); const bodyParser = require("body-parser"); const fs = require("fs"); var createError = require("http-errors"); const passport = require("passport"); var path = require("path"); const session = require("express-session"); var cookieParser = require("cookie-parser"); var logger = require("morgan"); var express = require('express'); var exphbs = require('express-handlebars'); app.set("views", path.join(__dirname, "views")); app.set("view engine", "hbs"); app.use(logger("dev")); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, "public"))); app.use(express.static("./public")); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); var userLogin = {};

app.post('/api/landing',(req,res)=>{ res.render("login"); });

app.post("/api/login", (req, res) => { fs.readFile("./data.json", (err, data) => { var arr = []; if (err) { console.log(err); } else { if (data.toString()) { arr = JSON.parse(data.toString()); } var s = arr.find((item) => { if (item.name == req.body.name) { return item; } }); if (s) { if (s.password == req.body.password) { userLogin = req.body; res.json({ status: "y", meg: "login success", data: s.name, }); } else { res.json({ status: "err", meg: "wrong password ", }); } } else { res.json({ status: "n", meg: "no such user ", }); } } }); });

------------------------ login .hbs

Login

Login

>
  • -----------------

    how could i add some picture in the "landing.hbs" ,and add a picture to be a background ?

    how can i makei t work ,when i press "signin "it will show the "login "page in the landing page ?"

    Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    Database Design And SQL For DB2

    Authors: James Cooper

    1st Edition

    1583473572, 978-1583473573

    More Books

    Students also viewed these Databases questions