Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 969c691

Browse files
committed
instead of relying on previously hard-coded passport strategies we can assume that any user entry which have no provider set is a local strategy and apply our validations only on those empty provider members of the user model object
1 parent ee63f17 commit 969c691

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

app/models/user.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
var mongoose = require('mongoose'),
77
Schema = mongoose.Schema,
8-
crypto = require('crypto'),
9-
authTypes = ['github', 'twitter', 'facebook', 'google'];
10-
8+
crypto = require('crypto');
119

1210
/**
1311
* User Schema
@@ -49,25 +47,25 @@ var validatePresenceOf = function(value) {
4947
// the below 4 validations only apply if you are signing up traditionally
5048
UserSchema.path('name').validate(function(name) {
5149
// if you are authenticating by any of the oauth strategies, don't validate
52-
if (authTypes.indexOf(this.provider) !== -1) return true;
50+
if (!this.provider) return true;
5351
return name.length;
5452
}, 'Name cannot be blank');
5553

5654
UserSchema.path('email').validate(function(email) {
5755
// if you are authenticating by any of the oauth strategies, don't validate
58-
if (authTypes.indexOf(this.provider) !== -1) return true;
56+
if (!this.provider) return true;
5957
return email.length;
6058
}, 'Email cannot be blank');
6159

6260
UserSchema.path('username').validate(function(username) {
6361
// if you are authenticating by any of the oauth strategies, don't validate
64-
if (authTypes.indexOf(this.provider) !== -1) return true;
62+
if (!this.provider) return true;
6563
return username.length;
6664
}, 'Username cannot be blank');
6765

6866
UserSchema.path('hashed_password').validate(function(hashed_password) {
6967
// if you are authenticating by any of the oauth strategies, don't validate
70-
if (authTypes.indexOf(this.provider) !== -1) return true;
68+
if (!this.provider) return true;
7169
return hashed_password.length;
7270
}, 'Password cannot be blank');
7371

@@ -78,7 +76,7 @@ UserSchema.path('hashed_password').validate(function(hashed_password) {
7876
UserSchema.pre('save', function(next) {
7977
if (!this.isNew) return next();
8078

81-
if (!validatePresenceOf(this.password) && authTypes.indexOf(this.provider) === -1)
79+
if (!validatePresenceOf(this.password) && !this.provider)
8280
next(new Error('Invalid password'));
8381
else
8482
next();

0 commit comments

Comments
 (0)