var requireAll = require('../lib/require-all');
var passport = require('./initializers/passport.js');
var ctrls = requireAll({
  dirname: __dirname + '/../app/controllers',
  filter: /(.+)\.js(on)?$/
})

module.exports = (function(){
  function configure(app) {
    app.get('/', function(req, res){ res.render('index.html') })
    /////////////////////////
    //  Unauthenticated Resources

    app.get('/api/v1/gateway/settings', ctrls['settings'].index);
    app.post('/api/v1/gateway/users', ctrls['users'].create)
    app.post('/api/v1/admin/users', ctrls['users'].createAdmin);

    ////////////////////////
    // User Authenticated Resources

    app.get('/api/v1/users/:id/ripple_addresses', ctrls['ripple_addresses'].userIndex);

    app.get('/api/v1/users/:id/ripple_transactions', ctrls['ripple_transactions'].index);
    app.post('/api/v1/users/:user_id/ripple_transactions', ctrls['ripple_transactions'].create);

    app.get('/api/v1/users/:id/external_accounts', ctrls['external_accounts'].index);
    app.post('/api/v1/users/:id/external_accounts', ctrls['external_accounts'].create);

    app.get('/api/v1/users/:id/external_transactions', ctrls['external_transactions'].userIndex);
    app.post('/api/v1/users/:id/external_transactions', ctrls['external_transactions'].create);

    app.get('/api/v1/users/:id/balances', ctrls['balances'].userIndex);

    app.post('/api/v1/gateway/users/login', 
      passport.authenticate('basic', { session: false }),
      ctrls['users'].login);

    app.get('/api/v1/gateway/user', 
      passport.authenticate('basic', { session: false }), 
      ctrls['users'].show);

    /////////////////////////
    // Admin Authenticated Resources

    app.get('/api/v1/users', ctrls['users'].index);
    app.get('/api/v1/external_transactions', ctrls['external_transactions'].index);

    /////////////////////////
  }

  return { route: configure }
})()

@@ -421,24 +421,90 @@
 /settings', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'setti
@@ -509,32 +509,33 @@
 tings'%5D.index);%0A
+%0A
     app.post('/a
@@ -548,32 +548,98 @@
 gateway/users', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'users'%5D.c
@@ -645,16 +645,17 @@
 create)%0A
+%0A
     app.
@@ -674,32 +674,98 @@
 1/admin/users', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'users'%5D.c
@@ -890,24 +890,90 @@
 addresses', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'rippl
@@ -1044,32 +1044,98 @@
 _transactions', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'ripple_tr
@@ -1147,32 +1147,33 @@
 tions'%5D.index);%0A
+%0A
     app.post('/a
@@ -1211,24 +1211,90 @@
 nsactions', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'rippl
@@ -1363,32 +1363,98 @@
 rnal_accounts', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'external_
@@ -1464,32 +1464,33 @@
 ounts'%5D.index);%0A
+%0A
     app.post('/a
@@ -1521,24 +1521,90 @@
 _accounts', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'exter
@@ -1675,32 +1675,98 @@
 _transactions', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'external_
@@ -1788,24 +1788,25 @@
 userIndex);%0A
+%0A
     app.post
@@ -1841,32 +1841,98 @@
 _transactions', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'external_
@@ -1994,24 +1994,90 @@
 /balances', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'balan
@@ -2446,24 +2446,31 @@
 /v1/users', 
+%0A      
 ctrls%5B'users
@@ -2480,16 +2480,17 @@
 index);%0A
+%0A
     app.
@@ -2526,16 +2526,82 @@
 tions', 
+%0A      passport.authentication('basic', %7B session: false %7D,%0A      
 ctrls%5B'e

Add Basic Auth to all but one resource.