user.js 21 KB

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