user.js 21 KB

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