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

authentication.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict'
  2. const Joi = require('joi')
  3. const params = require('../../schemas/params')
  4. const pluginConfig = {
  5. handlerType: 'password',
  6. docs: {
  7. get: {
  8. description: 'get password',
  9. notes: 'Returns a password by the user email passed in the path',
  10. },
  11. },
  12. }
  13. /** Validator functions by request method */
  14. const validators = {
  15. /** Validate the route params (/active/{thing}) */
  16. params: params.userEmail
  17. }
  18. module.exports = {
  19. method: 'GET',
  20. path: '/{user_email}/password',
  21. options: {
  22. ...pluginConfig.docs.get,
  23. tags: ['api'],
  24. // auth: 'default_jwt',
  25. auth: false,
  26. handler: async function (request, h) {
  27. try {
  28. const userEmail = request.params.user_email
  29. const { userService } = request.services()
  30. const password = userService.getPassword(userEmail)
  31. return {
  32. ok: true,
  33. handler: pluginConfig.handlerType,
  34. data: { password: password },
  35. }
  36. } catch (err) {
  37. return {
  38. ok: false,
  39. handler: pluginConfig.handlerType,
  40. data: { error: err },
  41. }
  42. }
  43. },
  44. validate: {
  45. ...validators,
  46. failAction: 'log',
  47. },
  48. response: {
  49. schema: Joi.object({
  50. ok: Joi.bool(),
  51. handler: Joi.string(),
  52. data: Joi.object(),
  53. }).label('password_res'),
  54. failAction: 'log',
  55. },
  56. },
  57. }