Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

email.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'email',
  5. docs: {
  6. get: {
  7. description: 'sends confirmation email',
  8. notes: 'Stores the email in memory in a hash and sends confirmation email for signup',
  9. },
  10. },
  11. }
  12. module.exports = {
  13. method: 'POST',
  14. path: '/sendemail/',
  15. options: {
  16. ...pluginConfig.docs.get,
  17. tags: ['api'],
  18. auth: false,
  19. cors: true,
  20. handler: async function (request, h) {
  21. const { userService } = request.server.services()
  22. const userCredentials = request.payload
  23. try {
  24. const emailSent = await userService.emailSent(userCredentials)
  25. const hashedSessionToken = Object.keys(
  26. userService.activeSessions,
  27. ).find(hashedToken => {
  28. return (
  29. userService.activeSessions[`${hashedToken}`].email ===
  30. userCredentials.email
  31. )
  32. })
  33. if (!hashedSessionToken.length) {
  34. throw Error('hashedSessionToken not Found!!')
  35. }
  36. return {
  37. ok: true,
  38. handler: pluginConfig.handlerType,
  39. data: {
  40. emailSentSuccessfully: emailSent.wasSuccessfull,
  41. hashedSessionToken: hashedSessionToken,
  42. },
  43. }
  44. } catch (err) {
  45. console.log('err :=>', err)
  46. return {
  47. ok: false,
  48. handler: pluginConfig.handlerType,
  49. data: {
  50. error: err,
  51. },
  52. }
  53. }
  54. },
  55. validate: {
  56. failAction: 'log',
  57. },
  58. response: {
  59. schema: Joi.object({
  60. ok: Joi.bool(),
  61. handler: Joi.string(),
  62. data: Joi.object(),
  63. }).label('email_res'),
  64. failAction: 'log',
  65. },
  66. },
  67. }