user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /* eslint-disable no-use-before-define */
  2. const debug = require('debug')('growi:models:user');
  3. const logger = require('@alias/logger')('growi:models:user');
  4. const mongoose = require('mongoose');
  5. const mongoosePaginate = require('mongoose-paginate-v2');
  6. const path = require('path');
  7. const uniqueValidator = require('mongoose-unique-validator');
  8. const md5 = require('md5');
  9. const ObjectId = mongoose.Schema.Types.ObjectId;
  10. const crypto = require('crypto');
  11. const { listLocaleIds } = require('@commons/util/locale-utils');
  12. module.exports = function(crowi) {
  13. const STATUS_REGISTERED = 1;
  14. const STATUS_ACTIVE = 2;
  15. const STATUS_SUSPENDED = 3;
  16. const STATUS_DELETED = 4;
  17. const STATUS_INVITED = 5;
  18. const USER_PUBLIC_FIELDS = '_id image isEmailPublished isGravatarEnabled googleId name username email introduction'
  19. + 'status lang createdAt lastLoginAt admin imageUrlCached';
  20. const PAGE_ITEMS = 50;
  21. let userEvent;
  22. // init event
  23. if (crowi != null) {
  24. userEvent = crowi.event('user');
  25. userEvent.on('activated', userEvent.onActivated);
  26. }
  27. const userSchema = new mongoose.Schema({
  28. userId: String,
  29. image: String,
  30. imageAttachment: { type: ObjectId, ref: 'Attachment' },
  31. imageUrlCached: String,
  32. isGravatarEnabled: { type: Boolean, default: false },
  33. isEmailPublished: { type: Boolean, default: true },
  34. googleId: String,
  35. name: { type: String },
  36. username: { type: String, required: true, unique: true },
  37. email: { type: String, unique: true, sparse: true },
  38. // === Crowi settings
  39. // username: { type: String, index: true },
  40. // email: { type: String, required: true, index: true },
  41. // === crowi-plus (>= 2.1.0, <2.3.0) settings
  42. // email: { type: String, required: true, unique: true },
  43. introduction: String,
  44. password: String,
  45. apiToken: { type: String, index: true },
  46. lang: {
  47. type: String,
  48. enum: listLocaleIds(),
  49. default: 'en_US',
  50. },
  51. status: {
  52. type: Number, required: true, default: STATUS_ACTIVE, index: true,
  53. },
  54. createdAt: { type: Date, default: Date.now },
  55. lastLoginAt: { type: Date },
  56. admin: { type: Boolean, default: 0, index: true },
  57. }, {
  58. toObject: {
  59. transform: (doc, ret, opt) => {
  60. // omit password
  61. delete ret.password;
  62. // omit email
  63. if (!doc.isEmailPublished) {
  64. delete ret.email;
  65. }
  66. return ret;
  67. },
  68. },
  69. });
  70. userSchema.plugin(mongoosePaginate);
  71. userSchema.plugin(uniqueValidator);
  72. function validateCrowi() {
  73. if (crowi == null) {
  74. throw new Error('"crowi" is null. Init User model with "crowi" argument first.');
  75. }
  76. }
  77. function decideUserStatusOnRegistration() {
  78. validateCrowi();
  79. const { configManager, aclService } = crowi;
  80. const isInstalled = configManager.getConfig('crowi', 'app:installed');
  81. if (!isInstalled) {
  82. return STATUS_ACTIVE; // is this ok?
  83. }
  84. // status decided depends on registrationMode
  85. const registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
  86. switch (registrationMode) {
  87. case aclService.labels.SECURITY_REGISTRATION_MODE_OPEN:
  88. return STATUS_ACTIVE;
  89. case aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED:
  90. case aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
  91. return STATUS_REGISTERED;
  92. default:
  93. return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
  94. }
  95. }
  96. function generateRandomEmail() {
  97. const randomstr = generateRandomTempPassword();
  98. return `change-it-${randomstr}@example.com`;
  99. }
  100. function generateRandomTempPassword() {
  101. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!=-_';
  102. let password = '';
  103. const len = 12;
  104. for (let i = 0; i < len; i++) {
  105. const randomPoz = Math.floor(Math.random() * chars.length);
  106. password += chars.substring(randomPoz, randomPoz + 1);
  107. }
  108. return password;
  109. }
  110. function generatePassword(password) {
  111. validateCrowi();
  112. const hasher = crypto.createHash('sha256');
  113. hasher.update(crowi.env.PASSWORD_SEED + password);
  114. return hasher.digest('hex');
  115. }
  116. function generateApiToken(user) {
  117. const hasher = crypto.createHash('sha256');
  118. hasher.update((new Date()).getTime() + user._id);
  119. return hasher.digest('base64');
  120. }
  121. userSchema.methods.isPasswordSet = function() {
  122. if (this.password) {
  123. return true;
  124. }
  125. return false;
  126. };
  127. userSchema.methods.isPasswordValid = function(password) {
  128. return this.password === generatePassword(password);
  129. };
  130. userSchema.methods.setPassword = function(password) {
  131. this.password = generatePassword(password);
  132. return this;
  133. };
  134. userSchema.methods.isEmailSet = function() {
  135. if (this.email) {
  136. return true;
  137. }
  138. return false;
  139. };
  140. userSchema.methods.updateLastLoginAt = function(lastLoginAt, callback) {
  141. this.lastLoginAt = lastLoginAt;
  142. this.save((err, userData) => {
  143. return callback(err, userData);
  144. });
  145. };
  146. userSchema.methods.updateIsGravatarEnabled = async function(isGravatarEnabled) {
  147. this.isGravatarEnabled = isGravatarEnabled;
  148. await this.updateImageUrlCached();
  149. const userData = await this.save();
  150. return userData;
  151. };
  152. userSchema.methods.updatePassword = async function(password) {
  153. this.setPassword(password);
  154. const userData = await this.save();
  155. return userData;
  156. };
  157. userSchema.methods.canDeleteCompletely = function(creatorId) {
  158. const pageCompleteDeletionAuthority = crowi.configManager.getConfig('crowi', 'security:pageCompleteDeletionAuthority');
  159. if (this.admin) {
  160. return true;
  161. }
  162. if (pageCompleteDeletionAuthority === 'anyOne' || pageCompleteDeletionAuthority == null) {
  163. return true;
  164. }
  165. if (pageCompleteDeletionAuthority === 'adminAndAuthor') {
  166. return (this._id.equals(creatorId));
  167. }
  168. return false;
  169. };
  170. userSchema.methods.updateApiToken = async function() {
  171. const self = this;
  172. self.apiToken = generateApiToken(this);
  173. const userData = await self.save();
  174. return userData;
  175. };
  176. // TODO: create UserService and transplant this method because image uploading depends on AttachmentService
  177. userSchema.methods.updateImage = async function(attachment) {
  178. this.imageAttachment = attachment;
  179. await this.updateImageUrlCached();
  180. return this.save();
  181. };
  182. // TODO: create UserService and transplant this method because image deletion depends on AttachmentService
  183. userSchema.methods.deleteImage = async function() {
  184. validateCrowi();
  185. // the 'image' field became DEPRECATED in v3.3.8
  186. this.image = undefined;
  187. if (this.imageAttachment != null) {
  188. const { attachmentService } = crowi;
  189. attachmentService.removeAttachment(this.imageAttachment._id);
  190. }
  191. this.imageAttachment = undefined;
  192. this.updateImageUrlCached();
  193. return this.save();
  194. };
  195. userSchema.methods.updateImageUrlCached = async function() {
  196. this.imageUrlCached = await this.generateImageUrlCached();
  197. };
  198. userSchema.methods.generateImageUrlCached = async function() {
  199. if (this.isGravatarEnabled) {
  200. const email = this.email || '';
  201. const hash = md5(email.trim().toLowerCase());
  202. return `https://gravatar.com/avatar/${hash}`;
  203. }
  204. if (this.image != null) {
  205. return this.image;
  206. }
  207. if (this.imageAttachment != null && this.imageAttachment._id != null) {
  208. const Attachment = crowi.model('Attachment');
  209. const imageAttachment = await Attachment.findById(this.imageAttachment);
  210. return imageAttachment.filePathProxied;
  211. }
  212. return '/images/icons/user.svg';
  213. };
  214. userSchema.methods.updateGoogleId = function(googleId, callback) {
  215. this.googleId = googleId;
  216. this.save((err, userData) => {
  217. return callback(err, userData);
  218. });
  219. };
  220. userSchema.methods.deleteGoogleId = function(callback) {
  221. return this.updateGoogleId(null, callback);
  222. };
  223. userSchema.methods.activateInvitedUser = async function(username, name, password) {
  224. this.setPassword(password);
  225. this.name = name;
  226. this.username = username;
  227. this.status = STATUS_ACTIVE;
  228. this.save((err, userData) => {
  229. userEvent.emit('activated', userData);
  230. if (err) {
  231. throw new Error(err);
  232. }
  233. return userData;
  234. });
  235. };
  236. userSchema.methods.removeFromAdmin = async function() {
  237. debug('Remove from admin', this);
  238. this.admin = 0;
  239. return this.save();
  240. };
  241. userSchema.methods.makeAdmin = async function() {
  242. debug('Admin', this);
  243. this.admin = 1;
  244. return this.save();
  245. };
  246. userSchema.methods.asyncMakeAdmin = async function(callback) {
  247. this.admin = 1;
  248. return this.save();
  249. };
  250. userSchema.methods.statusActivate = async function() {
  251. debug('Activate User', this);
  252. this.status = STATUS_ACTIVE;
  253. const userData = await this.save();
  254. return userEvent.emit('activated', userData);
  255. };
  256. userSchema.methods.statusSuspend = async function() {
  257. debug('Suspend User', this);
  258. this.status = STATUS_SUSPENDED;
  259. if (this.email === undefined || this.email === null) { // migrate old data
  260. this.email = '-';
  261. }
  262. if (this.name === undefined || this.name === null) { // migrate old data
  263. this.name = `-${Date.now()}`;
  264. }
  265. if (this.username === undefined || this.usename === null) { // migrate old data
  266. this.username = '-';
  267. }
  268. return this.save();
  269. };
  270. userSchema.methods.statusDelete = async function() {
  271. debug('Delete User', this);
  272. const now = new Date();
  273. const deletedLabel = `deleted_at_${now.getTime()}`;
  274. this.status = STATUS_DELETED;
  275. this.username = deletedLabel;
  276. this.password = '';
  277. this.name = '';
  278. this.email = `${deletedLabel}@deleted`;
  279. this.googleId = null;
  280. this.isGravatarEnabled = false;
  281. this.image = null;
  282. return this.save();
  283. };
  284. userSchema.methods.updateGoogleId = function(googleId, callback) {
  285. this.googleId = googleId;
  286. this.save((err, userData) => {
  287. return callback(err, userData);
  288. });
  289. };
  290. userSchema.statics.getUserStatusLabels = function() {
  291. const userStatus = {};
  292. userStatus[STATUS_REGISTERED] = 'Approval Pending';
  293. userStatus[STATUS_ACTIVE] = 'Active';
  294. userStatus[STATUS_SUSPENDED] = 'Suspended';
  295. userStatus[STATUS_DELETED] = 'Deleted';
  296. userStatus[STATUS_INVITED] = 'Invited';
  297. return userStatus;
  298. };
  299. userSchema.statics.isEmailValid = function(email, callback) {
  300. validateCrowi();
  301. const whitelist = crowi.configManager.getConfig('crowi', 'security:registrationWhiteList');
  302. if (Array.isArray(whitelist) && whitelist.length > 0) {
  303. return whitelist.some((allowedEmail) => {
  304. const re = new RegExp(`${allowedEmail}$`);
  305. return re.test(email);
  306. });
  307. }
  308. return true;
  309. };
  310. userSchema.statics.findUsers = function(options, callback) {
  311. const sort = options.sort || { status: 1, createdAt: 1 };
  312. this.find()
  313. .sort(sort)
  314. .skip(options.skip || 0)
  315. .limit(options.limit || 21)
  316. .exec((err, userData) => {
  317. callback(err, userData);
  318. });
  319. };
  320. userSchema.statics.findAllUsers = function(option) {
  321. // eslint-disable-next-line no-param-reassign
  322. option = option || {};
  323. const sort = option.sort || { createdAt: -1 };
  324. const fields = option.fields || USER_PUBLIC_FIELDS;
  325. let status = option.status || [STATUS_ACTIVE, STATUS_SUSPENDED];
  326. if (!Array.isArray(status)) {
  327. status = [status];
  328. }
  329. return this.find()
  330. .or(status.map((s) => { return { status: s } }))
  331. .select(fields)
  332. .sort(sort);
  333. };
  334. userSchema.statics.findUsersByIds = function(ids, option) {
  335. // eslint-disable-next-line no-param-reassign
  336. option = option || {};
  337. const sort = option.sort || { createdAt: -1 };
  338. const status = option.status || STATUS_ACTIVE;
  339. const fields = option.fields || USER_PUBLIC_FIELDS;
  340. return this.find({ _id: { $in: ids }, status })
  341. .select(fields)
  342. .sort(sort);
  343. };
  344. userSchema.statics.findAdmins = async function() {
  345. return this.find({ admin: true });
  346. };
  347. userSchema.statics.findUsersByPartOfEmail = function(emailPart, options) {
  348. const status = options.status || null;
  349. const emailPartRegExp = new RegExp(emailPart.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'));
  350. const User = this;
  351. return new Promise((resolve, reject) => {
  352. const query = User.find({ email: emailPartRegExp }, USER_PUBLIC_FIELDS);
  353. if (status) {
  354. query.and({ status });
  355. }
  356. query
  357. .limit(PAGE_ITEMS + 1)
  358. .exec((err, userData) => {
  359. if (err) {
  360. return reject(err);
  361. }
  362. return resolve(userData);
  363. });
  364. });
  365. };
  366. userSchema.statics.findUserByUsername = function(username) {
  367. if (username == null) {
  368. return Promise.resolve(null);
  369. }
  370. return this.findOne({ username });
  371. };
  372. userSchema.statics.findUserByApiToken = function(apiToken) {
  373. if (apiToken == null) {
  374. return Promise.resolve(null);
  375. }
  376. return this.findOne({ apiToken });
  377. };
  378. userSchema.statics.findUserByGoogleId = function(googleId, callback) {
  379. if (googleId == null) {
  380. callback(null, null);
  381. }
  382. this.findOne({ googleId }, (err, userData) => {
  383. callback(err, userData);
  384. });
  385. };
  386. userSchema.statics.findUserByUsernameOrEmail = function(usernameOrEmail, password, callback) {
  387. this.findOne()
  388. .or([
  389. { username: usernameOrEmail },
  390. { email: usernameOrEmail },
  391. ])
  392. .exec((err, userData) => {
  393. callback(err, userData);
  394. });
  395. };
  396. userSchema.statics.findUserByEmailAndPassword = function(email, password, callback) {
  397. const hashedPassword = generatePassword(password);
  398. this.findOne({ email, password: hashedPassword }, (err, userData) => {
  399. callback(err, userData);
  400. });
  401. };
  402. userSchema.statics.isUserCountExceedsUpperLimit = async function() {
  403. const { configManager } = crowi;
  404. const userUpperLimit = configManager.getConfig('crowi', 'security:userUpperLimit');
  405. const activeUsers = await this.countListByStatus(STATUS_ACTIVE);
  406. if (userUpperLimit <= activeUsers) {
  407. return true;
  408. }
  409. return false;
  410. };
  411. userSchema.statics.countListByStatus = async function(status) {
  412. const User = this;
  413. const conditions = { status };
  414. // TODO count は非推奨。mongoose のバージョンアップ後に countDocuments に変更する。
  415. return User.count(conditions);
  416. };
  417. userSchema.statics.isRegisterableUsername = async function(username) {
  418. let usernameUsable = true;
  419. const userData = await this.findOne({ username });
  420. if (userData) {
  421. usernameUsable = false;
  422. }
  423. return usernameUsable;
  424. };
  425. userSchema.statics.isRegisterable = function(email, username, callback) {
  426. const User = this;
  427. let emailUsable = true;
  428. let usernameUsable = true;
  429. // username check
  430. this.findOne({ username }, (err, userData) => {
  431. if (userData) {
  432. usernameUsable = false;
  433. }
  434. // email check
  435. User.findOne({ email }, (err, userData) => {
  436. if (userData) {
  437. emailUsable = false;
  438. }
  439. if (!emailUsable || !usernameUsable) {
  440. return callback(false, { email: emailUsable, username: usernameUsable });
  441. }
  442. return callback(true, {});
  443. });
  444. });
  445. };
  446. userSchema.statics.resetPasswordByRandomString = async function(id) {
  447. const user = await this.findById(id);
  448. if (!user) {
  449. throw new Error('User not found');
  450. }
  451. const newPassword = generateRandomTempPassword();
  452. user.setPassword(newPassword);
  453. await user.save();
  454. return newPassword;
  455. };
  456. userSchema.statics.createUserByEmail = async function(email) {
  457. const configManager = crowi.configManager;
  458. const User = this;
  459. const newUser = new User();
  460. /* eslint-disable newline-per-chained-call */
  461. const tmpUsername = `temp_${Math.random().toString(36).slice(-16)}`;
  462. const password = Math.random().toString(36).slice(-16);
  463. /* eslint-enable newline-per-chained-call */
  464. newUser.username = tmpUsername;
  465. newUser.email = email;
  466. newUser.setPassword(password);
  467. newUser.createdAt = Date.now();
  468. newUser.status = STATUS_INVITED;
  469. const globalLang = configManager.getConfig('crowi', 'app:globalLang');
  470. if (globalLang != null) {
  471. newUser.lang = globalLang;
  472. }
  473. try {
  474. const newUserData = await newUser.save();
  475. return {
  476. email,
  477. password,
  478. user: newUserData,
  479. };
  480. }
  481. catch (err) {
  482. return {
  483. email,
  484. };
  485. }
  486. };
  487. userSchema.statics.createUsersByEmailList = async function(emailList) {
  488. const User = this;
  489. // check exists and get list of try to create
  490. const existingUserList = await User.find({ email: { $in: emailList }, userStatus: { $ne: STATUS_DELETED } });
  491. const existingEmailList = existingUserList.map((user) => { return user.email });
  492. const creationEmailList = emailList.filter((email) => { return existingEmailList.indexOf(email) === -1 });
  493. const createdUserList = [];
  494. await Promise.all(creationEmailList.map(async(email) => {
  495. const createdEmail = await this.createUserByEmail(email);
  496. createdUserList.push(createdEmail);
  497. }));
  498. return { existingEmailList, createdUserList };
  499. };
  500. userSchema.statics.sendEmailbyUserList = async function(userList) {
  501. const { appService, mailService } = crowi;
  502. const appTitle = appService.getAppTitle();
  503. await Promise.all(userList.map(async(user) => {
  504. if (user.password == null) {
  505. return;
  506. }
  507. try {
  508. return mailService.send({
  509. to: user.email,
  510. subject: `Invitation to ${appTitle}`,
  511. template: path.join(crowi.localeDir, 'en_US/admin/userInvitation.txt'),
  512. vars: {
  513. email: user.email,
  514. password: user.password,
  515. url: crowi.appService.getSiteUrl(),
  516. appTitle,
  517. },
  518. });
  519. }
  520. catch (err) {
  521. return debug('fail to send email: ', err);
  522. }
  523. }));
  524. };
  525. userSchema.statics.createUsersByInvitation = async function(emailList, toSendEmail) {
  526. validateCrowi();
  527. if (!Array.isArray(emailList)) {
  528. debug('emailList is not array');
  529. }
  530. const afterWorkEmailList = await this.createUsersByEmailList(emailList);
  531. if (toSendEmail) {
  532. await this.sendEmailbyUserList(afterWorkEmailList.createdUserList);
  533. }
  534. return afterWorkEmailList;
  535. };
  536. userSchema.statics.createUserByEmailAndPasswordAndStatus = async function(name, username, email, password, lang, status, callback) {
  537. const User = this;
  538. const newUser = new User();
  539. // check user upper limit
  540. const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
  541. if (isUserCountExceedsUpperLimit) {
  542. const err = new UserUpperLimitException();
  543. return callback(err);
  544. }
  545. // check email duplication because email must be unique
  546. const count = await this.count({ email });
  547. if (count > 0) {
  548. // eslint-disable-next-line no-param-reassign
  549. email = generateRandomEmail();
  550. }
  551. newUser.name = name;
  552. newUser.username = username;
  553. newUser.email = email;
  554. if (password != null) {
  555. newUser.setPassword(password);
  556. }
  557. const configManager = crowi.configManager;
  558. const globalLang = configManager.getConfig('crowi', 'app:globalLang');
  559. if (globalLang != null) {
  560. newUser.lang = globalLang;
  561. }
  562. if (lang != null) {
  563. newUser.lang = lang;
  564. }
  565. newUser.createdAt = Date.now();
  566. newUser.status = status || decideUserStatusOnRegistration();
  567. newUser.save((err, userData) => {
  568. if (err) {
  569. logger.error('createUserByEmailAndPasswordAndStatus failed: ', err);
  570. return callback(err);
  571. }
  572. if (userData.status === STATUS_ACTIVE) {
  573. userEvent.emit('activated', userData);
  574. }
  575. return callback(err, userData);
  576. });
  577. };
  578. /**
  579. * A wrapper function of createUserByEmailAndPasswordAndStatus with callback
  580. *
  581. */
  582. userSchema.statics.createUserByEmailAndPassword = function(name, username, email, password, lang, callback) {
  583. this.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, undefined, callback);
  584. };
  585. /**
  586. * A wrapper function of createUserByEmailAndPasswordAndStatus
  587. *
  588. * @return {Promise<User>}
  589. */
  590. userSchema.statics.createUser = function(name, username, email, password, lang, status) {
  591. const User = this;
  592. return new Promise((resolve, reject) => {
  593. User.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, status, (err, userData) => {
  594. if (err) {
  595. return reject(err);
  596. }
  597. return resolve(userData);
  598. });
  599. });
  600. };
  601. userSchema.statics.getUsernameByPath = function(path) {
  602. let username = null;
  603. const match = path.match(/^\/user\/([^/]+)\/?/);
  604. if (match) {
  605. username = match[1];
  606. }
  607. return username;
  608. };
  609. class UserUpperLimitException {
  610. constructor() {
  611. this.name = this.constructor.name;
  612. }
  613. }
  614. userSchema.statics.STATUS_REGISTERED = STATUS_REGISTERED;
  615. userSchema.statics.STATUS_ACTIVE = STATUS_ACTIVE;
  616. userSchema.statics.STATUS_SUSPENDED = STATUS_SUSPENDED;
  617. userSchema.statics.STATUS_DELETED = STATUS_DELETED;
  618. userSchema.statics.STATUS_INVITED = STATUS_INVITED;
  619. userSchema.statics.USER_PUBLIC_FIELDS = USER_PUBLIC_FIELDS;
  620. userSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
  621. return mongoose.model('User', userSchema);
  622. };