You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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