diff --git a/config/passport.js b/config/passport.js index 04b02132b1..32b495a0f9 100755 --- a/config/passport.js +++ b/config/passport.js @@ -17,13 +17,10 @@ passport.deserializeUser(function(id, done) { }); }); -passport.use(new LocalStrategy({ - usernameField: 'email' - }, - function(email, password, done) { - User.findOne({ email: email }, function(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: 'Unknown user ' + email }); } + if (!user) { return done(null, false, { message: 'Unknown user ' + username }); } user.comparePassword(password, function(err, isMatch) { if (err) return done(err); if(isMatch) { @@ -123,37 +120,27 @@ passport.use(new GoogleStrategy({ callbackURL: config.google.callbackUrl }, function(accessToken, refreshToken, profile, done) { - console.log(accessToken); - console.log(profile); User.findOne({ google: profile.id }, function(err, existingUser) { - - if (err) { - done(err); - } + if (err) done(err); if (existingUser) { return done(null, existingUser); } var user = new User({ - firstName: profile.name.givenName, - lastName: profile.name.familyName, + name: profile.displayName, email: profile._json.email, + gender: profile._json.gender, + picture: profile._json.picture, provider: profile.provider }); + user.tokens.google = accessToken; user[profile.provider] = profile.id; user.save(function(err) { - if (err) { - if (err.code === 11000) { - // Found another user with the same email - - } - } - done(null, user); + done(err, user); }); - }); } )); @@ -177,4 +164,4 @@ exports.ensureAdmin = function ensureAdmin(req, res, next) { else res.send(403); }; -}; \ No newline at end of file +}; diff --git a/controllers/user.js b/controllers/user.js index 3e439c5d85..0e13f7410e 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -66,7 +66,7 @@ exports.getSignup = function(req, res) { exports.postSignup = function(req, res) { var user = new User({ - email: req.body.email, + username: req.body.email, password: req.body.password, confirmPassword: req.body.confirmPassword }); diff --git a/models/User.js b/models/User.js index 1ea1ab6653..e7e9df5123 100644 --- a/models/User.js +++ b/models/User.js @@ -16,7 +16,7 @@ var userSchema = new mongoose.Schema({ provider: String, facebook: String, google: String, - isAdmin: Boolean, + isAdmin: Boolean }); userSchema.path('password').validate(function(password) { @@ -24,20 +24,11 @@ userSchema.path('password').validate(function(password) { return password.length; }, 'Password cannot be blank'); -userSchema.path('email').validate(function(email) { +userSchema.path('username').validate(function(username) { if (this.provider) return true; - return email.length; -}, 'Email cannot be blank'); + return username.length; +}, 'Username cannot be blank'); -userSchema.path('firstName').validate(function(firstName) { - if (this.provider) return true; - return firstName.length; -}, 'First Name cannot be blank'); - -userSchema.path('lastName').validate(function(lastName) { - if (this.provider) return true; - return lastName.length; -}, 'Last Name cannot be blank'); userSchema.pre('save', function(next) { var user = this;