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 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 userEmail = request.payload.email
  23. try {
  24. const emailSent = await userService.emailSent(userEmail)
  25. return {
  26. ok: true,
  27. handler: pluginConfig.handlerType,
  28. data: { emailSentSuccessfully: emailSent.wasSuccessfull },
  29. }
  30. } catch (err) {
  31. return {
  32. ok: false,
  33. handler: pluginConfig.handlerType,
  34. data: {
  35. error: err,
  36. },
  37. }
  38. }
  39. },
  40. validate: {
  41. failAction: 'log',
  42. },
  43. response: {
  44. schema: Joi.object({
  45. ok: Joi.bool(),
  46. handler: Joi.string(),
  47. data: Joi.object(),
  48. }).label('email_res'),
  49. failAction: 'log',
  50. },
  51. },
  52. }