Вы не можете выбрать более 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. cors: true,
  27. handler: async function (request, h) {
  28. try {
  29. const { userService } = request.services()
  30. const userEmail = request.params.user_email
  31. const password = await userService.getPassword(userEmail)
  32. return {
  33. ok: true,
  34. handler: pluginConfig.handlerType,
  35. data: { password: password },
  36. }
  37. } catch (err) {
  38. return {
  39. ok: false,
  40. handler: pluginConfig.handlerType,
  41. data: { error: err },
  42. }
  43. }
  44. },
  45. validate: {
  46. ...validators,
  47. failAction: 'log',
  48. },
  49. response: {
  50. schema: Joi.object({
  51. ok: Joi.bool(),
  52. handler: Joi.string(),
  53. data: Joi.object(),
  54. }).label('password_res'),
  55. failAction: 'log',
  56. },
  57. },
  58. }