var express = require('express');
var router = express.Router();

// Login a user with basic auth
router.post('/', function (req, res, next) {});

module.exports = router;

@@ -57,16 +57,153 @@
 outer();
+%0Avar auth = require('../../utils/auth');%0Avar _ = require('lodash');%0Avar JsonDB = require('node-json-db');%0Avar crypto = require('crypto');
 %0A%0A// Log
@@ -244,16 +244,28 @@
 ost('/',
+ auth.basic,
  functio
@@ -284,16 +284,817 @@
  next) %7B
+%0A  var db = new JsonDB('db', false, true);%0A  var users = db.getData('/users');%0A%0A  function sendError() %7B%0A    res.status(500).json(%7B%0A      success: false,%0A      message: 'Unable to authenticate user.'%0A    %7D);%0A  %7D%0A%0A  // Find the auth user to update last login%0A  var i = _.findIndex(users, %7Busername: req.user.username%7D);%0A  crypto.randomBytes(16, function(err, buf) %7B%0A    if (!err) %7B%0A      var ret = _.attempt(db.push.bind(db), '/users%5B'+i+'%5D', %7B%0A        last_login: _.now(),%0A        token: buf.toString('hex')%0A      %7D, false);%0A%0A      if (!_.isError(ret)) %7B%0A        res.json(%7B%0A          success: true,%0A          message: 'Successfully authenticated user.',%0A          token: buf.toString('hex')%0A        %7D);%0A      %7D%0A      else %7B%0A        sendError();%0A      %7D%0A    %7D%0A    else %7B%0A      sendError();%0A    %7D%0A  %7D);%0A
 %7D);%0A%0Amod

Add section 6.1 code to provide login for users