Skip to content

Commit

Permalink
Level 1 - Username and Password Only
Browse files Browse the repository at this point in the history
  • Loading branch information
angelabauer authored and Angela committed Jan 21, 2019
0 parents commit 7078af8
Show file tree
Hide file tree
Showing 2,079 changed files with 270,560 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
75 changes: 75 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//jshint esversion:6
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require("mongoose");

const app = express();

app.use(express.static("public"));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({
extended: true
}));

mongoose.connect("mongodb://localhost:27017/userDB", {useNewUrlParser: true});

const userSchema = ({
email: String,
password: String
});

const User = new mongoose.model("User", userSchema);

app.get("/", function(req, res){
res.render("home");
});

app.get("/login", function(req, res){
res.render("login");
});

app.get("/register", function(req, res){
res.render("register");
});

app.post("/register", function(req, res){
const newUser = new User({
email: req.body.username,
password: req.body.password
});
newUser.save(function(err){
if (err) {
console.log(err);
} else {
res.render("secrets");
}
});
});

app.post("/login", function(req, res){
const username = req.body.username;
const password = req.body.password;

User.findOne({email: username}, function(err, foundUser){
if (err) {
console.log(err);
} else {
if (foundUser) {
if (foundUser.password === password) {
res.render("secrets");
}
}
}
});
});







app.listen(3000, function() {
console.log("Server started on port 3000.");
});
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

224 changes: 224 additions & 0 deletions node_modules/accepts/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/accepts/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7078af8

Please sign in to comment.