fix some minor eslint errors

This commit is contained in:
catarak 2016-06-27 13:09:18 -04:00
parent e18a5e0941
commit 2bdd682771
3 changed files with 15 additions and 14 deletions

View File

@ -1,8 +1,8 @@
const passport = require('passport');
const GitHubStrategy = require('passport-github').Strategy;
// const GitHubStrategy = require('passport-github').Strategy;
const LocalStrategy = require('passport-local').Strategy;
import User from '../models/user'
import User from '../models/user';
passport.serializeUser((user, done) => {
done(null, user.id);
@ -18,11 +18,11 @@ passport.deserializeUser((id, done) => {
* Sign in using Email and Password.
*/
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
User.findOne({ email: email.toLowerCase() }, (err, user) => {
User.findOne({ email: email.toLowerCase() }, (err, user) => { // eslint-disable-line consistent-return
if (!user) {
return done(null, false, { msg: `Email ${email} not found.` });
}
user.comparePassword(password, (err, isMatch) => {
user.comparePassword(password, (innerErr, isMatch) => {
if (isMatch) {
return done(null, user);
}
@ -34,7 +34,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, don
/**
* Sign in with GitHub.
*/
//TODO add dotenv so I can add github login
// TODO add github login
// passport.use(new GitHubStrategy({
// clientID: process.env.GITHUB_ID,
// clientSecret: process.env.GITHUB_SECRET,

View File

@ -4,26 +4,26 @@ const bcrypt = require('bcrypt-nodejs');
const userSchema = new Schema({
name: { type: String, default: '' },
username: { type: String, required: true, unique: true},
username: { type: String, required: true, unique: true },
password: { type: String },
github: { type: String },
email: { type: String, unique: true },
tokens: Array,
admin: { type: Boolean, default: false }
}, {timestamps: true});
}, { timestamps: true });
/**
* Password hash middleware.
*/
userSchema.pre('save', function (next) {
userSchema.pre('save', function checkPassword(next) { // eslint-disable-line consistent-return
const user = this;
if (!user.isModified('password')) { return next(); }
bcrypt.genSalt(10, (err, salt) => {
bcrypt.genSalt(10, (err, salt) => { // eslint-disable-line consistent-return
if (err) { return next(err); }
bcrypt.hash(user.password, salt, null, (err, hash) => {
if (err) { return next(err); }
bcrypt.hash(user.password, salt, null, (innerErr, hash) => {
if (innerErr) { return next(innerErr); }
user.password = hash;
next();
return next();
});
});
});
@ -31,7 +31,7 @@ userSchema.pre('save', function (next) {
/**
* Helper method for validating user's password.
*/
userSchema.methods.comparePassword = function (candidatePassword, cb) {
userSchema.methods.comparePassword = function comparePassword(candidatePassword, cb) {
// userSchema.methods.comparePassword = (candidatePassword, cb) => {
bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
cb(err, isMatch);

View File

@ -58,7 +58,8 @@ app.use('/api', projects);
app.use('/', serverRoutes);
// configure passport
const passportConfig = require('./config/passport');
require('./config/passport');
// const passportConfig = require('./config/passport');
// Connect to MongoDB
// mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);