-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2931ac3
commit 575c765
Showing
27 changed files
with
504 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//import localStrategy from `passport-local`; | ||
const localStrategy = require(`passport-local`).Strategy; | ||
const bcrypt = require(`bcryptjs`); | ||
const User = require(`../models/User`); | ||
|
||
module.exports = (passport) => { | ||
passport.use( | ||
new localStrategy({ usernameField: `email` }, (email, password, done) => { | ||
User.findByEmail(email) | ||
.then((user) => { | ||
if (!user) { | ||
return done(null, false, { message: "account not found" }); | ||
} | ||
|
||
bcrypt.compare(password, user.password, (err, samePsw) => { | ||
if (samePsw) { | ||
return done(null, user); | ||
} else { | ||
return done(null, false, { message: "Incorrect password" }); | ||
} | ||
}); | ||
}) | ||
.catch(() => {}); | ||
}) | ||
); | ||
|
||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser((id, done) => { | ||
User.findByPk(id) | ||
.then((user) => { | ||
done(null, user); | ||
}) | ||
.catch((e) => { | ||
console.log("err: " + e); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const connection = require("../db/connection"); | ||
const mysql = require("mysql"); | ||
|
||
const create = (user) => { | ||
return new Promise((resolve, reject) => { | ||
sql = `insert into users (name, email, isAdmin, password ) values ('${user.name}', '${user.email}', ${user.isAdmin}, '${user.password}')`; | ||
|
||
connection.query(sql, (err, result) => { | ||
err ? reject(err) : resolve(result); | ||
}); | ||
}); | ||
}; | ||
|
||
const findByEmail = (email) => { | ||
return new Promise((resolve, reject) => { | ||
sql = `select * from users where email = ${mysql.escape(email)}`; | ||
|
||
connection.query(sql, (err, result) => { | ||
err ? reject(err) : resolve(result[0]); | ||
}); | ||
}); | ||
}; | ||
|
||
const findByPk = (id) => { | ||
return new Promise((resolve, reject) => { | ||
sql = `select * from users where id = ${mysql.escape(id)}`; | ||
|
||
connection.query(sql, (err, result) => { | ||
err ? reject(err) : resolve(result[0]); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
create: create, | ||
findByEmail: findByEmail, | ||
findByPk: findByPk, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
function w3_open() { | ||
document.getElementById("main").style.marginLeft = "25%"; | ||
document.getElementById("mySidebar").style.width = "25%"; | ||
document.getElementById("main").style.marginLeft = "23%"; | ||
document.getElementById("mySidebar").style.width = "23%"; | ||
document.getElementById("mySidebar").style.display = "block"; | ||
document.getElementById("openNav").style.display = "none"; | ||
localStorage.setItem("openSidebar", true); | ||
} | ||
|
||
function w3_close() { | ||
document.getElementById("main").style.marginLeft = "0%"; | ||
document.getElementById("mySidebar").style.display = "none"; | ||
document.getElementById("openNav").style.display = "inline-block"; | ||
localStorage.setItem("openSidebar", false); | ||
} | ||
|
||
if (localStorage.getItem("openSidebar") === "true") { | ||
w3_open(); | ||
} else { | ||
w3_close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.