Я сделал авторизацию для своего сайта и попытался заполнить страницу регистрации некоторыми частями информации.Когда я заполняю эту информацию, при установке или регистрации у меня появляется событие клика, которое перенаправляет на страницу плохого запроса.Вы можете помочь?
код app.js
//jshint esversion:6
const express = require("express");
const ejs = require("ejs");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const session = require("express-session");
const passport = require("passport");
const passportLocalMongoose = require("passport-local-mongoose");
const app = express();
app.use(express.static("public"));
app.set('view engine', "ejs");
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(session({
secret: 'Thisismynameisdo',
resave: false,
saveUninitialized: true,
}));
app.use(passport.initialize());
// create session
app.use(passport.session());
mongoose.connect("mongodb://localhost:27017/myPortfolio", {useNewUrlParser: true});
const adminUser = new mongoose.Schema ({
flname : String,
username : String,
email : String,
password: String
});
// hash and salt password
adminUser.plugin(passportLocalMongoose);
const Admin = mongoose.model("Admin", adminUser);
// create strategies
passport.use(Admin.createStrategy());
passport.serializeUser(Admin.serializeUser());
passport.deserializeUser(Admin.deserializeUser());
app.get("/", function(req, res) {
res.render("frontend/index");
});
app.get("/blog", function(req, res) {
res.render("frontend/blog");
});
app.get("/404", function(req, res) {
res.render("frontend/404");
});
app.get("/blogdetail", function(req, res) {
res.render("frontend/blogdetail");
});
app.get("/blogaudio", function(req, res) {
res.render("frontend/blogaudio");
});
app.get("/login", function(req, res) {
res.render("backend/login");
});
app.get("/thanks", function(req, res) {
res.render("frontend/mailchimp");
});
app.get('/install', function(req, res) {
res.render("backend/install.ejs");
});
app.get("/admin", function(req, res) {
if(req.isAuthenticated()) {
res.render("backend/dashboard");
} else {
res.redirect("/login");
}
});
app.post("/install", function(req, res) {
//registration page
Admin.register({flname: req.body.flname, username: req.body.username, email: req.body.email}, req.body.pass, function(err, user) {
if (err) {
console.log(err);
res.redirect("/install");
} else {
passport.authenticate("local")(req, res, function() {
res.redirect("/admin");
});
}
});
});
app.post("/login", function(req, res) {
const user = new Admin({
flname : req.body.flname,
username : req.body.username,
email : req.body.email,
password: req.body.pass
});
req.login(user, function(err){
passport.authenticate("local")(req, res, function() {
res.redirect("/admin");
});
});
});
app.listen(3000, function(req, res) {
console.log("running => 3000");
});
Я использую содержимое ejs для просмотра своих страниц и анализатор тела, чтобы получить код из файла js приложения.
Код моей страницы регистрации указан ниже:
Администратор
<form action="/install" method="POST" class="login100-form validate-form">
<span class="login100-form-title">
Installation Process
</span>
<div class="wrap-input100 validate-input" data-validate = "enter Full name like : Ismail Taibi">
<input class="input100" type="text" name="flname" placeholder="Full Name">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-users" aria-hidden="true"></i>
</span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Valid username is required: abcd123">
<input class="input100" type="text" name="username" placeholder="Username">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-user" aria-hidden="true"></i>
</span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
<input class="input100" type="email" name="email" placeholder="Email">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-envelope" aria-hidden="true"></i>
</span>
</div>
<div class="wrap-input100 validate-input" data-validate = "Password is required">
<input class="input100" type="password" name="pass" placeholder="Password">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock" aria-hidden="true"></i>
</span>
</div>
<div class="container-login100-form-btn">
<button type="submit" name="btnRegistrationSubmit" class="login100-form-btn">
INSTALL
</button>
</div>
<div class="text-center p-t-136">
<a class="txt2" href="https://www.facebook.com/profile.php?id=100011693180444">
Developed by Ismail Taibi
<i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
</a>
</div>
</form> </div> </div> </div>
$('.js-tilt').tilt({ scale: 1.1 }) </script> <!--===============================================================================================--> <script src="admin/js/main.js"></script>