user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. module.exports = function(crowi) {
  2. var debug = require('debug')('growi:models:user')
  3. , mongoose = require('mongoose')
  4. , mongoosePaginate = require('mongoose-paginate')
  5. , uniqueValidator = require('mongoose-unique-validator')
  6. , crypto = require('crypto')
  7. , async = require('async')
  8. , ObjectId = mongoose.Schema.Types.ObjectId
  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. , 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. this.save(function(err, userData) {
  182. userEvent.emit('activated', userData);
  183. return callback(err, userData);
  184. });
  185. };
  186. userSchema.methods.removeFromAdmin = function(callback) {
  187. debug('Remove from admin', this);
  188. this.admin = 0;
  189. this.save(function(err, userData) {
  190. return callback(err, userData);
  191. });
  192. };
  193. userSchema.methods.makeAdmin = function(callback) {
  194. debug('Admin', this);
  195. this.admin = 1;
  196. this.save(function(err, userData) {
  197. return callback(err, userData);
  198. });
  199. };
  200. userSchema.methods.statusActivate = function(callback) {
  201. debug('Activate User', this);
  202. this.status = STATUS_ACTIVE;
  203. this.save(function(err, userData) {
  204. userEvent.emit('activated', userData);
  205. return callback(err, userData);
  206. });
  207. };
  208. userSchema.methods.statusSuspend = function(callback) {
  209. debug('Suspend User', this);
  210. this.status = STATUS_SUSPENDED;
  211. if (this.email === undefined || this.email === null) { // migrate old data
  212. this.email = '-';
  213. }
  214. if (this.name === undefined || this.name === null) { // migrate old data
  215. this.name = '-' + Date.now();
  216. }
  217. if (this.username === undefined || this.usename === null) { // migrate old data
  218. this.username = '-';
  219. }
  220. this.save(function(err, userData) {
  221. return callback(err, userData);
  222. });
  223. };
  224. userSchema.methods.statusDelete = function(callback) {
  225. debug('Delete User', this);
  226. const now = new Date();
  227. const deletedLabel = `deleted_at_${now.getTime()}`;
  228. this.status = STATUS_DELETED;
  229. this.username = deletedLabel;
  230. this.password = '';
  231. this.name = '';
  232. this.email = `${deletedLabel}@deleted`;
  233. this.googleId = null;
  234. this.isGravatarEnabled = false;
  235. this.image = null;
  236. this.save(function(err, userData) {
  237. return callback(err, userData);
  238. });
  239. };
  240. userSchema.methods.updateGoogleId = function(googleId, callback) {
  241. this.googleId = googleId;
  242. this.save(function(err, userData) {
  243. return callback(err, userData);
  244. });
  245. };
  246. userSchema.statics.getLanguageLabels = getLanguageLabels;
  247. userSchema.statics.getUserStatusLabels = function() {
  248. var userStatus = {};
  249. userStatus[STATUS_REGISTERED] = '承認待ち';
  250. userStatus[STATUS_ACTIVE] = 'Active';
  251. userStatus[STATUS_SUSPENDED] = 'Suspended';
  252. userStatus[STATUS_DELETED] = 'Deleted';
  253. userStatus[STATUS_INVITED] = '招待済み';
  254. return userStatus;
  255. };
  256. userSchema.statics.isEmailValid = function(email, callback) {
  257. var config = crowi.getConfig()
  258. , whitelist = config.crowi['security:registrationWhiteList'];
  259. if (Array.isArray(whitelist) && whitelist.length > 0) {
  260. return config.crowi['security:registrationWhiteList'].some(function(allowedEmail) {
  261. var re = new RegExp(allowedEmail + '$');
  262. return re.test(email);
  263. });
  264. }
  265. return true;
  266. };
  267. userSchema.statics.filterToPublicFields = function(user) {
  268. debug('User is', typeof user, user);
  269. if (typeof user !== 'object' || !user._id) {
  270. return user;
  271. }
  272. var filteredUser = {};
  273. var fields = USER_PUBLIC_FIELDS.split(' ');
  274. for (var i = 0; i < fields.length; i++) {
  275. var key = fields[i];
  276. if (user[key]) {
  277. filteredUser[key] = user[key];
  278. }
  279. }
  280. return filteredUser;
  281. };
  282. userSchema.statics.findUsers = function(options, callback) {
  283. var sort = options.sort || {status: 1, createdAt: 1};
  284. this.find()
  285. .sort(sort)
  286. .skip(options.skip || 0)
  287. .limit(options.limit || 21)
  288. .exec(function(err, userData) {
  289. callback(err, userData);
  290. });
  291. };
  292. userSchema.statics.findAllUsers = function(option) {
  293. var User = this;
  294. var option = option || {}
  295. , sort = option.sort || {createdAt: -1}
  296. , status = option.status || [STATUS_ACTIVE, STATUS_SUSPENDED]
  297. , fields = option.fields || USER_PUBLIC_FIELDS
  298. ;
  299. if (!Array.isArray(status)) {
  300. status = [status];
  301. }
  302. return new Promise(function(resolve, reject) {
  303. User
  304. .find()
  305. .or(status.map(s => { return {status: s} }))
  306. .select(fields)
  307. .sort(sort)
  308. .exec(function(err, userData) {
  309. if (err) {
  310. return reject(err);
  311. }
  312. return resolve(userData);
  313. });
  314. });
  315. };
  316. userSchema.statics.findUsersByIds = function(ids, option) {
  317. var User = this;
  318. var option = option || {}
  319. , sort = option.sort || {createdAt: -1}
  320. , status = option.status || STATUS_ACTIVE
  321. , fields = option.fields || USER_PUBLIC_FIELDS
  322. ;
  323. return new Promise(function(resolve, reject) {
  324. User
  325. .find({ _id: { $in: ids }, status: status })
  326. .select(fields)
  327. .sort(sort)
  328. .exec(function(err, userData) {
  329. if (err) {
  330. return reject(err);
  331. }
  332. return resolve(userData);
  333. });
  334. });
  335. };
  336. userSchema.statics.findAdmins = function(callback) {
  337. var User = this;
  338. this.find({admin: true})
  339. .exec(function(err, admins) {
  340. debug('Admins: ', admins);
  341. callback(err, admins);
  342. });
  343. };
  344. userSchema.statics.findUsersWithPagination = function(options, callback) {
  345. var sort = options.sort || {status: 1, username: 1, createdAt: 1};
  346. this.paginate({status: { $ne: STATUS_DELETED }}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
  347. if (err) {
  348. debug('Error on pagination:', err);
  349. return callback(err, null);
  350. }
  351. return callback(err, result);
  352. }, { sortBy: sort });
  353. };
  354. userSchema.statics.findUsersByPartOfEmail = function(emailPart, options) {
  355. const status = options.status || null;
  356. const emailPartRegExp = new RegExp(emailPart.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  357. const User = this;
  358. return new Promise((resolve, reject) => {
  359. const query = User.find({ email: emailPartRegExp }, USER_PUBLIC_FIELDS);
  360. if (status) {
  361. query.and({status});
  362. }
  363. query
  364. .limit(PAGE_ITEMS + 1)
  365. .exec((err, userData) => {
  366. if (err) {
  367. return reject(err);
  368. }
  369. return resolve(userData);
  370. });
  371. });
  372. };
  373. userSchema.statics.findUserByUsername = function(username) {
  374. if (username == null) {
  375. return Promise.resolve(null);
  376. }
  377. return this.findOne({username});
  378. };
  379. userSchema.statics.findUserByApiToken = function(apiToken) {
  380. if (apiToken == null) {
  381. return Promise.resolve(null);
  382. }
  383. return this.findOne({apiToken});
  384. };
  385. userSchema.statics.findUserByGoogleId = function(googleId, callback) {
  386. if (googleId == null) {
  387. callback(null, null);
  388. }
  389. this.findOne({googleId}, function(err, userData) {
  390. callback(err, userData);
  391. });
  392. };
  393. userSchema.statics.findUserByUsernameOrEmail = function(usernameOrEmail, password, callback) {
  394. this.findOne()
  395. .or([
  396. {username: usernameOrEmail},
  397. {email: usernameOrEmail},
  398. ])
  399. .exec((err, userData) => {
  400. callback(err, userData);
  401. });
  402. };
  403. userSchema.statics.findUserByEmailAndPassword = function(email, password, callback) {
  404. var hashedPassword = generatePassword(password);
  405. this.findOne({email: email, password: hashedPassword}, function(err, userData) {
  406. callback(err, userData);
  407. });
  408. };
  409. userSchema.statics.isRegisterableUsername = function(username, callback) {
  410. var User = this;
  411. var usernameUsable = true;
  412. this.findOne({username: username}, function(err, userData) {
  413. if (userData) {
  414. usernameUsable = false;
  415. }
  416. return callback(usernameUsable);
  417. });
  418. };
  419. userSchema.statics.isRegisterable = function(email, username, callback) {
  420. var User = this;
  421. var emailUsable = true;
  422. var usernameUsable = true;
  423. // username check
  424. this.findOne({username: username}, function(err, userData) {
  425. if (userData) {
  426. usernameUsable = false;
  427. }
  428. // email check
  429. User.findOne({email: email}, function(err, userData) {
  430. if (userData) {
  431. emailUsable = false;
  432. }
  433. if (!emailUsable || !usernameUsable) {
  434. return callback(false, {email: emailUsable, username: usernameUsable});
  435. }
  436. return callback(true, {});
  437. });
  438. });
  439. };
  440. userSchema.statics.removeCompletelyById = function(id, callback) {
  441. var User = this;
  442. User.findById(id, function(err, userData) {
  443. if (!userData) {
  444. return callback(err, null);
  445. }
  446. debug('Removing user:', userData);
  447. // 物理削除可能なのは、承認待ちユーザー、招待中ユーザーのみ
  448. // 利用を一度開始したユーザーは論理削除のみ可能
  449. if (userData.status !== STATUS_REGISTERED && userData.status !== STATUS_INVITED) {
  450. return callback(new Error('Cannot remove completely the user whoes status is not INVITED'), null);
  451. }
  452. userData.remove(function(err) {
  453. if (err) {
  454. return callback(err, null);
  455. }
  456. return callback(null, 1);
  457. });
  458. });
  459. };
  460. userSchema.statics.resetPasswordByRandomString = function(id) {
  461. var User = this;
  462. return new Promise(function(resolve, reject) {
  463. User.findById(id, function(err, userData) {
  464. if (!userData) {
  465. return reject(new Error('User not found'));
  466. }
  467. // is updatable check
  468. // if (userData.isUp
  469. var newPassword = generateRandomTempPassword();
  470. userData.setPassword(newPassword);
  471. userData.save(function(err, userData) {
  472. if (err) {
  473. return reject(err);
  474. }
  475. resolve({user: userData, newPassword: newPassword});
  476. });
  477. });
  478. });
  479. };
  480. userSchema.statics.createUsersByInvitation = function(emailList, toSendEmail, callback) {
  481. var User = this
  482. , createdUserList = []
  483. , Config = crowi.model('Config')
  484. , config = crowi.getConfig()
  485. , mailer = crowi.getMailer()
  486. ;
  487. if (!Array.isArray(emailList)) {
  488. debug('emailList is not array');
  489. }
  490. async.each(
  491. emailList,
  492. function(email, next) {
  493. var newUser = new User()
  494. , tmpUsername, password;
  495. email = email.trim();
  496. // email check
  497. // TODO: 削除済みはチェック対象から外そう〜
  498. User.findOne({email: email}, function(err, userData) {
  499. // The user is exists
  500. if (userData) {
  501. createdUserList.push({
  502. email: email,
  503. password: null,
  504. user: null,
  505. });
  506. return next();
  507. }
  508. tmpUsername = 'temp_' + Math.random().toString(36).slice(-16);
  509. password = Math.random().toString(36).slice(-16);
  510. newUser.username = tmpUsername;
  511. newUser.email = email;
  512. newUser.setPassword(password);
  513. newUser.createdAt = Date.now();
  514. newUser.status = STATUS_INVITED;
  515. newUser.save(function(err, userData) {
  516. if (err) {
  517. createdUserList.push({
  518. email: email,
  519. password: null,
  520. user: null,
  521. });
  522. debug('save failed!! ', err);
  523. }
  524. else {
  525. createdUserList.push({
  526. email: email,
  527. password: password,
  528. user: userData,
  529. });
  530. debug('saved!', email);
  531. }
  532. next();
  533. });
  534. });
  535. },
  536. function(err) {
  537. if (err) {
  538. debug('error occured while iterate email list');
  539. }
  540. if (toSendEmail) {
  541. // TODO: メール送信部分のロジックをサービス化する
  542. async.each(
  543. createdUserList,
  544. function(user, next) {
  545. if (user.password === null) {
  546. return next();
  547. }
  548. mailer.send({
  549. to: user.email,
  550. subject: 'Invitation to ' + Config.appTitle(config),
  551. template: 'admin/userInvitation.txt',
  552. vars: {
  553. email: user.email,
  554. password: user.password,
  555. url: config.crowi['app:url'],
  556. appTitle: Config.appTitle(config),
  557. }
  558. },
  559. function(err, s) {
  560. debug('completed to send email: ', err, s);
  561. next();
  562. }
  563. );
  564. },
  565. function(err) {
  566. debug('Sending invitation email completed.', err);
  567. }
  568. );
  569. }
  570. debug('createdUserList!!! ', createdUserList);
  571. return callback(null, createdUserList);
  572. }
  573. );
  574. };
  575. userSchema.statics.createUserByEmailAndPasswordAndStatus = function(name, username, email, password, lang, status, callback) {
  576. var User = this
  577. , newUser = new User();
  578. newUser.name = name;
  579. newUser.username = username;
  580. newUser.email = email || generateRandomEmail(); // don't set undefined for backward compatibility -- 2017.12.27 Yuki Takei
  581. if (password != null) {
  582. newUser.setPassword(password);
  583. }
  584. if (lang != null) {
  585. newUser.lang = lang;
  586. }
  587. newUser.createdAt = Date.now();
  588. newUser.status = status || decideUserStatusOnRegistration();
  589. newUser.save(function(err, userData) {
  590. if (err) {
  591. debug('createUserByEmailAndPassword failed: ', err);
  592. return callback(err);
  593. }
  594. if (userData.status == STATUS_ACTIVE) {
  595. userEvent.emit('activated', userData);
  596. }
  597. return callback(err, userData);
  598. });
  599. };
  600. /**
  601. * A wrapper function of createUserByEmailAndPasswordAndStatus
  602. *
  603. * @return {Promise<User>}
  604. */
  605. userSchema.statics.createUserByEmailAndPassword = function(name, username, email, password, lang, callback) {
  606. this.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, undefined, callback);
  607. };
  608. /**
  609. * A wrapper function of createUserByEmailAndPasswordAndStatus
  610. *
  611. * @return {Promise<User>}
  612. */
  613. userSchema.statics.createUser = function(name, username, email, password, lang, status) {
  614. const User = this;
  615. return new Promise((resolve, reject) => {
  616. User.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, status, (err, userData) => {
  617. if (err) {
  618. return reject(err);
  619. }
  620. return resolve(userData);
  621. });
  622. });
  623. };
  624. userSchema.statics.createUserPictureFilePath = function(user, name) {
  625. var ext = '.' + name.match(/(.*)(?:\.([^.]+$))/)[2];
  626. return 'user/' + user._id + ext;
  627. };
  628. userSchema.statics.getUsernameByPath = function(path) {
  629. var username = null;
  630. if (m = path.match(/^\/user\/([^\/]+)\/?/)) {
  631. username = m[1];
  632. }
  633. return username;
  634. };
  635. userSchema.statics.STATUS_REGISTERED = STATUS_REGISTERED;
  636. userSchema.statics.STATUS_ACTIVE = STATUS_ACTIVE;
  637. userSchema.statics.STATUS_SUSPENDED = STATUS_SUSPENDED;
  638. userSchema.statics.STATUS_DELETED = STATUS_DELETED;
  639. userSchema.statics.STATUS_INVITED = STATUS_INVITED;
  640. userSchema.statics.USER_PUBLIC_FIELDS = USER_PUBLIC_FIELDS;
  641. userSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
  642. userSchema.statics.LANG_EN = LANG_EN;
  643. userSchema.statics.LANG_EN_US = LANG_EN_US;
  644. userSchema.statics.LANG_EN_GB = LANG_EN_US;
  645. userSchema.statics.LANG_JA = LANG_JA;
  646. return mongoose.model('User', userSchema);
  647. };