Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

verifyemail.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'email',
  5. docs: {
  6. get: {
  7. description: 'verifies confirmation email',
  8. notes: 'Verifies the email from the stored hash',
  9. },
  10. },
  11. }
  12. module.exports = {
  13. method: 'GET',
  14. path: '/verify/{hash}',
  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 hashToMatch = await userService.hashedEmail
  23. const hash = request.params.hash
  24. const hashesMatch = hashToMatch === hash ? true : false
  25. try {
  26. if (hashesMatch) {
  27. return {
  28. ok: true,
  29. handler: pluginConfig.handlerType,
  30. data: { hashesMatch: hashesMatch },
  31. }
  32. }
  33. } catch (err) {
  34. return {
  35. ok: false,
  36. handler: pluginConfig.handlerType,
  37. data: {
  38. error: err,
  39. },
  40. }
  41. }
  42. },
  43. validate: {
  44. failAction: 'log',
  45. },
  46. response: {
  47. schema: Joi.object({
  48. ok: Joi.bool(),
  49. handler: Joi.string(),
  50. data: Joi.object(),
  51. }).label('verify_email_res'),
  52. failAction: 'log',
  53. },
  54. },
  55. }