I am creating a site with login authentication using node.js, express and Passport. For the registration page, I want the site to send a message when the username is already executed, right now the following code is working fine, but I would like to add a warning message with a slightly red background and highlighted text.
Code for signup.jade:
div(class="col-lg-12") form(class="form" method="post" action="/SignupForm") -if(message) div#note #{message} label(class="col-lg-12") username input(type="text" name="username") br label(class="col-lg-12") password input(type="password" name="password") br label(class="col-lg-12") email input(type="email" name="email") br input(type="submit" value="Signup")
For my routes my code is as follows (it is inside module.exports)
app.get('/SignupForm', function(req,res){ res.render('SignUp', {message: req.flash('signupMessage')}); }); app.post('/SignupForm', passport.authenticate('localSignup', { successRedirect: '/', failureRedirect: '/SignupForm', failureFlash: true }));
And finally, for the Passport.js file, this is the code:
passport.use('localSignup', new localStrategy({ usernameField: 'username', passwordField: 'password', passReqToCallback: true }, function (req, username, password, done) { process.nextTick(function () { User.findOne({'username' : username}, function (err, user) { if (err) return done(err); else if (user){ return done(null, false, req.flash('signupMessage', 'User already taken')); } else { var newUser = new User({username: username, password: password); newUser.save(function (err) { if (err) throw err; return done (null, newUser); }); } }); }); }) );
By the way, I already tried using a message for bootstrap, like this:
.alert.alert-danger !{ message }
But it immediately shows the highlighted area inside the registration page, although the message has not yet been sent.