user.js 22 KB

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