Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2. /**
  3.  * Route definition for authentication/authorization endpoints.
  4.  * @author Challenge.IT
  5.  */
  6. const Boom = require('boom')
  7. const Joi = require('joi')
  8.  
  9. module.exports = (server, opts) => {
  10.  
  11.     /*
  12.         Command example:
  13.         $ curl -i -H 'Content-Type: application/json' -d '{"username": "rikmms", "password": "admin"}' http://localhost:3000/login
  14.      */
  15.     server.route({
  16.         method: 'POST',
  17.         path: '/login',
  18.         handler: function(request, reply) {
  19.             opts.customProvider.login(request.payload.username, request.payload.password, (err, user) => {
  20.                 reply(err? (err.code? Boom.badRequest(err.message) : err) : null, {user: user})
  21.             })
  22.         },
  23.         config: {
  24.             auth: false,
  25.             validate: {
  26.                 payload: {
  27.                     username: Joi.string().required(),
  28.                     password: Joi.string().required()
  29.                 }
  30.             }
  31.         }
  32.     })
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement