@@ -81,7 +81,7 @@ UserSchema
81
81
// returns only first found email
82
82
// TODO: in case of multiple emails, should prioritize confirmed ones
83
83
return this . credentials . filter ( function ( c ) {
84
- return c . type === 'email' ;
84
+ return c . type === 'email' ;
85
85
86
86
} ) [ 0 ] . value ;
87
87
} ) ;
@@ -90,21 +90,21 @@ UserSchema
90
90
. virtual ( 'emails' )
91
91
. get ( function ( ) {
92
92
return this . credentials
93
- . filter ( function ( c ) { return c . type === 'email' ; } )
93
+ . filter ( function ( c ) { return c . type === 'email' ; } )
94
94
. map ( function ( c ) { return c . value ; } ) ;
95
95
96
96
} ) ;
97
97
98
98
UserSchema
99
99
. pre ( 'save' , function ( next ) { < % if ( filters . oauth ) { % >
100
100
if ( ! this . localEnabled ) {
101
- if ( Object . keys ( this . strategies ) . length === 0 ) {
101
+ if ( Object . keys ( this . strategies ) . length === 0 ) {
102
102
return next ( new Error ( 'No connected accounts' ) ) ;
103
103
}
104
104
return next ( ) ;
105
105
} < % } % >
106
106
107
- mongoose . models [ ' User' ] < % if ( filters . oauth ) { % >
107
+ mongoose . models . User < % if ( filters . oauth ) { % >
108
108
. find ( { localEnabled :true } ) < % } % >
109
109
. where ( 'credentials.type' ) . equals ( 'email' )
110
110
. where ( 'credentials.value' ) . equals ( this . email )
@@ -132,15 +132,15 @@ UserSchema.methods = {
132
132
} ,
133
133
confirm : function ( emailOrPhone , cb ) {
134
134
this . credentials . forEach ( function ( c ) {
135
- if ( c . value === emailOrPhone ) {
135
+ if ( c . value === emailOrPhone ) {
136
136
c . confirmed = true ;
137
137
}
138
138
} ) ;
139
139
this . save ( cb ) ;
140
140
} ,
141
141
changeEmail : function ( oldEmail , newEmail , cb ) {
142
142
this . credentials . forEach ( function ( c ) {
143
- if ( c . value === oldEmail ) {
143
+ if ( c . value === oldEmail ) {
144
144
c . value = newEmail ;
145
145
c . confirmed = false ;
146
146
}
@@ -177,14 +177,14 @@ UserSchema.statics = {
177
177
var dataFormatted ;
178
178
dataFormatted = [ ] ;
179
179
180
- if ( data . email != null ) {
180
+ if ( data . email !== null ) {
181
181
dataFormatted . push ( {
182
182
'credentials.type' : 'email' ,
183
183
'credentials.value' : data . email
184
184
} ) ;
185
185
}
186
186
187
- if ( data . phone != null ) {
187
+ if ( data . phone !== null ) {
188
188
dataFormatted . push ( {
189
189
'credentials.type' : 'phone' ,
190
190
'credentials.value' : data . phone
@@ -195,11 +195,11 @@ UserSchema.statics = {
195
195
. or ( dataFormatted )
196
196
. exec ( function ( err , users ) {
197
197
if ( err ) return cb ( err ) ;
198
- if ( users . length === 0 ) return cb ( null , null ) ;
198
+ if ( users . length === 0 ) return cb ( null , null ) ;
199
199
200
200
cb ( null , users ) ;
201
201
} ) ;
202
202
} < % } % >
203
203
} ;
204
204
205
- module . exports = mongoose . model ( 'User' , UserSchema ) ;
205
+ module . exports = mongoose . model ( 'User' , UserSchema ) ;
0 commit comments