Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 66 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
72f2e9f
Setting up GitHub Classroom Feedback
github-classroom[bot] Nov 22, 2022
128d71d
initial commit.
dcheris Nov 22, 2022
a32d52c
server foundation.
dcheris Nov 22, 2022
c062b88
setting routes/middleware.
dcheris Nov 22, 2022
99df937
correcting routing
dcheris Nov 22, 2022
a7c00c4
adding bootstrap css.
dcheris Nov 25, 2022
d718cea
adding bcrypt to see if I can implement it as a password security man…
dcheris Nov 25, 2022
e6cfd1b
adding a create page.
dcheris Nov 25, 2022
4362520
adding a database js file.
dcheris Nov 25, 2022
cf36dba
correcting routing files.
dcheris Nov 25, 2022
1fa1a96
completing basic routing.
dcheris Nov 25, 2022
eb2de04
completeing basic routing.
dcheris Nov 25, 2022
7781cba
completing basic routing.
dcheris Nov 25, 2022
c74a8fc
completing basic routing.
dcheris Nov 25, 2022
cf37d33
completing basic routing.
dcheris Nov 25, 2022
0f8c19a
correcting routing.
dcheris Nov 25, 2022
c88af3e
adding jade files for routes.
dcheris Nov 25, 2022
125e8dc
adding database functions.
dcheris Nov 25, 2022
43024e5
adding database
dcheris Nov 25, 2022
7f232f2
Added handlebars.
dcheris Nov 26, 2022
e9eb167
still working on CRUD.
dcheris Nov 26, 2022
8b64d7c
made a new branch to successfully route from scratch.
dcheris Nov 27, 2022
81216c6
getting forms to display data, and some css.
dcheris Nov 27, 2022
ae9dd7d
create, delete, and retrieve work in application but not in display.
dcheris Nov 28, 2022
5be1ff1
pushing new code to remote repo.
dcheris Dec 2, 2022
5b3c21e
trying to get the pages to display data.
dcheris Dec 4, 2022
14a7fe8
starting over on new branch.
dcheris Dec 4, 2022
0712b2e
Fixed routing and got anime to display.
dcheris Dec 4, 2022
8d15395
working on update functionality.
dcheris Dec 5, 2022
68cb884
added a description box, fixed css not rendering, update function is …
dcheris Dec 5, 2022
077dba4
fixing update and delete.
dcheris Dec 5, 2022
89dbbd7
fixing update for sql
dcheris Dec 5, 2022
5d12287
adding notes.
dcheris Dec 6, 2022
c096ac3
merging start-over branch into main.
dcheris Dec 6, 2022
9ffd52e
still working on the update function.
dcheris Dec 6, 2022
6a7ca08
adding ignore file.
dcheris Dec 13, 2022
5eb50ad
adding procfile.
dcheris Dec 13, 2022
cc603f6
fixed update function.
dcheris Dec 15, 2022
bf92bd7
adding views for authentication.
dcheris Dec 15, 2022
995e89c
adding mongoose foundation.
dcheris Dec 16, 2022
b2a5698
adding Heroku link to readme.
dcheris Dec 17, 2022
1fd0c9e
fixing deployment.
dcheris Dec 17, 2022
aeae34d
changing a config file.
dcheris Dec 17, 2022
166eab3
modifying ignore files.
dcheris Dec 17, 2022
3660def
correcting for deployment.
dcheris Dec 17, 2022
c700525
recommitting.
dcheris Dec 17, 2022
9245ebc
gitignore.
dcheris Dec 17, 2022
d68fa5a
config files.
dcheris Dec 17, 2022
de21298
config.
dcheris Dec 17, 2022
2f4c22c
package file.
dcheris Dec 17, 2022
d2721e3
fixing procfile.
dcheris Dec 17, 2022
07c4027
procfile.
dcheris Dec 17, 2022
438e445
config.
dcheris Dec 17, 2022
d0b190b
delete.
dcheris Dec 17, 2022
aa7f91e
config.
dcheris Dec 17, 2022
d9e0f90
config
dcheris Dec 17, 2022
5ffed83
connecting to mongoose.
dcheris Dec 18, 2022
ace6293
implementing passport.
dcheris Dec 18, 2022
8372137
working on authentication.
dcheris Dec 19, 2022
759d604
fixing for heroku.
dcheris Dec 19, 2022
f1dd8fc
adding procfile again.
dcheris Dec 19, 2022
52f7109
heroku
dcheris Dec 19, 2022
59de8ad
re-adding home page.
dcheris Dec 19, 2022
bae870a
re-adding env.
dcheris Dec 19, 2022
8a662bc
env
dcheris Dec 19, 2022
18d5f54
env2
dcheris Dec 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implementing passport.
  • Loading branch information
dcheris committed Dec 18, 2022
commit ace6293a855be41db165eb9e9c0161e5eb0eb7ba
Binary file modified .DS_Store
Binary file not shown.
120 changes: 111 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ const port = process.env.PORT || 3000;
const bcrypt = require('bcrypt');
const mongoose = require('mongoose');
const passport = require('passport');
const { use } = require('passport');
const localStrategy = require('passport-local').Strategy;
require('dotenv').config();

const User = require('./models/User.js');

// CONNECT TO DATABASE
mongoose.set("strictQuery", true);

mongoose.connect(`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.qe67sb8.mongodb.net/?retryWrites=true&w=majority/Anime Database`,(err)=>{

if(err) throw err;
console.log("DB Connected Successfully");
})
console.log("Mongoose Connected Successfully")
});


/**To serve static files such as images, CSS files, and JavaScript files, create a folders
Expand All @@ -26,7 +26,51 @@ console.log("DB Connected Successfully");
app.use(express.static('assets'))
app.use(express.static(__dirname + '/public'));

app.use(session({
secret:process.env.SESS_PASS,
resave: false,
saveUninitialized:true
}));



// INITIALIZING PASSPORT
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function (user, done) {
return done(null, user.id);
});

passport.deserializeUser(function(id,done) {
User.findById(id, function (err, user) {
return done(err,user);
});
});

passport.use(new localStrategy(function (username,password, done) {
User.findOne({username: username}, function (err, user) {
if (err)return done(err);
if(!user) return done(null,false, {message: 'Incorrect username'});

bcrypt.compare(password, user.password, function (err,res) {
if (err)return done(err);

if(res === false) return done(null, false, {message: 'Incorrect password'});
return done(null,user);
});
});
}));

// REDIRECT TO LOGIN PAGE
function isLoggedIn(req,res,next) {
if (req.isAuthenticated()) return next();
res.redirect('/login');
}

function isLoggedOut(req,res,next) {
if (!req.isAuthenticated()) return next();
res.redirect('/');
}

// VIEW ENGINE
app.set("view engine", "hbs");
Expand All @@ -35,23 +79,64 @@ app.set("view engine", "hbs");
app.use(express.json());

// For parsing application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }))
app.use(express.urlencoded({ extended: false }))


// USERS JS
/* USERS JS
app.use('/users', require('./routes/users'));
*/
// ROUTES


// SETUP ADMIN USER
app.get('/setup', async (req,res) => {
const exists = await User.exists({ username: "admin"});

if (exists) {
res.redirect('/login');
return;
};
bcrypt.genSalt(10, function (err, salt) {
if (err) return next(err);
bcrypt.hash('mypassword', salt, function (err,hash) {
if (err) return next(err);
const newAdmin = new User ({
username: "admin",
password: hash
});

newAdmin.save();
res.redirect('/login');
});
});
});

// LOGIN / LOGOUT ROUTES
app.get('/',isLoggedIn, (req, res) =>{
res.render('dashboard')
})

app.get('/',isLoggedOut,(req, res) =>{
res.render('login')
})

app.get('logout', function (req,res) {
req.logout();
res.redirect('/');
});

// ROUTE TO LOGIN PAGE
app.get('/login',function (req, res) {
res.render('login')
})

// ROUTE TO REGISTRATION PAGE
// ROUTE TO REGISTER PAGE
app.get('/register',function (req, res) {
res.render('register')
})

app.get('/dashboard',function (req, res) {
// ROUTE TO DASHBOARD PAGE
app.get('/dashboard',function (req, res) {
res.render('dashboard')
})

Expand All @@ -67,7 +152,7 @@ app.get('/display',function (req, res) {


// ROUTE TO HOME PAGE
app.get('/', function (req, res) {
app.get('/home', function (req, res) {

dbOperations.getAnime(res);
})
Expand Down Expand Up @@ -130,4 +215,21 @@ dbOperations.updateItem(updatedAnimeItem,res);

})

// CREATE A ROUTE TO POST REGISTER
app.post('/register', function (req, res){

})

// CREATE A ROUTE TO DASHBOARD REGISTER
app.post('/dashboard', function (req, res){

})

// LOGIN AUTHENTICATE
app.post('/login', passport.authenticate ('local', {
successRedirect: '/',
failureRedirect: 'login?error=true'
}));


app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Empty file removed assets
Empty file.
Binary file added images/naruto.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 5 additions & 11 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
const mongoose = require('mongoose');

const UserSchema = new mongoose.Schema({
name: {
username: {
type: String,
required: True
},
email: {
type: String,
required: True
required: true
},

password: {
type: String,
required: True
},
date: {
type: Date,
default: Date.now
required: true
}

});

const User = mongoose.model('User', UserSchema);
Expand Down
76 changes: 76 additions & 0 deletions notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*

Making the dashboard.hbs my home page so that people are forced to login or create an account. May need to copy the register page
page over so that it makes sense.
May need to make everywhere that someone would initially visit be the dashboard page.


users.js
var express = require('express');
var router = express.Router();
const {check, validationResult} = require('express-validator');


// TUTORIAL

router.use((req, res, next) => {
console.log('Request made to /users route')
next();
});

// LOGIN PAGE
router.get('/login', function(req, res, next) {
res.render('Login');
});

// REGISTER
router.get('/register', function(req, res, next) {
res.render('register');
});


// REGISTER HANDLE
router.post('/', [
check('username').notEmpty,
check('password').notEmpty,

],(req,res)=>{

let errors = validationResult(req);
console.log(errors);
if(!errors.isEmpty()) {

}

const {username, password} = req.body;


// CHECK REGISTER FIELDS
if(!username || !password ) {
errors.push({msg: 'Please fill in all fields'});
}

// CHECK PASSWORDS MATCH
if(password !== password2) {
errors.push({msg: 'Passwords do not match'});
}

// PASSWORD LENGTH
if(password.length < 8) {
errors.push({msg: 'Password must be at least 8 characters'});
}
if(errors.length > 0) {
res.render('register', {
errors,
username,
password
});
}else {
res.send('pass');
}


});

module.exports = router;
*/
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var router = express.Router();

// GET home page.
router.get('/', function(req, res, next) {
res.render('index', ('Anime Database'));
res.render('dashboard', ('Anime Database'));
});

module.exports = router;
Expand Down
71 changes: 0 additions & 71 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -1,71 +0,0 @@
var express = require('express');
var router = express.Router();
const {check, validationResult} = require('express-validator');


// TUTORIAL

router.use((req, res, next) => {
console.log('Request made to /users route')
next();
});

// LOGIN PAGE
router.get('/login', function(req, res, next) {
res.render('Login');
});

// REGISTER
router.get('/register', function(req, res, next) {
res.render('register');
});


// REGISTER HANDLE
router.post('/', [
check('name').notEmpty,
check('email').notEmpty,
check('password').notEmpty,
check('password2').notEmpty,

],(req,res)=>{

let errors = validationResult(req);
console.log(errors);
if(!errors.isEmpty()) {

}

const {name,email, password, password2} = req.body;


// CHECK REGISTER FIELDS
if(!name || !email || !password || !password2) {
errors.push({msg: 'Please fill in all fields'});
}

// CHECK PASSWORDS MATCH
if(password !== password2) {
errors.push({msg: 'Passwords do not match'});
}

// PASSWORD LENGTH
if(password.length < 8) {
errors.push({msg: 'Password must be at least 8 characters'});
}
if(errors.length > 0) {
res.render('register', {
errors,
name,
email,
password,
password2
});
}else {
res.send('pass');
}


});

module.exports = router;
Loading