User.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. const request = require('./request')
  2. const settings = require('@overleaf/settings')
  3. const { db, ObjectId } = require('../../../../app/src/infrastructure/mongodb')
  4. const UserModel = require('../../../../app/src/models/User').User
  5. const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
  6. const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager')
  7. const { promisify } = require('util')
  8. const fs = require('fs')
  9. const Path = require('path')
  10. let count = settings.test.counterInit
  11. class User {
  12. constructor(options) {
  13. if (options == null) {
  14. options = {}
  15. }
  16. this.emails = [
  17. {
  18. email: options.email || `acceptance-test-${count}@example.com`,
  19. createdAt: new Date(),
  20. confirmedAt: options.confirmedAt,
  21. },
  22. ]
  23. this.email = this.emails[0].email
  24. this.password = `a-terrible-secret-${count}`
  25. count++
  26. this.jar = request.jar()
  27. this.request = request.defaults({
  28. jar: this.jar,
  29. })
  30. }
  31. setExtraAttributes(user) {
  32. if ((user != null ? user._id : undefined) == null) {
  33. throw new Error('User does not exist')
  34. }
  35. this.id = user._id.toString()
  36. this._id = user._id.toString()
  37. this.first_name = user.first_name
  38. this.referal_id = user.referal_id
  39. }
  40. get(callback) {
  41. db.users.findOne({ _id: ObjectId(this._id) }, callback)
  42. }
  43. getAuditLog(callback) {
  44. this.get((error, user) => {
  45. if (error) return callback(error)
  46. if (!user) return callback(new Error('User not found'))
  47. db.userAuditLogEntries
  48. .find({ userId: ObjectId(this._id) })
  49. .toArray((error, auditLog) => {
  50. if (error) return callback(error)
  51. callback(null, auditLog || [])
  52. })
  53. })
  54. }
  55. getAuditLogWithoutNoise(callback) {
  56. this.getAuditLog((error, auditLog) => {
  57. if (error) return callback(error)
  58. callback(
  59. null,
  60. auditLog.filter(entry => {
  61. return entry.operation !== 'login'
  62. })
  63. )
  64. })
  65. }
  66. mongoUpdate(updateOp, callback) {
  67. db.users.updateOne({ _id: ObjectId(this._id) }, updateOp, callback)
  68. }
  69. register(callback) {
  70. this.registerWithQuery('', callback)
  71. }
  72. registerWithQuery(query, callback) {
  73. if (this._id != null) {
  74. return callback(new Error('User already registered'))
  75. }
  76. this.getCsrfToken(error => {
  77. if (error != null) {
  78. return callback(error)
  79. }
  80. this.request.post(
  81. {
  82. url: `/register${query}`,
  83. json: { email: this.email, password: this.password },
  84. },
  85. (error, response, body) => {
  86. if (error != null) {
  87. return callback(error)
  88. }
  89. db.users.findOne({ email: this.email }, (error, user) => {
  90. if (error != null) {
  91. return callback(error)
  92. }
  93. this.setExtraAttributes(user)
  94. callback(null, user)
  95. })
  96. }
  97. )
  98. })
  99. }
  100. login(callback) {
  101. this.loginWith(this.email, callback)
  102. }
  103. loginWith(email, callback) {
  104. this.ensureUserExists(error => {
  105. if (error != null) {
  106. return callback(error)
  107. }
  108. this.loginWithEmailPassword(email, this.password, callback)
  109. })
  110. }
  111. loginNoUpdate(callback) {
  112. this.loginWithEmailPassword(this.email, this.password, callback)
  113. }
  114. loginWithEmailPassword(email, password, callback) {
  115. this.getCsrfToken(error => {
  116. if (error != null) {
  117. return callback(error)
  118. }
  119. this.request.post(
  120. {
  121. url: settings.enableLegacyLogin ? '/login/legacy' : '/login',
  122. json: {
  123. email,
  124. password,
  125. 'g-recaptcha-response': 'valid',
  126. },
  127. },
  128. (error, response, body) => {
  129. if (error != null) {
  130. return callback(error)
  131. }
  132. // get new csrf token, then return result of login
  133. this.getCsrfToken(err => {
  134. if (err) {
  135. return callback(err)
  136. }
  137. callback(null, response, body)
  138. })
  139. }
  140. )
  141. })
  142. }
  143. ensureUserExists(callback) {
  144. const filter = { email: this.email }
  145. const options = { upsert: true, new: true, setDefaultsOnInsert: true }
  146. AuthenticationManager.hashPassword(
  147. this.password,
  148. (error, hashedPassword) => {
  149. if (error != null) {
  150. return callback(error)
  151. }
  152. UserModel.findOneAndUpdate(
  153. filter,
  154. { $set: { hashedPassword, emails: this.emails } },
  155. options,
  156. (error, user) => {
  157. if (error != null) {
  158. return callback(error)
  159. }
  160. this.setExtraAttributes(user)
  161. callback(null, this.password)
  162. }
  163. )
  164. }
  165. )
  166. }
  167. setFeatures(features, callback) {
  168. const update = {}
  169. for (const key in features) {
  170. const value = features[key]
  171. update[`features.${key}`] = value
  172. }
  173. UserModel.updateOne({ _id: this.id }, update, callback)
  174. }
  175. setFeaturesOverride(featuresOverride, callback) {
  176. const update = { $push: { featuresOverrides: featuresOverride } }
  177. UserModel.updateOne({ _id: this.id }, update, callback)
  178. }
  179. setOverleafId(overleafId, callback) {
  180. UserModel.updateOne(
  181. { _id: this.id },
  182. { 'overleaf.id': overleafId },
  183. callback
  184. )
  185. }
  186. logout(callback) {
  187. this.getCsrfToken(error => {
  188. if (error != null) {
  189. return callback(error)
  190. }
  191. this.request.post(
  192. {
  193. url: '/logout',
  194. json: {
  195. email: this.email,
  196. password: this.password,
  197. },
  198. },
  199. (error, response, body) => {
  200. if (error != null) {
  201. return callback(error)
  202. }
  203. db.users.findOne({ email: this.email }, (error, user) => {
  204. if (error != null) {
  205. return callback(error)
  206. }
  207. if (user == null) {
  208. return callback()
  209. }
  210. this.id = user._id.toString()
  211. this._id = user._id.toString()
  212. callback()
  213. })
  214. }
  215. )
  216. })
  217. }
  218. addEmail(email, callback) {
  219. this.emails.push({ email, createdAt: new Date() })
  220. UserUpdater.addEmailAddress(
  221. this.id,
  222. email,
  223. {},
  224. { initiatorId: this._id, ipAddress: '127:0:0:0' },
  225. callback
  226. )
  227. }
  228. confirmEmail(email, callback) {
  229. for (let idx = 0; idx < this.emails.length; idx++) {
  230. const emailData = this.emails[idx]
  231. if (emailData.email === email) {
  232. this.emails[idx].confirmedAt = new Date()
  233. }
  234. }
  235. UserUpdater.confirmEmail(this.id, email, callback)
  236. }
  237. ensureAdmin(callback) {
  238. this.mongoUpdate({ $set: { isAdmin: true } }, callback)
  239. }
  240. ensureStaffAccess(flag, callback) {
  241. const update = { $set: {} }
  242. update.$set[`staffAccess.${flag}`] = true
  243. this.mongoUpdate(update, callback)
  244. }
  245. upgradeFeatures(callback) {
  246. const features = {
  247. collaborators: -1, // Infinite
  248. versioning: true,
  249. dropbox: true,
  250. compileTimeout: 60,
  251. compileGroup: 'priority',
  252. templates: true,
  253. references: true,
  254. trackChanges: true,
  255. trackChangesVisible: true,
  256. }
  257. this.mongoUpdate({ $set: { features } }, callback)
  258. }
  259. downgradeFeatures(callback) {
  260. const features = {
  261. collaborators: 1,
  262. versioning: false,
  263. dropbox: false,
  264. compileTimeout: 60,
  265. compileGroup: 'standard',
  266. templates: false,
  267. references: false,
  268. trackChanges: false,
  269. trackChangesVisible: false,
  270. }
  271. this.mongoUpdate({ $set: { features } }, callback)
  272. }
  273. defaultFeatures(callback) {
  274. const features = settings.defaultFeatures
  275. this.mongoUpdate({ $set: { features } }, callback)
  276. }
  277. getFeatures(callback) {
  278. db.users.findOne(
  279. { _id: ObjectId(this.id) },
  280. { projection: { features: 1 } },
  281. (error, user) => callback(error, user && user.features)
  282. )
  283. }
  284. fullDeleteUser(email, callback) {
  285. db.users.findOne({ email }, (error, user) => {
  286. if (error != null) {
  287. return callback(error)
  288. }
  289. if (user == null) {
  290. return callback()
  291. }
  292. const userId = user._id
  293. db.projects.deleteMany({ owner_ref: ObjectId(userId) }, err => {
  294. if (err != null) {
  295. callback(err)
  296. }
  297. db.users.deleteOne({ _id: ObjectId(userId) }, callback)
  298. })
  299. })
  300. }
  301. deleteUser(callback) {
  302. this.getCsrfToken(error => {
  303. if (error) {
  304. return callback(error)
  305. }
  306. this.request.post(
  307. {
  308. url: '/user/delete',
  309. json: { password: this.password },
  310. },
  311. (err, res) => {
  312. if (err) {
  313. return callback(err)
  314. }
  315. if (res.statusCode < 200 || res.statusCode >= 300) {
  316. return callback(
  317. new Error('Error received from API: ' + res.statusCode)
  318. )
  319. }
  320. callback()
  321. }
  322. )
  323. })
  324. }
  325. getProject(projectId, callback) {
  326. db.projects.findOne({ _id: ObjectId(projectId.toString()) }, callback)
  327. }
  328. saveProject(project, callback) {
  329. db.projects.updateOne({ _id: project._id }, { $set: project }, callback)
  330. }
  331. createProject(name, options, callback) {
  332. if (typeof options === 'function') {
  333. callback = options
  334. options = {}
  335. }
  336. this.request.post(
  337. {
  338. url: '/project/new',
  339. json: Object.assign({ projectName: name }, options),
  340. },
  341. (error, response, body) => {
  342. if (error != null) {
  343. return callback(error)
  344. }
  345. if ((body != null ? body.project_id : undefined) == null) {
  346. error = new Error(
  347. JSON.stringify([
  348. 'SOMETHING WENT WRONG CREATING PROJECT',
  349. name,
  350. options,
  351. response.statusCode,
  352. response.headers.location,
  353. body,
  354. ])
  355. )
  356. callback(error)
  357. } else {
  358. callback(null, body.project_id)
  359. }
  360. }
  361. )
  362. }
  363. deleteProject(projectId, callback) {
  364. this.request.delete(
  365. {
  366. url: `/project/${projectId}`,
  367. },
  368. (error, response, body) => {
  369. if (error != null) {
  370. return callback(error)
  371. }
  372. callback(null)
  373. }
  374. )
  375. }
  376. undeleteProject(projectId, callback) {
  377. this.request.post(
  378. {
  379. url: `/admin/project/${projectId}/undelete`,
  380. },
  381. (error, response) => {
  382. if (error) {
  383. return callback(error)
  384. }
  385. if (response.statusCode !== 204) {
  386. return callback(
  387. new Error(
  388. `Non-success response when undeleting project: ${response.statusCode}`
  389. )
  390. )
  391. }
  392. callback(null)
  393. }
  394. )
  395. }
  396. deleteProjects(callback) {
  397. db.projects.deleteMany({ owner_ref: ObjectId(this.id) }, callback)
  398. }
  399. openProject(projectId, callback) {
  400. this.request.get(
  401. {
  402. url: `/project/${projectId}`,
  403. },
  404. (error, response, body) => {
  405. if (error != null) {
  406. return callback(error)
  407. }
  408. if (response.statusCode !== 200) {
  409. const err = new Error(
  410. `Non-success response when opening project: ${response.statusCode}`
  411. )
  412. return callback(err)
  413. }
  414. callback(null)
  415. }
  416. )
  417. }
  418. createDocInProject(projectId, parentFolderId, name, callback) {
  419. this.getCsrfToken(error => {
  420. if (error != null) {
  421. return callback(error)
  422. }
  423. this.request.post(
  424. {
  425. url: `/project/${projectId}/doc`,
  426. json: {
  427. name,
  428. parentFolderId,
  429. },
  430. },
  431. (error, response, body) => {
  432. if (error != null) {
  433. return callback(error)
  434. }
  435. callback(null, body._id)
  436. }
  437. )
  438. })
  439. }
  440. uploadFileInProject(projectId, folderId, file, name, contentType, callback) {
  441. const imageFile = fs.createReadStream(
  442. Path.resolve(Path.join(__dirname, '..', '..', 'files', file))
  443. )
  444. this.request.post(
  445. {
  446. uri: `project/${projectId}/upload`,
  447. qs: {
  448. folder_id: String(folderId),
  449. },
  450. formData: {
  451. name,
  452. qqfile: {
  453. value: imageFile,
  454. options: {
  455. filename: name,
  456. contentType,
  457. },
  458. },
  459. },
  460. },
  461. (error, res, body) => {
  462. if (error) {
  463. return callback(error)
  464. }
  465. if (res.statusCode < 200 || res.statusCode >= 300) {
  466. return callback(new Error(`failed to upload file ${res.statusCode}`))
  467. }
  468. callback(null, JSON.parse(body).entity_id)
  469. }
  470. )
  471. }
  472. uploadExampleFileInProject(projectId, folderId, name, callback) {
  473. this.uploadFileInProject(
  474. projectId,
  475. folderId,
  476. '1pixel.png',
  477. name,
  478. 'image/png',
  479. callback
  480. )
  481. }
  482. moveItemInProject(projectId, type, itemId, folderId, callback) {
  483. this.request.post(
  484. {
  485. uri: `project/${projectId}/${type}/${itemId}/move`,
  486. json: {
  487. folder_id: folderId,
  488. },
  489. },
  490. (error, res) => {
  491. if (error) {
  492. return callback(error)
  493. }
  494. if (res.statusCode < 200 || res.statusCode >= 300) {
  495. return callback(new Error(`failed to move ${type} ${res.statusCode}`))
  496. }
  497. callback()
  498. }
  499. )
  500. }
  501. renameItemInProject(projectId, type, itemId, name, callback) {
  502. this.request.post(
  503. {
  504. uri: `project/${projectId}/${type}/${itemId}/rename`,
  505. json: {
  506. name,
  507. },
  508. },
  509. (error, res) => {
  510. if (error) {
  511. return callback(error)
  512. }
  513. if (res.statusCode < 200 || res.statusCode >= 300) {
  514. return callback(
  515. new Error(`failed to rename ${type} ${res.statusCode}`)
  516. )
  517. }
  518. callback()
  519. }
  520. )
  521. }
  522. deleteItemInProject(projectId, type, itemId, callback) {
  523. this.request.delete(
  524. `project/${projectId}/${type}/${itemId}`,
  525. (error, res) => {
  526. if (error) {
  527. return callback(error)
  528. }
  529. if (res.statusCode < 200 || res.statusCode >= 300) {
  530. return callback(
  531. new Error(`failed to delete ${type} ${res.statusCode}`)
  532. )
  533. }
  534. callback()
  535. }
  536. )
  537. }
  538. joinProject(projectId, callback) {
  539. this.request.post(
  540. {
  541. url: `/project/${projectId}/join`,
  542. qs: { user_id: this._id },
  543. auth: {
  544. user: settings.apis.web.user,
  545. pass: settings.apis.web.pass,
  546. sendImmediately: true,
  547. },
  548. json: true,
  549. jar: false,
  550. },
  551. (error, res, body) => {
  552. if (error) {
  553. return callback(error)
  554. }
  555. if (res.statusCode < 200 || res.statusCode >= 300) {
  556. return callback(
  557. new Error(`failed to join project ${projectId} ${res.statusCode}`)
  558. )
  559. }
  560. callback(null, body)
  561. }
  562. )
  563. }
  564. addUserToProject(projectId, user, privileges, callback) {
  565. let updateOp
  566. if (privileges === 'readAndWrite') {
  567. updateOp = { $addToSet: { collaberator_refs: user._id } }
  568. } else if (privileges === 'readOnly') {
  569. updateOp = { $addToSet: { readOnly_refs: user._id } }
  570. }
  571. db.projects.updateOne({ _id: ObjectId(projectId) }, updateOp, callback)
  572. }
  573. makePublic(projectId, level, callback) {
  574. // A fudge, to get around the fact that `readOnly` and `readAndWrite` are now disallowed
  575. // via the API, but we still need to test the behaviour of projects with these values set.
  576. db.projects.updateOne(
  577. { _id: ObjectId(projectId) },
  578. // NOTE: Yes, there is a typo in the db schema.
  579. { $set: { publicAccesLevel: level } },
  580. callback
  581. )
  582. }
  583. makePrivate(projectId, callback) {
  584. this.request.post(
  585. {
  586. url: `/project/${projectId}/settings/admin`,
  587. json: {
  588. publicAccessLevel: 'private',
  589. },
  590. },
  591. (error, response, body) => {
  592. if (error != null) {
  593. return callback(error)
  594. }
  595. callback(null)
  596. }
  597. )
  598. }
  599. makeTokenBased(projectId, callback) {
  600. this.request.post(
  601. {
  602. url: `/project/${projectId}/settings/admin`,
  603. json: {
  604. publicAccessLevel: 'tokenBased',
  605. },
  606. },
  607. (error, response, body) => {
  608. if (error != null) {
  609. return callback(error)
  610. }
  611. callback(null)
  612. }
  613. )
  614. }
  615. getCsrfToken(callback) {
  616. this.request.get(
  617. {
  618. url: '/dev/csrf',
  619. },
  620. (err, response, body) => {
  621. if (err != null) {
  622. return callback(err)
  623. }
  624. this.csrfToken = body
  625. this.request = this.request.defaults({
  626. headers: {
  627. 'x-csrf-token': this.csrfToken,
  628. },
  629. })
  630. callback()
  631. }
  632. )
  633. }
  634. changePassword(newPassword, callback) {
  635. this.getCsrfToken(error => {
  636. if (error != null) {
  637. return callback(error)
  638. }
  639. this.request.post(
  640. {
  641. url: '/user/password/update',
  642. json: {
  643. currentPassword: this.password,
  644. newPassword1: newPassword,
  645. newPassword2: newPassword,
  646. },
  647. },
  648. err => {
  649. if (err) {
  650. return callback(err)
  651. }
  652. this.password = newPassword
  653. callback()
  654. }
  655. )
  656. })
  657. }
  658. reconfirmAccountRequest(userEmail, callback) {
  659. this.getCsrfToken(error => {
  660. if (error != null) {
  661. return callback(error)
  662. }
  663. this.request.post(
  664. {
  665. url: '/user/reconfirm',
  666. json: {
  667. email: userEmail,
  668. },
  669. },
  670. (error, response, body) => {
  671. callback(error, response)
  672. }
  673. )
  674. })
  675. }
  676. getUserSettingsPage(callback) {
  677. this.getCsrfToken(error => {
  678. if (error != null) {
  679. return callback(error)
  680. }
  681. this.request.get(
  682. {
  683. url: '/user/settings',
  684. },
  685. (error, response, body) => {
  686. if (error != null) {
  687. return callback(error)
  688. }
  689. callback(null, response.statusCode)
  690. }
  691. )
  692. })
  693. }
  694. updateSettings(newSettings, callback) {
  695. this.getCsrfToken(error => {
  696. if (error != null) {
  697. return callback(error)
  698. }
  699. this.request.post(
  700. {
  701. url: '/user/settings',
  702. json: newSettings,
  703. },
  704. callback
  705. )
  706. })
  707. }
  708. getProjectListPage(callback) {
  709. this.getCsrfToken(error => {
  710. if (error != null) {
  711. return callback(error)
  712. }
  713. this.request.get(
  714. {
  715. url: '/project',
  716. },
  717. (error, response, body) => {
  718. if (error != null) {
  719. return callback(error)
  720. }
  721. callback(null, response.statusCode)
  722. }
  723. )
  724. })
  725. }
  726. isLoggedIn(callback) {
  727. this.request.get('/user/personal_info', (error, response, body) => {
  728. if (error != null) {
  729. return callback(error)
  730. }
  731. if (response.statusCode === 200) {
  732. callback(null, true)
  733. } else if (response.statusCode === 302) {
  734. callback(null, false)
  735. } else {
  736. callback(
  737. new Error(
  738. `unexpected status code from /user/personal_info: ${response.statusCode}`
  739. )
  740. )
  741. }
  742. })
  743. }
  744. transferProjectOwnership(projectId, userId, callback) {
  745. this.getCsrfToken(err => {
  746. if (err != null) {
  747. return callback(err)
  748. }
  749. this.request.post(
  750. {
  751. url: `/project/${projectId.toString()}/transfer-ownership`,
  752. json: {
  753. user_id: userId.toString(),
  754. },
  755. },
  756. (err, response) => {
  757. if (err != null) {
  758. return callback(err)
  759. }
  760. if (response.statusCode !== 204) {
  761. return callback(
  762. new Error(`Unexpected status code: ${response.statusCode}`)
  763. )
  764. }
  765. callback()
  766. }
  767. )
  768. })
  769. }
  770. setV1Id(v1Id, callback) {
  771. UserModel.updateOne(
  772. {
  773. _id: this._id,
  774. },
  775. {
  776. overleaf: {
  777. id: v1Id,
  778. },
  779. },
  780. callback
  781. )
  782. }
  783. setCollaboratorInfo(projectId, userId, info, callback) {
  784. this.getCsrfToken(err => {
  785. if (err != null) {
  786. return callback(err)
  787. }
  788. this.request.put(
  789. {
  790. url: `/project/${projectId.toString()}/users/${userId.toString()}`,
  791. json: info,
  792. },
  793. (err, response) => {
  794. if (err != null) {
  795. return callback(err)
  796. }
  797. if (response.statusCode !== 204) {
  798. return callback(
  799. new Error(`Unexpected status code: ${response.statusCode}`)
  800. )
  801. }
  802. callback()
  803. }
  804. )
  805. })
  806. }
  807. }
  808. User.promises = class extends User {
  809. doRequest(method, params) {
  810. return new Promise((resolve, reject) => {
  811. this.request[method.toLowerCase()](params, (err, response, body) => {
  812. if (err) {
  813. reject(err)
  814. } else {
  815. resolve({ response, body })
  816. }
  817. })
  818. })
  819. }
  820. }
  821. // promisify User class methods - works for methods with 0-1 output parameters,
  822. // otherwise we will need to implement the method manually instead
  823. const nonPromiseMethods = ['constructor', 'setExtraAttributes']
  824. Object.getOwnPropertyNames(User.prototype).forEach(methodName => {
  825. const method = User.prototype[methodName]
  826. if (typeof method === 'function' && !nonPromiseMethods.includes(methodName)) {
  827. User.promises.prototype[methodName] = promisify(method)
  828. }
  829. })
  830. module.exports = User