mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Tweaked emailLower and nameLower auto-setting to not set if their respective depending properties do not exist. With minimizing mongoose off, this was causing db duplicate key problems.
This commit is contained in:
parent
8480fe7836
commit
da93c45ef3
1 changed files with 6 additions and 2 deletions
|
@ -224,8 +224,10 @@ UserSchema.methods.saveActiveUser = (event, done=null) ->
|
|||
done?()
|
||||
|
||||
UserSchema.pre('save', (next) ->
|
||||
@set('emailLower', @get('email')?.toLowerCase())
|
||||
@set('nameLower', @get('name')?.toLowerCase())
|
||||
if email = @get('email')
|
||||
@set('emailLower', email.toLowerCase())
|
||||
if name = @get('name')
|
||||
@set('nameLower', name.toLowerCase())
|
||||
pwd = @get('password')
|
||||
if @get('password')
|
||||
@set('passwordHash', User.hashPassword(pwd))
|
||||
|
@ -265,6 +267,8 @@ UserSchema.statics.editableProperties = [
|
|||
|
||||
UserSchema.plugin plugins.NamedPlugin
|
||||
UserSchema.index({'stripe.subscriptionID':1}, {unique: true, sparse: true})
|
||||
UserSchema.index({'emailLower':1}, {unique: true, sparse: true, name: 'emailLower_1'})
|
||||
UserSchema.index({'nameLower':1}, {unique: true, sparse: true, name: 'nameLower_1'})
|
||||
|
||||
module.exports = User = mongoose.model('User', UserSchema)
|
||||
|
||||
|
|
Loading…
Reference in a new issue