Login and Register on the same Page nodejs - javascript

Hi guys I am currently creating a website where the login and register is on the same page (for design reasons) I have also tried around but somehow I always get into an infinitely long loading loop.
Folder structure:
The code I have currently divided as follows:
routes/auth.js:
const express = require('express');
const authController = require('../controllers/auth');
const router = express.Router();
router.post('/register', authController.register);
router.post('/register', authController.login);
module.exports = router;
and controllers/auth.js:
const mysql = require("mysql");
const jwt = require('jsonwebtoken');
const bcrypt = require('bcryptjs');
const db = mysql.createConnection({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE
});
exports.register = (req, res) => {
console.log(req.body);
const { name, email, password, passwordConfirm } = req.body;
let hashedPassword = bcrypt.hash(password, 10);
console.log(hashedPassword);
db.query('SELECT email from users WHERE email = ?', [email], async(error, results) => {
if (error) {
console.log(error);
}
if (results.length > 0) {
return res.render('message/emailerror');
} else if (password !== passwordConfirm) {
return res.render('message/pwderror');
}
let hashedPassword = await bcrypt.hash(password, 10);
console.log(hashedPassword);
db.query('INSERT INTO users SET ?', { name: name, email: email, password: hashedPassword }, (error, results) => {
if (error) {
console.log(error);
} else {
console.log(results);
console.log('+++++++++++ User registered ++++++++++')
//return res.render('register', {
// message: 'User registered'
//});
}
});
});
}
//to login the user
exports.login = async (req, res) => {
try {
const {emaillogin, passwordlogin} = req.body;
if(!emaillogin || !passwordlogin) {
return res.status(400).render('register', {
message: 'Pls provide something'
});
}
} catch (error) {
console.log(error);
}
}
and the register.hbs where i have the html code:
Login Form:
<div id="login">
<h1 class="loginh1 transform2">Willkommen</h1>
<form class="form transform3" action="/auth/register" method="POST">
<div class="input-container">
<label class="label" for="email"><img src="../img/ETCO-img/icons/mail.svg" height="25px"> <span
style="margin-left:25px;"></span></label>
<input placeholder="example#gmail.com" class="input" type="email" id="emaillogin" name="emaillogin">
</div><br>
<div class="input-container">
<label class="label" for="password"><img src="../img/ETCO-img/icons/lock.svg" height="25px"> <span
style="margin-left:25px;"></span></label>
<input placeholder="Passwort" class="input" type="password" id="passwordlogin" name="passwordlogin">
</div>
<div class="input-container">
<input type="hidden" name="formType" value="signin">
</div>
</form>
<button type="submit" class="bnlogin transform4">LOGIN</button>
</div>
Register Form:
<div class="registerarea transform7">
<h1 class="registerh1 ">Join us</h1>
<form class="formregister" action="/auth/register" method="POST">
<div class="input-container">
<label class="label" for="name"><img src="../img/ETCO-img/icons/user.svg" height="30px"> <span
style="margin-left:30px;"></span></label>
<input placeholder="Your Name" class="input" type="text" id="name" name="name">
</div>
<div class="input-container">
<label class="label" for="email"><img src="../img/ETCO-img/icons/mail.svg" height="25px"> <span
style="margin-left:25px;"></span></label>
<input placeholder="example#gmail.com" class="input" type="email" id="email" name="email">
</div>
<div class="input-container">
<label class="label" for="password"><img src="../img/ETCO-img/icons/lock.svg" height="25px"> <span
style="margin-left:25px;"></span></label>
<input placeholder="Passwort" class="input" type="password" id="password" name="password">
</div>
<div class="input-container">
<label class="label" for="passwordConfirm"><img src="../img/ETCO-img/icons/lock.svg" height="25px">
<span style="margin-left:25px;"></span></label>
<input placeholder="Passwort Bestätigen" class="input" type="password" id="passwordConfirm"
name="passwordConfirm">
</div>
<div class="input-container">
<input type="hidden" name="formType" value="signup">
</div>
<button type="submit" class="btnregister">Lets go</button>
</form>
So, I hope that someone of you can help me. That would be really great. Thanks in advance and best regards :D

Related

how do i get the sender email from the input form nodemailer node.js

I want the from(sender email) part to be gotten from the input but it keeps giving me the same thing as the sender and receiver the same i.e it keeps showing the user as the sender and receiver.
front end part
<p class="drop">Drop A Message</p>
<label for="name">Name:</label><br>
<input type="text" name="" id="name" class="form-inputs" placeholder="Full Name" ><br>
<label for="email">Email:</label><br>
<input type="email" name="" id="email" class="form-inputs" placeholder="Email Address" ><br>
<label for="subject">Subject:</label><br>
<input type="text" name="" id="subject" class="form-inputs" placeholder="Subject Of The Message"><br>
<label for="message">Message:</label><br>
<textarea name="" id="mainMessage" cols="30" rows="10" class="message_body" ></textarea><br>
<input type="submit" value="Send Message" class="submit_btn">
</form>
NodeJS
app.post('/', (req,res) =>{
// console.log(req.body);
const transporter = nodemailer.createTransport(smtpTransport({
service:'Gmail',
// host: 'smtp.gmail.com',
secure:false,
auth: {
user: 'horiyorrmi72#gmail.com',
pass: 'password'
}
}))
const mailOptions = {
from: req.body.email,
to : "horla_tech#protonmail.com",
subject: `${req.body.subject}`,
text : req.body.message
}
transporter.sendMail(mailOptions, (error, info) =>{
if(error){
console.log(error);
res.send('error');
}else{
console.log('Email sent' + info.response);
res.send('success');
}
})
})
app.listen(PORT, ()=> {
console.log(`server running on port: ${PORT}`);
})
Nodemailer
#nodemailer
·
Oct 22
Replying to
#horla_techs
Gmail does not allow to send email through their servers as 3rd person. If you try to use any other email address than your own as the sender, Gmail will override it.

How do I send an action in Sails.js after getting form data?

Currently, I can get the form data from my html but the action isn't being triggered after the fact. I'm trying to signup a user but my signup action file never gets reached. After I click submit, I receive no errors, but the new user isn't created either.
Any helps appreciated. Thanks :)
signup.ejs
<h2>Please Sign up.</h2>
<div class="container">
<div class="signup-form">
<ajax-form class="ajax-form" action="signup" :handle-parsing="handleParsingForm">
<div class="form-group">
<label for="username">Username</label>
<input class="form-control" id="username" type="text" :class="[formErrors.username
? 'is-invalid' : '']" v-model.trim="formData.username" placeholder="Sturgis P. Sturgeon"
autocomplete="name" focus-first>
<div class="invalid-feedback" v-if="formErrors.username">Please enter your full
name.</div>
</div>
<div class="form-group">
<label for="password">Choose a password</label>
<input class="form-control" id="password" type="password" :class=".
[formErrors.password ? 'is-invalid' : '']" v-model.trim="formData.password"
placeholder="••••••••" autocomplete="new-password">
<div class="invalid-feedback" v-if="formErrors.password">Please enter a password</div>
</div>
<div class="form-group">
<label for="confirm-password">Confirm password</label>
<input class="form-control" id="confirm-password" type="password" :class=".
[formErrors.confirmPassword ? 'is-invalid' : '']" v-model.trim="formData.confirmPassword"
placeholder="••••••••" autocomplete="new-password">
<div class="invalid-feedback" v-if="formErrors.confirmPassword">Your password
and confirmation do not match.</div>
</div>
<ajax-button type="submit" class="btn ajax-button" :class="[syncing ? 'syncing' :
'']">Submit</ajax-button>
</form>
</div>
</div>
</div>
Route
`"POST /signup": {action: 'signup'}`
Cloud Setup
`"signup":{
"verb":"POST","url":"/signup","args":["username","password"]
}`
handleParsingForm
`handleParsingForm: function() {
this.formErrors = {};
var argins = this.formData;
if(!argins.username) {
this.formErrors.username = true;
}
if(!argins.password) {
this.formErrors.password = true;
}
if(argins.password && argins.password !== argins.confirmPassword) {
this.formErrors.confirmPassword = true;
}
if (Object.keys(this.formErrors).length > 0) {
return;
}
return argins;
}
signup action
`signup: async function (inputs) {
const { username, password, confirmPassword } = inputs;
try {
let existingUser = await User.findOne({
username
})
if (existingUser) {
throw(400, 'That username is already taken.')
}
} catch (error) {
throw(error);
}
finally {
if (password === confirmPassword) {
let newUser = {username, password}
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password1, salt, (err, hash) => {
newUser.password = hash;
User.create(newUser);
});
})
// };
};
// this.req.session.userId = newUser.id;
// return newUser;
}`
The route should be
'POST /api/v1/signup': { action: 'signup' }
then rerun sails run rebuild-cloud-sdk

Hey I don't know where to start when inserting data into MySql from html form using node.js

I just want to know where to start with getting my html page to work with my back end code and database. I want to insert information into my table with a basic html login page but all i found were confusing sources, maybe i suck at googling but was wondering if someone can help telling me where i should start and what else i need to learn in order to achieve this,
The code below is what i managed to learn and implement.
var http = require('http');
var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
var url = require('url');
var pages = require('html-pages');
const css = fs.readFileSync(`${__dirname}/public/art.css`, 'utf-8');
const htmlLogin = fs.readFileSync(`${__dirname}/login.html`, 'utf-8');
const htmlSignUp = fs.readFileSync(`${__dirname}/signup.html`, 'utf-8');
//static files for login
app.use('/login', express.static('./public'));
//
app.get('/login', function(req,res,next) {
res.writeHead(200, {'Content-Type' :'text/html'});
res.write(htmlLogin);
next();
}).listen(3000);
app.get("/signup", function(req,res, next) {
res.writeHead(200, {'Content-Type':'text/html'});
res.write(htmlSignUp);
});
and here is my html page
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<link href="./signup.js">
</head>
<body>
<div class="signupBox">
<h1 id="signUp">Sign Up!</h1>
<div>
<input text="text" placeholder="First Name" name="" value="">
</div>
<div>
<input text=text" placeholder="Last Name" name="Last Name" value="">
</div>
<div>
<input text="text" placeholder="Email" name="Email" value="">
</div>
<div>
<input text="text" placeholder="Password" name="Password" value="">
</div>
<input id="submit" type="button" name="" value="Sign In">
</div>
</body>
</html>
Learning how to back end with node.js and mysql just got stuck in knowing how to do this task,
var express = require('express');
var app = express();
var session = require('express-session');
var bodyParser = require('body-parser');
var path = require('path');
var http = require('http');
var sql = require('mysql');
var fs = require('fs');
var url = require('url');
var myDB = sql.createConnection({
//properties...
host: 'localhost',
user: 'root',
password: '',
database: 'sampleDB'
});
myDB.connect(function(err) {
if (err) {
console.log('There is an error');
} else {
console.log("Connected to Database");
}
});
As what I am seeing from your code, you already setup login and signup page, it it's working than now you now to save signup data you can create new route like
app.post("/register", function(req,res, next) {
console.log('request data', req.body) // you will get signup for data here.
});
and in signup for you need to add action like -
<form method="post" action="localhost:3000/register">
<h1 id="signUp">Sign Up!</h1>
<div>
<input text="text" placeholder="First Name" name="" value="">
</div>
<div>
<input text=text" placeholder="Last Name" name="Last Name" value="">
</div>
<div>
<input text="text" placeholder="Email" name="Email" value="">
</div>
<div>
<input text="text" placeholder="Password" name="Password" value="">
</div>
<input id="submit" type="button" name="" value="Sign In">
</form>
you can do same with login verification, send login detail as in below route -
app.post("/checkLogin", function(req,res, next) {
console.log('request data', req.body) // you will get login detail here.
});
Hop this help.
Update html:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<link href="./signup.js">
</head>
<body>
<div class="signupBox">
<h1 id="signUp">Sign Up!</h1>
<form action="signup" method="POST">
<!-- it's important to define name="xx" here otherwise you'll get 'undefined' value in server side -->
<div> <input type="text" placeholder="First Name" name="firstname"> </div>
<div> <input type="text" placeholder="Last Name" name="lastname"> </div>
<div> <input type="text" placeholder="Email" name="email"> </div>
<div> <input type="password" placeholder="Password" name="password"> </div>
<input id="submit" type="button" name="" value="Sign Up">
</form>
</div>
</body>
</html>
Add this code in server side:
app.post ("/signup", function(req, res) {
// get info from form
var firstname = request.body.firstname;
var lastname = request.body.lastname;
var email = request.body.email;
var password = request.body.password;
var adduserquery = "INSERT INTO `myTable` (`firstname`,`lastname`,`email`,`password`) VALUES ('" + firstname + "', '" + lastname + "', '" + email + "', '" + password + "')";
if (email) {
// check if e-mail already exists
myDB.query('SELECT * FROM `myTable` WHERE email = ?', [email], function(error, results, fields) {
if (results.length > 0) {
response.send('This e-mail is already registered!' );
} else {
// execute query to insert data
myDB.query(adduserquery, (err, result) => {
if (err) {
return response.status(500).send(err);
}
// if insert is successful, return you to homepage
response.redirect('/home');
});
}
});
}
}
}
Thats great you have already added the express module , i woud suggest try adding form tag and give the action to the form tag , on which you want to hit eg /signup and change your input type button to submit this will workout .
<div class="signupBox">
<form action='/signup'>
<h1 id="signUp">Sign Up!</h1>
<div>
<input text="text" placeholder="First Name" name="" value="">
</div>
<div>
<input text=text" placeholder="Last Name" name="Last Name" value="">
</div>
<div>
<input text="text" placeholder="Email" name="Email" value="">
</div>
<div>
<input text="text" placeholder="Password" name="Password" value="">
</div>
<input id="submit" type="button" name="" value="Sign In">
</form>
</div>
Now if you click on submit the data can be getable inside the /signup route you have created using the req.body.NAME_VALE , once you got the value you can insert it into the database .

cannot post login form html node js

I have seen the same problem a few times on stack, but not one that seems to help me. I have a register form with a submit button that I am trying to get to submit data to MySQL and take me to the login page using node js. It successfully submits data, but will say Cannot POST / loginform.html.
Here is my index.html (register form)
<form target = "_blank" method = "post" action="//localhost:3000/LoginForm.html" onsubmit = "return validationRedirect();">
<div class="container">
<h1>Register</h1>
<p>Please fill out this form to create an account for BAH University.</p>
<hr>
<img style="float: right; margin: 40px 20px 20px 20px;" src="views/photos/furman.jpg" width="770" height="310" border = "4" />
<img style="float: right; margin: -24px 20px 0px 0px;" src="views/photos/furman1.jpg" width="770" height="310" border = "4" />
<div class="relative"><em><i>Committed to Excellence</i></em></div>
<label for="username"><b>Username</b></label>
<br>
<input type="text" style="width: 600px" placeholder="Enter Username" name="Username" required>
<br>
<label for="psw"><b>Password</b></label>
<br>
<input type="password" style="width: 600px" placeholder="Enter Password" name="Password" required>
<br>
<label for="pswrepeat"><b>Repeat Password</b></label>
<br>
<input type="password" style="width: 600px" placeholder="Repeat Password" name="Passwordrpt" required>
<br>
<label for="lastName"><b>Last Name</b></label>
<br>
<input type="text" style="width: 600px" placeholder="Last Name" name="LastName" required>
<br>
<label for="firstName"><b>First Name</b></label>
<br>
<input type="text" style="width: 600px" placeholder="First Name" name="FirstName" required>
<br>
<label for="address"><b>Address</b></label>
<br>
<input type="text" style="width: 600px" placeholder="Address" name="Address">
<br>
<label for="email"><b>Email</b></label>
<br>
<input type="text" style="width: 600px" placeholder="Email" name="Email" required>
<br>
<label for="phone"><b>Phone</b></label>
<br>
<input type="text" style="width: 600px" placeholder="Phone" name="Phone" required>
<hr>
<input name = "submit" type = "submit" value = "Register" class = "savebtn">
<!--<a><input type ="button" value = "Login" class = "registerbtn" onclick = "window.location.href ='LoginForm.html'"></a>-->
</div>
</form>
</body>
</html>
And my LoginForm.html
<form action="/LoginForm" method = "post">
<div class="container">
<h1>Login</h1>
<img src="views/photos/furman.jpg" alt="BAH" style="float: left; margin: 10px -30px 45px 20px; width:
708px;height:365px;" border = "4">
<img src="views/photos/furman1.jpg" alt="BAH" style="float: left; margin: 10px -30px 45px 20px; width:
708px;height:365px;" border = "4">
</br></br></br>
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<input type = "submit" value = "Login" class = "newlogbtn">
<a><input type="button" class="newuserbtn" value = "New User" button onclick = "window.location.href ='index.html'"></a>
</div>
<div class="container" style="background-color: white">
<bgcolor = "black"></bgcolor>
</div>
</form>
</body>
</html>
index.js
var express = require('express');
var app = express();
var router = express.Router();
var mysql = require('mysql');
var http = require('http');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: ""
})
app.use(express.static(__dirname + '/public')); //for css and photos directory
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
app.get('/LoginForm.html', function (req, res) {
res.sendFile(__dirname + '/LoginForm.html');
});
app.post('/RegisterForm', function (req, res) {
let name = req.body.Username + ' ' + req.body.Password + ' ' + req.body.Passwordrpt + ' ' + req.body.FirstName + ' ' + req.body.LastName + ' ' + req.body.Address + ' ' + req.body.Email + ' ' + req.body.Phone;
res.send(name + ' Submitted Successfully!');
//router.post('/registerform', function(req, res, next) {
con.connect(function(err) {
if (err) throw err;
console.log("connected");
var sql = "INSERT INTO persontable (Username, Password, LastName, FirstName, Address, Email, Phone)VALUES('"+req.body.Username+"','"+req.body.Password+"', '"+req.body.LastName+"', '"+req.body.FirstName+"', '"+req.body.Address+"', '"+req.body.Email+"', '"+req.body.Phone+"')";
con.query(sql, function(err, result) {
if(err) throw err;
console.log("Register information saved.");
});
});
//})
});
var server = app.listen(3000, function () {
console.log('Node server is running on port 3000..');
});
Thanks in advance for the help.
The method that worked for me was to use app.route method
https://expressjs.com/en/guide/routing.html
Eg:
app.route("url")
.get(function())
.post(function());
refer the documentation for more details on route
action="//localhost:3000/LoginForm.html"
You are trying to post to LoginForm.html.
Cannot POST / loginform.html
The error message confirms this
app.get('/LoginForm.html', function (req, res) {
You have a GET handler for that URL.
app.post('/RegisterForm', function (req, res) {
The only POST handler you have is for a different URL.
The route you are POSTing to needs to exist!
In your index.html there is :
action="//localhost:3000/LoginForm.html"
However in your server.js, your doing a get not a post on LoginForm.html
app.get('/LoginForm.html', function (req, res) {
res.sendFile(__dirname + '/LoginForm.html');
});
your error is simply in your registration form, you target the file LoginForm.html, not your RegisterForm action. If you change:
<form target = "_blank" method = "post" action="//localhost:3000/LoginForm.html" onsubmit = "return validationRedirect();">
Into
<form target = "_blank" method = "post" action="//localhost:3000/RegisterForm" onsubmit = "return validationRedirect();">
You will get a post body in your requesthandler.
:
You need to this:
app.get('/LoginForm.html', function (req, res) {
res.sendFile(__dirname + '/LoginForm.html');
});

Passport JS does not give error but, does not seem to work

I have a basic register and login app. After the user registers, and stores their information into my sequelize model, I redirect the page to the login page. When I try to login with the username and password I just made, it doesn't throw any errors, but the page goes into an endless loading phase where it eventually says The localhost page isnt working localhost didn't send any data'ERR_EMPTY_RESPONSE`
//Routes
var express = require('express');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var router = express.Router();
var db = require('../models');
router.get('/', function(req, res){
res.redirect('/friend-book');
});
router.get('/friend-book', function(req, res){
res.render('home');
});
router.get('/friend-book/profile', function(req, res){
res.render('profile');
});
router.get('/friend-book/login', function(req, res){
res.render('login');
});
router.get('/friend-book/register', function(req, res){
res.render('register');
});
router.post('/friend-book/search/user', function(req, res){
db.users.findAll({
where: {
name: req.body.name
}
}).then(function(data){
var userResults = {
people: data
}
res.render('searchedUser', userResults);
})
});
router.post('/friend-book/register', function(req, res){
console.log(req.body);
var name = req.body.name;
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
var password2 = req.body.password2;
var description = req.body.description
req.checkBody('name', 'Must type in name.').notEmpty();
req.checkBody('username', 'Must type in Username.').notEmpty();
req.checkBody('email', 'Must type in email.').notEmpty();
req.checkBody('email', 'Invalid Email').isEmail();
req.checkBody('password', 'Must type in password.').notEmpty();
req.checkBody('password2', 'Passwords do not match.').equals(req.body.password);
req.checkBody('description', 'Must type in something about yourself.').notEmpty();
var errors = req.validationErrors();
//If there are errors, render the errors
if(errors){
res.render('register', {
errors: errors
});
}else{
db.users.create(req.body).then(function(data){
console.log("register data", data);
console.log("poop", data.id);
req.session.user = {
id: data.id,
name: data.name,
username: data.username,
email: data.email,
description: data.description
};
req.flash('success_msg', 'Success! Welcome to Book Face!');
// res.render("profile", req.session.user);
res.redirect('/friend-book/login')
});
}
//***************************************************************************************************
});
passport.use(new LocalStrategy(
function(username, password, done) {
db.users.findOne({
where: {
username: username
}
}, function (err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
db.users.findById(id, function(err, user) {
done(err, user);
});
});
router.post('/friend-book/login',
passport.authenticate('local',
{
successRedirect: '/',
failureRedirect: '/friend-book/login',
failureFlash: true
}),function(req, res){
res.redirect('/friend-book/profile' + req.user.username);
}
);
module.exports = router;
//My model
var bcrypt = require('bcryptjs')
module.exports = function(sequelize, DataTypes){
var users = sequelize.define('users', {
name: DataTypes.STRING,
username: DataTypes.STRING,
password: DataTypes.STRING,
email: DataTypes.STRING,
description: DataTypes.STRING
}, {
hooks: {
beforeCreate: function(user, options){
return new Promise(function(resolve, reject){
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(user.password, salt, function(err, hash) {
if (err) {reject(err)}
user.password = hash;
console.log(user.password);
resolve();
});
});
})
}
}
});
return users;
}
//login handlebars
<div class="container">
<form action="/friend-book/login" method="POST" class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputUsername" class="sr-only">Username</label>
<input type="text" name="username" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
//Registration handlebars
<div class="container">
<h2 class="form-register-heading">Book Face Registration</h2>
{{#if errors}}
{{#each errors}}
<div class="alert alert-warning">{{msg}}</div>
{{/each}}
{{/if}}
<form action="/friend-book/register" method="POST" class="form-signin">
<div class="form-group">
<label for="inputName" class="sr-only">Name</label>
<input type="text" name="name" id="inputName" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<label for="inputUsername" class="sr-only">Username</label>
<input type="text" name="username" id="inputUsername" class="form-control" placeholder="Username">
</div>
<div class="form-group">
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label for="inputPassword2" class="sr-only">Password</label>
<input type="password" name="password2" id="inputPassword2" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email">
</div>
<div class="form-group">
<label for="inputDescription" class="sr-only">Description</label>
<input type="text" name="description" id="inputDescription" class="form-control" placeholder="Type something">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</form>
</div> <!-- /container -->
You only handle POST requests to /friend-book/login.
When you use res.redirect('/friend-book/login'), it'll redirect the user using GET method to that URL.
router.get('/friend-book/login', function (req, res) {
res.render('login');
});

Categories

Resources