user.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. module.exports = function(crowi) {
  2. const debug = require('debug')('growi:models:user')
  3. , path = require('path')
  4. , mongoose = require('mongoose')
  5. , mongoosePaginate = require('mongoose-paginate')
  6. , uniqueValidator = require('mongoose-unique-validator')
  7. , crypto = require('crypto')
  8. , async = require('async')
  9. , STATUS_REGISTERED = 1
  10. , STATUS_ACTIVE = 2
  11. , STATUS_SUSPENDED = 3
  12. , STATUS_DELETED = 4
  13. , STATUS_INVITED = 5
  14. , USER_PUBLIC_FIELDS = '_id image isEmailPublished isGravatarEnabled googleId name username email introduction status lang createdAt admin' // TODO: どこか別の場所へ...
  15. , LANG_EN = 'en'
  16. , LANG_EN_US = 'en-US'
  17. , LANG_EN_GB = 'en-GB'
  18. , LANG_JA = 'ja'
  19. , PAGE_ITEMS = 50
  20. let userSchema;
  21. let userEvent;
  22. // init event
  23. if (crowi != null) {
  24. userEvent = crowi.event('user');
  25. userEvent.on('activated', userEvent.onActivated);
  26. }
  27. userSchema = new mongoose.Schema({
  28. userId: String,
  29. image: String,
  30. isGravatarEnabled: { type: Boolean, default: false },
  31. isEmailPublished: { type: Boolean, default: true },
  32. googleId: String,
  33. name: { type: String },
  34. username: { type: String, required: true, unique: true },
  35. email: { type: String, unique: true, sparse: true },
  36. //// The official settings
  37. // username: { type: String, index: true },
  38. // email: { type: String, required: true, index: true },
  39. //// crowi-plus (>= 2.1.0, <2.3.0) settings
  40. // email: { type: String, required: true, unique: true },
  41. introduction: { type: String },
  42. password: String,
  43. apiToken: String,
  44. lang: {
  45. type: String,
  46. enum: Object.keys(getLanguageLabels()).map((k) => eval(k)),
  47. default: LANG_EN_US
  48. },
  49. status: { type: Number, required: true, default: STATUS_ACTIVE, index: true },
  50. createdAt: { type: Date, default: Date.now },
  51. lastLoginAt: { type: Date },
  52. admin: { type: Boolean, default: 0, index: true }
  53. });
  54. userSchema.plugin(mongoosePaginate);
  55. userSchema.plugin(uniqueValidator);
  56. function validateCrowi() {
  57. if (crowi == null) {
  58. throw new Error('"crowi" is null. Init User model with "crowi" argument first.');
  59. }
  60. }
  61. function decideUserStatusOnRegistration() {
  62. validateCrowi();
  63. var Config = crowi.model('Config'),
  64. config = crowi.getConfig();
  65. if (!config.crowi) {
  66. return STATUS_ACTIVE; // is this ok?
  67. }
  68. // status decided depends on registrationMode
  69. switch (config.crowi['security:registrationMode']) {
  70. case Config.SECURITY_REGISTRATION_MODE_OPEN:
  71. return STATUS_ACTIVE;
  72. case Config.SECURITY_REGISTRATION_MODE_RESTRICTED:
  73. case Config.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
  74. return STATUS_REGISTERED;
  75. default:
  76. return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
  77. }
  78. }
  79. function generateRandomEmail() {
  80. const randomstr = generateRandomTempPassword();
  81. return `change-it-${randomstr}@example.com`;
  82. }
  83. function generateRandomTempPassword() {
  84. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!=-_';
  85. var password = '';
  86. var len = 12;
  87. for (var i = 0; i < len; i++) {
  88. var randomPoz = Math.floor(Math.random() * chars.length);
  89. password += chars.substring(randomPoz, randomPoz+1);
  90. }
  91. return password;
  92. }
  93. function generatePassword(password) {
  94. validateCrowi();
  95. var hasher = crypto.createHash('sha256');
  96. hasher.update(crowi.env.PASSWORD_SEED + password);
  97. return hasher.digest('hex');
  98. }
  99. function generateApiToken(user) {
  100. var hasher = crypto.createHash('sha256');
  101. hasher.update((new Date).getTime() + user._id);
  102. return hasher.digest('base64');
  103. }
  104. function getLanguageLabels() {
  105. var lang = {};
  106. lang.LANG_EN = LANG_EN;
  107. lang.LANG_EN_US = LANG_EN_US;
  108. lang.LANG_EN_GB = LANG_EN_GB;
  109. lang.LANG_JA = LANG_JA;
  110. return lang;
  111. }
  112. userSchema.methods.isPasswordSet = function() {
  113. if (this.password) {
  114. return true;
  115. }
  116. return false;
  117. };
  118. userSchema.methods.isPasswordValid = function(password) {
  119. return this.password == generatePassword(password);
  120. };
  121. userSchema.methods.setPassword = function(password) {
  122. this.password = generatePassword(password);
  123. return this;
  124. };
  125. userSchema.methods.isEmailSet = function() {
  126. if (this.email) {
  127. return true;
  128. }
  129. return false;
  130. };
  131. userSchema.methods.updateLastLoginAt = function(lastLoginAt, callback) {
  132. this.lastLoginAt = lastLoginAt;
  133. this.save(function(err, userData) {
  134. return callback(err, userData);
  135. });
  136. };
  137. userSchema.methods.updateIsGravatarEnabled = function(isGravatarEnabled, callback) {
  138. this.isGravatarEnabled = isGravatarEnabled;
  139. this.save(function(err, userData) {
  140. return callback(err, userData);
  141. });
  142. };
  143. userSchema.methods.updateIsEmailPublished = function(isEmailPublished, callback) {
  144. this.isEmailPublished = isEmailPublished;
  145. this.save(function(err, userData) {
  146. return callback(err, userData);
  147. });
  148. };
  149. userSchema.methods.updatePassword = function(password, callback) {
  150. this.setPassword(password);
  151. this.save(function(err, userData) {
  152. return callback(err, userData);
  153. });
  154. };
  155. userSchema.methods.updateApiToken = function(callback) {
  156. var self = this;
  157. self.apiToken = generateApiToken(this);
  158. return new Promise(function(resolve, reject) {
  159. self.save(function(err, userData) {
  160. if (err) {
  161. return reject(err);
  162. }
  163. else {
  164. return resolve(userData);
  165. }
  166. });
  167. });
  168. };
  169. userSchema.methods.updateImage = function(image, callback) {
  170. this.image = image;
  171. this.save(function(err, userData) {
  172. return callback(err, userData);
  173. });
  174. };
  175. userSchema.methods.deleteImage = function(callback) {
  176. return this.updateImage(null, callback);
  177. };
  178. userSchema.methods.updateGoogleId = function(googleId, callback) {
  179. this.googleId = googleId;
  180. this.save(function(err, userData) {
  181. return callback(err, userData);
  182. });
  183. };
  184. userSchema.methods.deleteGoogleId = function(callback) {
  185. return this.updateGoogleId(null, callback);
  186. };
  187. userSchema.methods.activateInvitedUser = function(username, name, password, callback) {
  188. this.setPassword(password);
  189. this.name = name;
  190. this.username = username;
  191. this.status = STATUS_ACTIVE;
  192. this.save(function(err, userData) {
  193. userEvent.emit('activated', userData);
  194. return callback(err, userData);
  195. });
  196. };
  197. userSchema.methods.removeFromAdmin = function(callback) {
  198. debug('Remove from admin', this);
  199. this.admin = 0;
  200. this.save(function(err, userData) {
  201. return callback(err, userData);
  202. });
  203. };
  204. userSchema.methods.makeAdmin = function(callback) {
  205. debug('Admin', this);
  206. this.admin = 1;
  207. this.save(function(err, userData) {
  208. return callback(err, userData);
  209. });
  210. };
  211. userSchema.methods.statusActivate = function(callback) {
  212. debug('Activate User', this);
  213. this.status = STATUS_ACTIVE;
  214. this.save(function(err, userData) {
  215. userEvent.emit('activated', userData);
  216. return callback(err, userData);
  217. });
  218. };
  219. userSchema.methods.statusSuspend = function(callback) {
  220. debug('Suspend User', this);
  221. this.status = STATUS_SUSPENDED;
  222. if (this.email === undefined || this.email === null) { // migrate old data
  223. this.email = '-';
  224. }
  225. if (this.name === undefined || this.name === null) { // migrate old data
  226. this.name = '-' + Date.now();
  227. }
  228. if (this.username === undefined || this.usename === null) { // migrate old data
  229. this.username = '-';
  230. }
  231. this.save(function(err, userData) {
  232. return callback(err, userData);
  233. });
  234. };
  235. userSchema.methods.statusDelete = function(callback) {
  236. debug('Delete User', this);
  237. const now = new Date();
  238. const deletedLabel = `deleted_at_${now.getTime()}`;
  239. this.status = STATUS_DELETED;
  240. this.username = deletedLabel;
  241. this.password = '';
  242. this.name = '';
  243. this.email = `${deletedLabel}@deleted`;
  244. this.googleId = null;
  245. this.isGravatarEnabled = false;
  246. this.image = null;
  247. this.save(function(err, userData) {
  248. return callback(err, userData);
  249. });
  250. };
  251. userSchema.methods.updateGoogleId = function(googleId, callback) {
  252. this.googleId = googleId;
  253. this.save(function(err, userData) {
  254. return callback(err, userData);
  255. });
  256. };
  257. userSchema.statics.getLanguageLabels = getLanguageLabels;
  258. userSchema.statics.getUserStatusLabels = function() {
  259. var userStatus = {};
  260. userStatus[STATUS_REGISTERED] = '承認待ち';
  261. userStatus[STATUS_ACTIVE] = 'Active';
  262. userStatus[STATUS_SUSPENDED] = 'Suspended';
  263. userStatus[STATUS_DELETED] = 'Deleted';
  264. userStatus[STATUS_INVITED] = '招待済み';
  265. return userStatus;
  266. };
  267. userSchema.statics.isEmailValid = function(email, callback) {
  268. validateCrowi();
  269. var config = crowi.getConfig()
  270. , whitelist = config.crowi['security:registrationWhiteList'];
  271. if (Array.isArray(whitelist) && whitelist.length > 0) {
  272. return config.crowi['security:registrationWhiteList'].some(function(allowedEmail) {
  273. var re = new RegExp(allowedEmail + '$');
  274. return re.test(email);
  275. });
  276. }
  277. return true;
  278. };
  279. userSchema.statics.filterToPublicFields = function(user) {
  280. debug('User is', typeof user, user);
  281. if (typeof user !== 'object' || !user._id) {
  282. return user;
  283. }
  284. var filteredUser = {};
  285. var fields = USER_PUBLIC_FIELDS.split(' ');
  286. for (var i = 0; i < fields.length; i++) {
  287. var key = fields[i];
  288. if (user[key]) {
  289. filteredUser[key] = user[key];
  290. }
  291. }
  292. return filteredUser;
  293. };
  294. userSchema.statics.findUsers = function(options, callback) {
  295. var sort = options.sort || {status: 1, createdAt: 1};
  296. this.find()
  297. .sort(sort)
  298. .skip(options.skip || 0)
  299. .limit(options.limit || 21)
  300. .exec(function(err, userData) {
  301. callback(err, userData);
  302. });
  303. };
  304. userSchema.statics.findAllUsers = function(option) {
  305. var User = this;
  306. var option = option || {}
  307. , sort = option.sort || {createdAt: -1}
  308. , status = option.status || [STATUS_ACTIVE, STATUS_SUSPENDED]
  309. , fields = option.fields || USER_PUBLIC_FIELDS
  310. ;
  311. if (!Array.isArray(status)) {
  312. status = [status];
  313. }
  314. return new Promise(function(resolve, reject) {
  315. User
  316. .find()
  317. .or(status.map(s => { return {status: s} }))
  318. .select(fields)
  319. .sort(sort)
  320. .exec(function(err, userData) {
  321. if (err) {
  322. return reject(err);
  323. }
  324. return resolve(userData);
  325. });
  326. });
  327. };
  328. userSchema.statics.findUsersByIds = function(ids, option) {
  329. var User = this;
  330. var option = option || {}
  331. , sort = option.sort || {createdAt: -1}
  332. , status = option.status || STATUS_ACTIVE
  333. , fields = option.fields || USER_PUBLIC_FIELDS
  334. ;
  335. return new Promise(function(resolve, reject) {
  336. User
  337. .find({ _id: { $in: ids }, status: status })
  338. .select(fields)
  339. .sort(sort)
  340. .exec(function(err, userData) {
  341. if (err) {
  342. return reject(err);
  343. }
  344. return resolve(userData);
  345. });
  346. });
  347. };
  348. userSchema.statics.findAdmins = function(callback) {
  349. var User = this;
  350. this.find({admin: true})
  351. .exec(function(err, admins) {
  352. debug('Admins: ', admins);
  353. callback(err, admins);
  354. });
  355. };
  356. userSchema.statics.findUsersWithPagination = function(options, callback) {
  357. var sort = options.sort || {status: 1, username: 1, createdAt: 1};
  358. this.paginate({status: { $ne: STATUS_DELETED }}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
  359. if (err) {
  360. debug('Error on pagination:', err);
  361. return callback(err, null);
  362. }
  363. return callback(err, result);
  364. }, { sortBy: sort });
  365. };
  366. userSchema.statics.findUsersByPartOfEmail = function(emailPart, options) {
  367. const status = options.status || null;
  368. const emailPartRegExp = new RegExp(emailPart.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  369. const User = this;
  370. return new Promise((resolve, reject) => {
  371. const query = User.find({ email: emailPartRegExp }, USER_PUBLIC_FIELDS);
  372. if (status) {
  373. query.and({status});
  374. }
  375. query
  376. .limit(PAGE_ITEMS + 1)
  377. .exec((err, userData) => {
  378. if (err) {
  379. return reject(err);
  380. }
  381. return resolve(userData);
  382. });
  383. });
  384. };
  385. userSchema.statics.findUserByUsername = function(username) {
  386. if (username == null) {
  387. return Promise.resolve(null);
  388. }
  389. return this.findOne({username});
  390. };
  391. userSchema.statics.findUserByApiToken = function(apiToken) {
  392. if (apiToken == null) {
  393. return Promise.resolve(null);
  394. }
  395. return this.findOne({apiToken});
  396. };
  397. userSchema.statics.findUserByGoogleId = function(googleId, callback) {
  398. if (googleId == null) {
  399. callback(null, null);
  400. }
  401. this.findOne({googleId}, function(err, userData) {
  402. callback(err, userData);
  403. });
  404. };
  405. userSchema.statics.findUserByUsernameOrEmail = function(usernameOrEmail, password, callback) {
  406. this.findOne()
  407. .or([
  408. {username: usernameOrEmail},
  409. {email: usernameOrEmail},
  410. ])
  411. .exec((err, userData) => {
  412. callback(err, userData);
  413. });
  414. };
  415. userSchema.statics.findUserByEmailAndPassword = function(email, password, callback) {
  416. var hashedPassword = generatePassword(password);
  417. this.findOne({email: email, password: hashedPassword}, function(err, userData) {
  418. callback(err, userData);
  419. });
  420. };
  421. userSchema.statics.isRegisterableUsername = function(username, callback) {
  422. var User = this;
  423. var usernameUsable = true;
  424. this.findOne({username: username}, function(err, userData) {
  425. if (userData) {
  426. usernameUsable = false;
  427. }
  428. return callback(usernameUsable);
  429. });
  430. };
  431. userSchema.statics.isRegisterable = function(email, username, callback) {
  432. var User = this;
  433. var emailUsable = true;
  434. var usernameUsable = true;
  435. // username check
  436. this.findOne({username: username}, function(err, userData) {
  437. if (userData) {
  438. usernameUsable = false;
  439. }
  440. // email check
  441. User.findOne({email: email}, function(err, userData) {
  442. if (userData) {
  443. emailUsable = false;
  444. }
  445. if (!emailUsable || !usernameUsable) {
  446. return callback(false, {email: emailUsable, username: usernameUsable});
  447. }
  448. return callback(true, {});
  449. });
  450. });
  451. };
  452. userSchema.statics.removeCompletelyById = function(id, callback) {
  453. var User = this;
  454. User.findById(id, function(err, userData) {
  455. if (!userData) {
  456. return callback(err, null);
  457. }
  458. debug('Removing user:', userData);
  459. // 物理削除可能なのは、承認待ちユーザー、招待中ユーザーのみ
  460. // 利用を一度開始したユーザーは論理削除のみ可能
  461. if (userData.status !== STATUS_REGISTERED && userData.status !== STATUS_INVITED) {
  462. return callback(new Error('Cannot remove completely the user whoes status is not INVITED'), null);
  463. }
  464. userData.remove(function(err) {
  465. if (err) {
  466. return callback(err, null);
  467. }
  468. return callback(null, 1);
  469. });
  470. });
  471. };
  472. userSchema.statics.resetPasswordByRandomString = function(id) {
  473. var User = this;
  474. return new Promise(function(resolve, reject) {
  475. User.findById(id, function(err, userData) {
  476. if (!userData) {
  477. return reject(new Error('User not found'));
  478. }
  479. // is updatable check
  480. // if (userData.isUp
  481. var newPassword = generateRandomTempPassword();
  482. userData.setPassword(newPassword);
  483. userData.save(function(err, userData) {
  484. if (err) {
  485. return reject(err);
  486. }
  487. resolve({user: userData, newPassword: newPassword});
  488. });
  489. });
  490. });
  491. };
  492. userSchema.statics.createUsersByInvitation = function(emailList, toSendEmail, callback) {
  493. validateCrowi();
  494. var User = this
  495. , createdUserList = []
  496. , Config = crowi.model('Config')
  497. , config = crowi.getConfig()
  498. , mailer = crowi.getMailer()
  499. ;
  500. if (!Array.isArray(emailList)) {
  501. debug('emailList is not array');
  502. }
  503. async.each(
  504. emailList,
  505. function(email, next) {
  506. var newUser = new User()
  507. , tmpUsername, password;
  508. email = email.trim();
  509. // email check
  510. // TODO: 削除済みはチェック対象から外そう〜
  511. User.findOne({email: email}, function(err, userData) {
  512. // The user is exists
  513. if (userData) {
  514. createdUserList.push({
  515. email: email,
  516. password: null,
  517. user: null,
  518. });
  519. return next();
  520. }
  521. tmpUsername = 'temp_' + Math.random().toString(36).slice(-16);
  522. password = Math.random().toString(36).slice(-16);
  523. newUser.username = tmpUsername;
  524. newUser.email = email;
  525. newUser.setPassword(password);
  526. newUser.createdAt = Date.now();
  527. newUser.status = STATUS_INVITED;
  528. newUser.save(function(err, userData) {
  529. if (err) {
  530. createdUserList.push({
  531. email: email,
  532. password: null,
  533. user: null,
  534. });
  535. debug('save failed!! ', err);
  536. }
  537. else {
  538. createdUserList.push({
  539. email: email,
  540. password: password,
  541. user: userData,
  542. });
  543. debug('saved!', email);
  544. }
  545. next();
  546. });
  547. });
  548. },
  549. function(err) {
  550. if (err) {
  551. debug('error occured while iterate email list');
  552. }
  553. if (toSendEmail) {
  554. // TODO: メール送信部分のロジックをサービス化する
  555. async.each(
  556. createdUserList,
  557. function(user, next) {
  558. if (user.password === null) {
  559. return next();
  560. }
  561. mailer.send({
  562. to: user.email,
  563. subject: 'Invitation to ' + Config.appTitle(config),
  564. template: path.join(crowi.localeDir, 'en-US/admin/userInvitation.txt'),
  565. vars: {
  566. email: user.email,
  567. password: user.password,
  568. url: config.crowi['app:siteUrl:fixed'],
  569. appTitle: Config.appTitle(config),
  570. }
  571. },
  572. function(err, s) {
  573. debug('completed to send email: ', err, s);
  574. next();
  575. }
  576. );
  577. },
  578. function(err) {
  579. debug('Sending invitation email completed.', err);
  580. }
  581. );
  582. }
  583. debug('createdUserList!!! ', createdUserList);
  584. return callback(null, createdUserList);
  585. }
  586. );
  587. };
  588. userSchema.statics.createUserByEmailAndPasswordAndStatus = async function(name, username, email, password, lang, status, callback) {
  589. const User = this
  590. , newUser = new User();
  591. // check email duplication because email must be unique
  592. const count = await this.count({ email });
  593. if (count > 0) {
  594. email = generateRandomEmail();
  595. }
  596. newUser.name = name;
  597. newUser.username = username;
  598. newUser.email = email;
  599. if (password != null) {
  600. newUser.setPassword(password);
  601. }
  602. if (lang != null) {
  603. newUser.lang = lang;
  604. }
  605. newUser.createdAt = Date.now();
  606. newUser.status = status || decideUserStatusOnRegistration();
  607. newUser.save(function(err, userData) {
  608. if (err) {
  609. debug('createUserByEmailAndPassword failed: ', err);
  610. return callback(err);
  611. }
  612. if (userData.status == STATUS_ACTIVE) {
  613. userEvent.emit('activated', userData);
  614. }
  615. return callback(err, userData);
  616. });
  617. };
  618. /**
  619. * A wrapper function of createUserByEmailAndPasswordAndStatus with callback
  620. *
  621. */
  622. userSchema.statics.createUserByEmailAndPassword = function(name, username, email, password, lang, callback) {
  623. this.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, undefined, callback);
  624. };
  625. /**
  626. * A wrapper function of createUserByEmailAndPasswordAndStatus
  627. *
  628. * @return {Promise<User>}
  629. */
  630. userSchema.statics.createUser = function(name, username, email, password, lang, status) {
  631. const User = this;
  632. return new Promise((resolve, reject) => {
  633. User.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, status, (err, userData) => {
  634. if (err) {
  635. return reject(err);
  636. }
  637. return resolve(userData);
  638. });
  639. });
  640. };
  641. userSchema.statics.createUserPictureFilePath = function(user, name) {
  642. var ext = '.' + name.match(/(.*)(?:\.([^.]+$))/)[2];
  643. return 'user/' + user._id + ext;
  644. };
  645. userSchema.statics.getUsernameByPath = function(path) {
  646. var username = null;
  647. if (m = path.match(/^\/user\/([^\/]+)\/?/)) {
  648. username = m[1];
  649. }
  650. return username;
  651. };
  652. userSchema.statics.STATUS_REGISTERED = STATUS_REGISTERED;
  653. userSchema.statics.STATUS_ACTIVE = STATUS_ACTIVE;
  654. userSchema.statics.STATUS_SUSPENDED = STATUS_SUSPENDED;
  655. userSchema.statics.STATUS_DELETED = STATUS_DELETED;
  656. userSchema.statics.STATUS_INVITED = STATUS_INVITED;
  657. userSchema.statics.USER_PUBLIC_FIELDS = USER_PUBLIC_FIELDS;
  658. userSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
  659. userSchema.statics.LANG_EN = LANG_EN;
  660. userSchema.statics.LANG_EN_US = LANG_EN_US;
  661. userSchema.statics.LANG_EN_GB = LANG_EN_US;
  662. userSchema.statics.LANG_JA = LANG_JA;
  663. return mongoose.model('User', userSchema);
  664. };