User.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * User.js
  3. *
  4. * A user who can log in to this application.
  5. */
  6. module.exports = {
  7. attributes: {
  8. // ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
  9. // ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
  10. // ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
  11. emailAddress: {
  12. type: 'string',
  13. required: true,
  14. unique: true,
  15. isEmail: true,
  16. maxLength: 200,
  17. example: 'carol.reyna@microsoft.com'
  18. },
  19. password: {
  20. type: 'string',
  21. required: true,
  22. description: 'Securely hashed representation of the user\'s login password.',
  23. protect: true,
  24. example: '2$28a8eabna301089103-13948134nad'
  25. },
  26. fullName: {
  27. type: 'string',
  28. required: true,
  29. description: 'Full representation of the user\'s name',
  30. maxLength: 120,
  31. example: 'Lisa Microwave van der Jenny'
  32. },
  33. isSuperAdmin: {
  34. type: 'boolean',
  35. description: 'Whether this user is a "super admin" with extra permissions, etc.',
  36. extendedDescription:
  37. `Super admins might have extra permissions, see a different default home page when they log in,
  38. or even have a completely different feature set from normal users. In this app, the \`isSuperAdmin\`
  39. flag is just here as a simple way to represent two different kinds of users. Usually, it's a good idea
  40. to keep the data model as simple as possible, only adding attributes when you actually need them for
  41. features being built right now.
  42. For example, a "super admin" user for a small to medium-sized e-commerce website might be able to
  43. change prices, deactivate seasonal categories, add new offerings, and view live orders as they come in.
  44. On the other hand, for an e-commerce website like Walmart.com that has undergone years of development
  45. by a large team, those administrative features might be split across a few different roles.
  46. So, while this \`isSuperAdmin\` demarcation might not be the right approach forever, it's a good place to start.`
  47. },
  48. passwordResetToken: {
  49. type: 'string',
  50. description: 'A unique token used to verify the user\'s identity when recovering a password. Expires after 1 use, or after a set amount of time has elapsed.'
  51. },
  52. passwordResetTokenExpiresAt: {
  53. type: 'number',
  54. description: 'A JS timestamp (epoch ms) representing the moment when this user\'s `passwordResetToken` will expire (or 0 if the user currently has no such token).',
  55. example: 1502844074211
  56. },
  57. stripeCustomerId: {
  58. type: 'string',
  59. protect: true,
  60. description: 'The id of the customer entry in Stripe associated with this user (or empty string if this user is not linked to a Stripe customer -- e.g. if billing features are not enabled).',
  61. extendedDescription:
  62. `Just because this value is set doesn't necessarily mean that this user has a billing card.
  63. It just means they have a customer entry in Stripe, which might or might not have a billing card.`
  64. },
  65. hasBillingCard: {
  66. type: 'boolean',
  67. description: 'Whether this user has a default billing card hooked up as their payment method.',
  68. extendedDescription:
  69. `More specifically, this indcates whether this user record's linked customer entry in Stripe has
  70. a default payment source (i.e. credit card). Note that a user have a \`stripeCustomerId\`
  71. without necessarily having a billing card.`
  72. },
  73. billingCardBrand: {
  74. type: 'string',
  75. example: 'Visa',
  76. description: 'The brand of this user\'s default billing card (or empty string if no billing card is set up).',
  77. extendedDescription: 'To ensure PCI compliance, this data comes from Stripe, where it reflects the user\'s default payment source.'
  78. },
  79. billingCardLast4: {
  80. type: 'string',
  81. example: '4242',
  82. description: 'The last four digits of the card number for this user\'s default billing card (or empty string if no billing card is set up).',
  83. extendedDescription: 'To ensure PCI compliance, this data comes from Stripe, where it reflects the user\'s default payment source.'
  84. },
  85. billingCardExpMonth: {
  86. type: 'string',
  87. example: '08',
  88. description: 'The two-digit expiration month from this user\'s default billing card, formatted as MM (or empty string if no billing card is set up).',
  89. extendedDescription: 'To ensure PCI compliance, this data comes from Stripe, where it reflects the user\'s default payment source.'
  90. },
  91. billingCardExpYear: {
  92. type: 'string',
  93. example: '2023',
  94. description: 'The four-digit expiration year from this user\'s default billing card, formatted as YYYY (or empty string if no credit card is set up).',
  95. extendedDescription: 'To ensure PCI compliance, this data comes from Stripe, where it reflects the user\'s default payment source.'
  96. },
  97. emailProofToken: {
  98. type: 'string',
  99. description: 'A pseudorandom, probabilistically-unique token for use in our account verification emails.'
  100. },
  101. emailProofTokenExpiresAt: {
  102. type: 'number',
  103. description: 'A JS timestamp (epoch ms) representing the moment when this user\'s `emailProofToken` will expire (or 0 if the user currently has no such token).',
  104. example: 1502844074211
  105. },
  106. emailStatus: {
  107. type: 'string',
  108. isIn: ['unconfirmed', 'changeRequested', 'confirmed'],
  109. defaultsTo: 'confirmed',
  110. description: 'The confirmation status of the user\'s email address.',
  111. extendedDescription:
  112. `Users might be created as "unconfirmed" (e.g. normal signup) or as "confirmed" (e.g. hard-coded
  113. admin users). When the email verification feature is enabled, new users created via the
  114. signup form have \`emailStatus: 'unconfirmed'\` until they click the link in the confirmation email.
  115. Similarly, when an existing user changes their email address, they switch to the "changeRequested"
  116. email status until they click the link in the confirmation email.`
  117. },
  118. emailChangeCandidate: {
  119. type: 'string',
  120. description: 'The (still-unconfirmed) email address that this user wants to change to.'
  121. },
  122. tosAcceptedByIp: {
  123. type: 'string',
  124. description: 'The IP (ipv4) address of the request that accepted the terms of service.',
  125. extendedDescription: 'Useful for certain types of businesses and regulatory requirements (KYC, etc.)',
  126. moreInfoUrl: 'https://en.wikipedia.org/wiki/Know_your_customer'
  127. },
  128. lastSeenAt: {
  129. type: 'number',
  130. description: 'A JS timestamp (epoch ms) representing the moment at which this user most recently interacted with the backend while logged in (or 0 if they have not interacted with the backend at all yet).',
  131. example: 1502844074211
  132. },
  133. // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
  134. // ║╣ ║║║╠╩╗║╣ ║║╚═╗
  135. // ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
  136. // n/a
  137. // ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
  138. // ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
  139. // ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
  140. // n/a
  141. },
  142. };