user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. googleId: String,
  27. name: { type: String },
  28. username: { type: String, required: true, unique: true },
  29. email: { type: String, unique: true, sparse: true },
  30. //// The official settings
  31. // username: { type: String, index: true },
  32. // email: { type: String, required: true, index: true },
  33. //// crowi-plus (>= 2.1.0, <2.3.0) settings
  34. // email: { type: String, required: true, unique: true },
  35. introduction: { type: String },
  36. password: String,
  37. apiToken: String,
  38. lang: {
  39. type: String,
  40. enum: Object.keys(getLanguageLabels()).map((k) => eval(k)),
  41. default: LANG_EN_US
  42. },
  43. status: { type: Number, required: true, default: STATUS_ACTIVE, index: true },
  44. createdAt: { type: Date, default: Date.now },
  45. lastLoginAt: { type: Date },
  46. admin: { type: Boolean, default: 0, index: true }
  47. });
  48. userSchema.plugin(mongoosePaginate);
  49. userSchema.plugin(uniqueValidator);
  50. userEvent.on('activated', userEvent.onActivated);
  51. function decideUserStatusOnRegistration () {
  52. var Config = crowi.model('Config'),
  53. config = crowi.getConfig();
  54. if (!config.crowi) {
  55. return STATUS_ACTIVE; // is this ok?
  56. }
  57. // status decided depends on registrationMode
  58. switch (config.crowi['security:registrationMode']) {
  59. case Config.SECURITY_REGISTRATION_MODE_OPEN:
  60. return STATUS_ACTIVE;
  61. case Config.SECURITY_REGISTRATION_MODE_RESTRICTED:
  62. case Config.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
  63. return STATUS_REGISTERED;
  64. default:
  65. return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
  66. }
  67. }
  68. function generateRandomEmail() {
  69. const randomstr = generateRandomTempPassword();
  70. return `change-it-${randomstr}@example.com`
  71. }
  72. function generateRandomTempPassword () {
  73. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!=-_';
  74. var password = '';
  75. var len = 12;
  76. for (var i = 0; i < len; i++) {
  77. var randomPoz = Math.floor(Math.random() * chars.length);
  78. password += chars.substring(randomPoz, randomPoz+1);
  79. }
  80. return password;
  81. }
  82. function generatePassword (password) {
  83. var hasher = crypto.createHash('sha256');
  84. hasher.update(crowi.env.PASSWORD_SEED + password);
  85. return hasher.digest('hex');
  86. }
  87. function generateApiToken (user) {
  88. var hasher = crypto.createHash('sha256');
  89. hasher.update((new Date).getTime() + user._id);
  90. return hasher.digest('base64');
  91. }
  92. function getLanguageLabels() {
  93. var lang = {};
  94. lang.LANG_EN = LANG_EN;
  95. lang.LANG_EN_US = LANG_EN_US;
  96. lang.LANG_EN_GB = LANG_EN_GB;
  97. lang.LANG_JA = LANG_JA;
  98. return lang;
  99. }
  100. userSchema.methods.isPasswordSet = function() {
  101. if (this.password) {
  102. return true;
  103. }
  104. return false;
  105. };
  106. userSchema.methods.isPasswordValid = function(password) {
  107. return this.password == generatePassword(password);
  108. };
  109. userSchema.methods.setPassword = function(password) {
  110. this.password = generatePassword(password);
  111. return this;
  112. };
  113. userSchema.methods.isEmailSet = function() {
  114. if (this.email) {
  115. return true;
  116. }
  117. return false;
  118. };
  119. userSchema.methods.updateLastLoginAt = function(lastLoginAt, callback) {
  120. this.lastLoginAt = lastLoginAt;
  121. this.save(function(err, userData) {
  122. return callback(err, userData);
  123. });
  124. };
  125. userSchema.methods.updateIsGravatarEnabled = function(isGravatarEnabled, callback) {
  126. this.isGravatarEnabled = isGravatarEnabled;
  127. this.save(function(err, userData) {
  128. return callback(err, userData);
  129. });
  130. };
  131. userSchema.methods.updatePassword = function(password, callback) {
  132. this.setPassword(password);
  133. this.save(function(err, userData) {
  134. return callback(err, userData);
  135. });
  136. };
  137. userSchema.methods.updateApiToken = function(callback) {
  138. var self = this;
  139. self.apiToken = generateApiToken(this);
  140. return new Promise(function(resolve, reject) {
  141. self.save(function(err, userData) {
  142. if (err) {
  143. return reject(err);
  144. } else {
  145. return resolve(userData);
  146. }
  147. });
  148. });
  149. };
  150. userSchema.methods.updateImage = function(image, callback) {
  151. this.image = image;
  152. this.save(function(err, userData) {
  153. return callback(err, userData);
  154. });
  155. };
  156. userSchema.methods.deleteImage = function(callback) {
  157. return this.updateImage(null, callback);
  158. };
  159. userSchema.methods.updateGoogleId = function(googleId, callback) {
  160. this.googleId = googleId;
  161. this.save(function(err, userData) {
  162. return callback(err, userData);
  163. });
  164. };
  165. userSchema.methods.deleteGoogleId = function(callback) {
  166. return this.updateGoogleId(null, callback);
  167. };
  168. userSchema.methods.activateInvitedUser = function(username, name, password, callback) {
  169. this.setPassword(password);
  170. this.name = name;
  171. this.username = username;
  172. this.status = STATUS_ACTIVE;
  173. this.save(function(err, userData) {
  174. userEvent.emit('activated', userData);
  175. return callback(err, userData);
  176. });
  177. };
  178. userSchema.methods.removeFromAdmin = function(callback) {
  179. debug('Remove from admin', this);
  180. this.admin = 0;
  181. this.save(function(err, userData) {
  182. return callback(err, userData);
  183. });
  184. };
  185. userSchema.methods.makeAdmin = function(callback) {
  186. debug('Admin', this);
  187. this.admin = 1;
  188. this.save(function(err, userData) {
  189. return callback(err, userData);
  190. });
  191. };
  192. userSchema.methods.statusActivate = function(callback) {
  193. debug('Activate User', this);
  194. this.status = STATUS_ACTIVE;
  195. this.save(function(err, userData) {
  196. userEvent.emit('activated', userData);
  197. return callback(err, userData);
  198. });
  199. };
  200. userSchema.methods.statusSuspend = function(callback) {
  201. debug('Suspend User', this);
  202. this.status = STATUS_SUSPENDED;
  203. if (this.email === undefined || this.email === null) { // migrate old data
  204. this.email = '-';
  205. }
  206. if (this.name === undefined || this.name === null) { // migrate old data
  207. this.name = '-' + Date.now();
  208. }
  209. if (this.username === undefined || this.usename === null) { // migrate old data
  210. this.username = '-';
  211. }
  212. this.save(function(err, userData) {
  213. return callback(err, userData);
  214. });
  215. };
  216. userSchema.methods.statusDelete = function(callback) {
  217. debug('Delete User', this);
  218. const now = new Date();
  219. const deletedLabel = `deleted_at_${now.getTime()}`;
  220. this.status = STATUS_DELETED;
  221. this.username = deletedLabel;
  222. this.password = '';
  223. this.name = '';
  224. this.email = `${deletedLabel}@deleted`;
  225. this.googleId = null;
  226. this.isGravatarEnabled = false;
  227. this.image = null;
  228. this.save(function(err, userData) {
  229. return callback(err, userData);
  230. });
  231. };
  232. userSchema.methods.updateGoogleId = function(googleId, callback) {
  233. this.googleId = googleId;
  234. this.save(function(err, userData) {
  235. return callback(err, userData);
  236. });
  237. };
  238. userSchema.statics.getLanguageLabels = getLanguageLabels;
  239. userSchema.statics.getUserStatusLabels = function() {
  240. var userStatus = {};
  241. userStatus[STATUS_REGISTERED] = '承認待ち';
  242. userStatus[STATUS_ACTIVE] = 'Active';
  243. userStatus[STATUS_SUSPENDED] = 'Suspended';
  244. userStatus[STATUS_DELETED] = 'Deleted';
  245. userStatus[STATUS_INVITED] = '招待済み';
  246. return userStatus;
  247. };
  248. userSchema.statics.isEmailValid = function(email, callback) {
  249. var config = crowi.getConfig()
  250. , whitelist = config.crowi['security:registrationWhiteList'];
  251. if (Array.isArray(whitelist) && whitelist.length > 0) {
  252. return config.crowi['security:registrationWhiteList'].some(function(allowedEmail) {
  253. var re = new RegExp(allowedEmail + '$');
  254. return re.test(email);
  255. });
  256. }
  257. return true;
  258. };
  259. userSchema.statics.filterToPublicFields = function(user) {
  260. debug('User is', typeof user, user);
  261. if (typeof user !== 'object' || !user._id) {
  262. return user;
  263. }
  264. var filteredUser = {};
  265. var fields = USER_PUBLIC_FIELDS.split(' ');
  266. for (var i = 0; i < fields.length; i++) {
  267. var key = fields[i];
  268. if (user[key]) {
  269. filteredUser[key] = user[key];
  270. }
  271. }
  272. return filteredUser;
  273. };
  274. userSchema.statics.findUsers = function(options, callback) {
  275. var sort = options.sort || {status: 1, createdAt: 1};
  276. this.find()
  277. .sort(sort)
  278. .skip(options.skip || 0)
  279. .limit(options.limit || 21)
  280. .exec(function (err, userData) {
  281. callback(err, userData);
  282. });
  283. };
  284. userSchema.statics.findAllUsers = function(option) {
  285. var User = this;
  286. var option = option || {}
  287. , sort = option.sort || {createdAt: -1}
  288. , status = option.status || [STATUS_ACTIVE, STATUS_SUSPENDED]
  289. , fields = option.fields || USER_PUBLIC_FIELDS
  290. ;
  291. if (!Array.isArray(status)) {
  292. status = [status];
  293. }
  294. return new Promise(function(resolve, reject) {
  295. User
  296. .find()
  297. .or(status.map(s => { return {status: s}; }))
  298. .select(fields)
  299. .sort(sort)
  300. .exec(function (err, userData) {
  301. if (err) {
  302. return reject(err);
  303. }
  304. return resolve(userData);
  305. });
  306. });
  307. };
  308. userSchema.statics.findUsersByIds = function(ids, option) {
  309. var User = this;
  310. var option = option || {}
  311. , sort = option.sort || {createdAt: -1}
  312. , status = option.status || STATUS_ACTIVE
  313. , fields = option.fields || USER_PUBLIC_FIELDS
  314. ;
  315. return new Promise(function(resolve, reject) {
  316. User
  317. .find({ _id: { $in: ids }, status: status })
  318. .select(fields)
  319. .sort(sort)
  320. .exec(function (err, userData) {
  321. if (err) {
  322. return reject(err);
  323. }
  324. return resolve(userData);
  325. });
  326. });
  327. };
  328. userSchema.statics.findAdmins = function(callback) {
  329. var User = this;
  330. this.find({admin: true})
  331. .exec(function(err, admins) {
  332. debug('Admins: ', admins);
  333. callback(err, admins);
  334. });
  335. };
  336. userSchema.statics.findUsersWithPagination = function(options, callback) {
  337. var sort = options.sort || {status: 1, username: 1, createdAt: 1};
  338. this.paginate({status: { $ne: STATUS_DELETED }}, { page: options.page || 1, limit: options.limit || PAGE_ITEMS }, function(err, result) {
  339. if (err) {
  340. debug('Error on pagination:', err);
  341. return callback(err, null);
  342. }
  343. return callback(err, result);
  344. }, { sortBy : sort });
  345. };
  346. userSchema.statics.findUsersByPartOfEmail = function(emailPart, options) {
  347. const status = options.status || null;
  348. const emailPartRegExp = new RegExp(emailPart.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  349. const User = this;
  350. return new Promise((resolve, reject) => {
  351. const query = User.find({ email: emailPartRegExp }, USER_PUBLIC_FIELDS);
  352. if (status) {
  353. query.and({status});
  354. }
  355. query
  356. .limit(PAGE_ITEMS + 1)
  357. .exec((err, userData) => {
  358. if (err) {
  359. return reject(err);
  360. }
  361. return resolve(userData);
  362. });
  363. });
  364. };
  365. userSchema.statics.findUserByUsername = function(username) {
  366. var User = this;
  367. return new Promise(function(resolve, reject) {
  368. User.findOne({username: username}, function (err, userData) {
  369. if (err) {
  370. return reject(err);
  371. }
  372. return resolve(userData);
  373. });
  374. });
  375. };
  376. userSchema.statics.findUserByApiToken = function(apiToken) {
  377. var self = this;
  378. return new Promise(function(resolve, reject) {
  379. self.findOne({apiToken: apiToken}, function (err, userData) {
  380. if (err) {
  381. return reject(err);
  382. } else {
  383. return resolve(userData);
  384. }
  385. });
  386. });
  387. };
  388. userSchema.statics.findUserByGoogleId = function(googleId, callback) {
  389. this.findOne({googleId: googleId}, function (err, userData) {
  390. callback(err, userData);
  391. });
  392. };
  393. userSchema.statics.findUserByUsernameOrEmail = function(usernameOrEmail, password, callback) {
  394. this.findOne()
  395. .or([
  396. {username: usernameOrEmail},
  397. {email: usernameOrEmail},
  398. ])
  399. .exec((err, userData) => {
  400. callback(err, userData);
  401. });
  402. };
  403. userSchema.statics.findUserByEmailAndPassword = function(email, password, callback) {
  404. var hashedPassword = generatePassword(password);
  405. this.findOne({email: email, password: hashedPassword}, function (err, userData) {
  406. callback(err, userData);
  407. });
  408. };
  409. userSchema.statics.isRegisterableUsername = function(username, callback) {
  410. var User = this;
  411. var usernameUsable = true;
  412. this.findOne({username: username}, function (err, userData) {
  413. if (userData) {
  414. usernameUsable = false;
  415. }
  416. return callback(usernameUsable);
  417. });
  418. };
  419. userSchema.statics.isRegisterable = function(email, username, callback) {
  420. var User = this;
  421. var emailUsable = true;
  422. var usernameUsable = true;
  423. // username check
  424. this.findOne({username: username}, function (err, userData) {
  425. if (userData) {
  426. usernameUsable = false;
  427. }
  428. // email check
  429. User.findOne({email: email}, function (err, userData) {
  430. if (userData) {
  431. emailUsable = false;
  432. }
  433. if (!emailUsable || !usernameUsable) {
  434. return callback(false, {email: emailUsable, username: usernameUsable});
  435. }
  436. return callback(true, {});
  437. });
  438. });
  439. };
  440. userSchema.statics.removeCompletelyById = function(id, callback) {
  441. var User = this;
  442. User.findById(id, function (err, userData) {
  443. if (!userData) {
  444. return callback(err, null);
  445. }
  446. debug('Removing user:', userData);
  447. // 物理削除可能なのは、承認待ちユーザー、招待中ユーザーのみ
  448. // 利用を一度開始したユーザーは論理削除のみ可能
  449. if (userData.status !== STATUS_REGISTERED && userData.status !== STATUS_INVITED) {
  450. return callback(new Error('Cannot remove completely the user whoes status is not INVITED'), null);
  451. }
  452. userData.remove(function(err) {
  453. if (err) {
  454. return callback(err, null);
  455. }
  456. return callback(null, 1);
  457. });
  458. });
  459. };
  460. userSchema.statics.resetPasswordByRandomString = function(id) {
  461. var User = this;
  462. return new Promise(function(resolve, reject) {
  463. User.findById(id, function (err, userData) {
  464. if (!userData) {
  465. return reject(new Error('User not found'));
  466. }
  467. // is updatable check
  468. // if (userData.isUp
  469. var newPassword = generateRandomTempPassword();
  470. userData.setPassword(newPassword);
  471. userData.save(function(err, userData) {
  472. if (err) {
  473. return reject(err);
  474. }
  475. resolve({user: userData, newPassword: newPassword});
  476. });
  477. });
  478. });
  479. };
  480. userSchema.statics.createUsersByInvitation = function(emailList, toSendEmail, callback) {
  481. var User = this
  482. , createdUserList = []
  483. , config = crowi.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. ,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. password = Math.random().toString(36).slice(-16);
  508. newUser.email = email;
  509. newUser.setPassword(password);
  510. newUser.createdAt = Date.now();
  511. newUser.status = STATUS_INVITED;
  512. newUser.save(function(err, userData) {
  513. if (err) {
  514. createdUserList.push({
  515. email: email,
  516. password: null,
  517. user: null,
  518. });
  519. debug('save failed!! ', email);
  520. } else {
  521. createdUserList.push({
  522. email: email,
  523. password: password,
  524. user: userData,
  525. });
  526. debug('saved!', email);
  527. }
  528. next();
  529. });
  530. });
  531. },
  532. function(err) {
  533. if (err) {
  534. debug('error occured while iterate email list');
  535. }
  536. if (toSendEmail) {
  537. // TODO: メール送信部分のロジックをサービス化する
  538. async.each(
  539. createdUserList,
  540. function(user, next) {
  541. if (user.password === null) {
  542. return next();
  543. }
  544. mailer.send({
  545. to: user.email,
  546. subject: 'Invitation to ' + config.crowi['app:title'],
  547. template: 'admin/userInvitation.txt',
  548. vars: {
  549. email: user.email,
  550. password: user.password,
  551. url: config.crowi['app:url'],
  552. appTitle: config.crowi['app:title'],
  553. }
  554. },
  555. function (err, s) {
  556. debug('completed to send email: ', err, s);
  557. next();
  558. }
  559. );
  560. },
  561. function(err) {
  562. debug('Sending invitation email completed.', err);
  563. }
  564. );
  565. }
  566. debug('createdUserList!!! ', createdUserList);
  567. return callback(null, createdUserList);
  568. }
  569. );
  570. };
  571. userSchema.statics.createUserByEmailAndPasswordAndStatus = function(name, username, email, password, lang, status, callback) {
  572. var User = this
  573. , newUser = new User();
  574. newUser.name = name;
  575. newUser.username = username;
  576. newUser.email = email || generateRandomEmail(); // don't set undefined for backward compatibility -- 2017.12.27 Yuki Takei
  577. if (password != null) {
  578. newUser.setPassword(password);
  579. }
  580. if (lang != null) {
  581. newUser.lang = lang;
  582. }
  583. newUser.createdAt = Date.now();
  584. newUser.status = status || decideUserStatusOnRegistration();
  585. newUser.save(function(err, userData) {
  586. if (err) {
  587. debug('createUserByEmailAndPassword failed: ', err);
  588. return callback(err);
  589. }
  590. if (userData.status == STATUS_ACTIVE) {
  591. userEvent.emit('activated', userData);
  592. }
  593. return callback(err, userData);
  594. });
  595. }
  596. /**
  597. * A wrapper function of createUserByEmailAndPasswordAndStatus
  598. *
  599. * @return {Promise<User>}
  600. */
  601. userSchema.statics.createUserByEmailAndPassword = function(name, username, email, password, lang, callback) {
  602. this.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, undefined, callback);
  603. };
  604. /**
  605. * A wrapper function of createUserByEmailAndPasswordAndStatus
  606. *
  607. * @return {Promise<User>}
  608. */
  609. userSchema.statics.createUser = function(name, username, email, password, lang, status) {
  610. const User = this;
  611. return new Promise((resolve, reject) => {
  612. User.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, status, (err, userData) => {
  613. if (err) {
  614. return reject(err);
  615. }
  616. return resolve(userData);
  617. });
  618. });
  619. }
  620. userSchema.statics.createUserPictureFilePath = function(user, name) {
  621. var ext = '.' + name.match(/(.*)(?:\.([^.]+$))/)[2];
  622. return 'user/' + user._id + ext;
  623. };
  624. userSchema.statics.getUsernameByPath = function(path) {
  625. var username = null;
  626. if (m = path.match(/^\/user\/([^\/]+)\/?/)) {
  627. username = m[1];
  628. }
  629. return username;
  630. };
  631. userSchema.statics.STATUS_REGISTERED = STATUS_REGISTERED;
  632. userSchema.statics.STATUS_ACTIVE = STATUS_ACTIVE;
  633. userSchema.statics.STATUS_SUSPENDED = STATUS_SUSPENDED;
  634. userSchema.statics.STATUS_DELETED = STATUS_DELETED;
  635. userSchema.statics.STATUS_INVITED = STATUS_INVITED;
  636. userSchema.statics.USER_PUBLIC_FIELDS = USER_PUBLIC_FIELDS;
  637. userSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
  638. userSchema.statics.LANG_EN = LANG_EN;
  639. userSchema.statics.LANG_EN_US = LANG_EN_US;
  640. userSchema.statics.LANG_EN_GB = LANG_EN_US;
  641. userSchema.statics.LANG_JA = LANG_JA;
  642. return mongoose.model('User', userSchema);
  643. };