user.js 21 KB

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