//Schema for storing accounts in database
var userSchema = new mongoose.Schema({
name: String,
email: String,
password: String
});
var User = mongoose.model("User", userSchema);
app.get("/login", function(req, res){
res.render("login");
});
app.get("/signup", function(req, res){
var errors = "";
res.render("signup", {
errors: errors
});
});
//Submission for signup page
app.post("/signup", function(req, res){
var errors = [];
if(req.body.password.length < 8){
errors.push("Password must be at least 8 characters");
}else if(req.body.password != req.body.password2){
errors.push("Passwords must match");
}
if(errors.length > 0){
res.render("signup", {
errors: errors,
name: req.body.name,
email: req.body.email,
password: req.body.password,
password2: req.body.password2
})
}else{
res.send("User created!");
}
});