| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 'use strict'
-
- const Joi = require('joi')
- const params = require('../../schemas/params')
-
- const pluginConfig = {
- handlerType: 'password',
- docs: {
- get: {
- description: 'get password',
- notes: 'Returns a password by the user email passed in the path',
- },
- },
- }
-
- /** Validator functions by request method */
- const validators = {
- /** Validate the route params (/active/{thing}) */
- params: params.userEmail,
- }
-
- module.exports = {
- method: 'GET',
- path: '/{user_email}/password',
- options: {
- ...pluginConfig.docs.get,
- tags: ['api'],
- // auth: 'default_jwt',
- auth: false,
- cors: true,
- handler: async function (request, h) {
- try {
- const { userService } = request.services()
- const userEmail = request.params.user_email
-
- const password = await userService.getPassword(userEmail)
-
- return {
- ok: true,
- handler: pluginConfig.handlerType,
- data: { password: password },
- }
- } catch (err) {
- return {
- ok: false,
- handler: pluginConfig.handlerType,
- data: { error: err },
- }
- }
- },
- validate: {
- ...validators,
- failAction: 'log',
- },
-
- response: {
- schema: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: Joi.object(),
- }).label('password_res'),
- failAction: 'log',
- },
- },
- }
|