|
@@ -2,6 +2,7 @@ module.exports = function(crowi) {
|
|
|
var debug = require('debug')('crowi:models:user')
|
|
var debug = require('debug')('crowi:models:user')
|
|
|
, mongoose = require('mongoose')
|
|
, mongoose = require('mongoose')
|
|
|
, mongoosePaginate = require('mongoose-paginate')
|
|
, mongoosePaginate = require('mongoose-paginate')
|
|
|
|
|
+ , uniqueValidator = require('mongoose-unique-validator')
|
|
|
, crypto = require('crypto')
|
|
, crypto = require('crypto')
|
|
|
, async = require('async')
|
|
, async = require('async')
|
|
|
, ObjectId = mongoose.Schema.Types.ObjectId
|
|
, ObjectId = mongoose.Schema.Types.ObjectId
|
|
@@ -31,7 +32,7 @@ module.exports = function(crowi) {
|
|
|
googleId: String,
|
|
googleId: String,
|
|
|
name: { type: String },
|
|
name: { type: String },
|
|
|
username: { type: String, index: true },
|
|
username: { type: String, index: true },
|
|
|
- email: { type: String, required: true, index: true },
|
|
|
|
|
|
|
+ email: { type: String, required: true, unique: true },
|
|
|
introduction: { type: String },
|
|
introduction: { type: String },
|
|
|
password: String,
|
|
password: String,
|
|
|
apiToken: String,
|
|
apiToken: String,
|
|
@@ -46,6 +47,7 @@ module.exports = function(crowi) {
|
|
|
admin: { type: Boolean, default: 0, index: true }
|
|
admin: { type: Boolean, default: 0, index: true }
|
|
|
});
|
|
});
|
|
|
userSchema.plugin(mongoosePaginate);
|
|
userSchema.plugin(mongoosePaginate);
|
|
|
|
|
+ userSchema.plugin(uniqueValidator);
|
|
|
|
|
|
|
|
userEvent.on('activated', userEvent.onActivated);
|
|
userEvent.on('activated', userEvent.onActivated);
|
|
|
|
|
|
|
@@ -255,12 +257,13 @@ module.exports = function(crowi) {
|
|
|
debug('Delete User', this);
|
|
debug('Delete User', this);
|
|
|
|
|
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
|
|
+ const deletedLabel = `deleted_at_${now.getTime()}`;
|
|
|
|
|
|
|
|
this.status = STATUS_DELETED;
|
|
this.status = STATUS_DELETED;
|
|
|
- this.username = `deleted_at_${now.getTime()}`;
|
|
|
|
|
|
|
+ this.username = deletedLabel;
|
|
|
this.password = '';
|
|
this.password = '';
|
|
|
this.name = '';
|
|
this.name = '';
|
|
|
- this.email = 'deleted@deleted';
|
|
|
|
|
|
|
+ this.email = `${deletedLabel}@deleted`;
|
|
|
this.googleId = null;
|
|
this.googleId = null;
|
|
|
this.isGravatarEnabled = false;
|
|
this.isGravatarEnabled = false;
|
|
|
this.image = null;
|
|
this.image = null;
|