user.js 21 KB

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