2
2
3
3
var mongoose = require ( 'mongoose' ) ;
4
4
var Schema = mongoose . Schema ;
5
- var crypto = require ( 'crypto' ) ;
6
-
7
- var authTypes = [ 'github' , 'twitter' , 'facebook' , 'google' ] ;
5
+ var crypto = require ( 'crypto' ) ; < % if ( filters . oauth ) { % >
6
+ var authTypes = [ 'github' , 'twitter' , 'facebook' , 'google' ] ; < % } % >
8
7
9
8
var UserSchema = new Schema ( {
10
9
name : String ,
@@ -15,11 +14,11 @@ var UserSchema = new Schema({
15
14
} ,
16
15
hashedPassword : String ,
17
16
provider : String ,
18
- salt : String ,
19
- facebook : { } ,
20
- twitter : { } ,
21
- github : { } ,
22
- google : { }
17
+ salt : String < % if ( filters . oauth ) { % > , < % if ( filters . facebookAuth ) { % >
18
+ facebook : { } , < % } % > < % if ( filters . twitterAuth ) { % >
19
+ twitter : { } , < % } % > < % if ( filters . googleAuth ) { % >
20
+ google : { } , < % } % >
21
+ github : { } < % } % >
23
22
} ) ;
24
23
25
24
/**
@@ -63,18 +62,16 @@ UserSchema
63
62
// Validate empty email
64
63
UserSchema
65
64
. path ( 'email' )
66
- . validate ( function ( email ) {
67
- // if you are authenticating by any of the oauth strategies, don't validate
68
- if ( authTypes . indexOf ( this . provider ) !== - 1 ) return true ;
65
+ . validate ( function ( email ) { < % if ( filters . oauth ) { % >
66
+ if ( authTypes . indexOf ( this . provider ) !== - 1 ) return true ; < % } % >
69
67
return email . length ;
70
68
} , 'Email cannot be blank' ) ;
71
69
72
70
// Validate empty password
73
71
UserSchema
74
72
. path ( 'hashedPassword' )
75
- . validate ( function ( hashedPassword ) {
76
- // if you are authenticating by any of the oauth strategies, don't validate
77
- if ( authTypes . indexOf ( this . provider ) !== - 1 ) return true ;
73
+ . validate ( function ( hashedPassword ) { < % if ( filters . oauth ) { % >
74
+ if ( authTypes . indexOf ( this . provider ) !== - 1 ) return true ; < % } % >
78
75
return hashedPassword . length ;
79
76
} , 'Password cannot be blank' ) ;
80
77
@@ -104,7 +101,7 @@ UserSchema
104
101
. pre ( 'save' , function ( next ) {
105
102
if ( ! this . isNew ) return next ( ) ;
106
103
107
- if ( ! validatePresenceOf ( this . hashedPassword ) && authTypes . indexOf ( this . provider ) === - 1 )
104
+ if ( ! validatePresenceOf ( this . hashedPassword ) < % if ( filters . oauth ) { % > && authTypes . indexOf ( this . provider ) === - 1 < % } % > )
108
105
next ( new Error ( 'Invalid password' ) ) ;
109
106
else
110
107
next ( ) ;
0 commit comments