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

authentication.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. opts: {
  13. tags: ['api'],
  14. auth: { strategy: 'default_jwt' },
  15. cors: true,
  16. },
  17. }
  18. /** Validator functions by request method */
  19. const validators = {
  20. /** Validate the route params (/active/{thing}) */
  21. params: params.userEmail,
  22. }
  23. module.exports = {
  24. method: 'GET',
  25. path: '/{user_email}/password',
  26. options: {
  27. ...pluginConfig.docs.get,
  28. ...pluginConfig.opts,
  29. handler: async function (request, h) {
  30. try {
  31. const { userService } = request.services()
  32. const userEmail = request.params.user_email
  33. const password = await userService.getPassword(userEmail)
  34. return {
  35. ok: true,
  36. handler: pluginConfig.handlerType,
  37. data: { password: password },
  38. }
  39. } catch (err) {
  40. return {
  41. ok: false,
  42. handler: pluginConfig.handlerType,
  43. data: { error: err },
  44. }
  45. }
  46. },
  47. validate: {
  48. ...validators,
  49. failAction: 'log',
  50. },
  51. response: {
  52. schema: Joi.object({
  53. ok: Joi.bool(),
  54. handler: Joi.string(),
  55. data: Joi.object(),
  56. }).label('password_res'),
  57. failAction: 'log',
  58. },
  59. },
  60. }