Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
added working sample
Browse files Browse the repository at this point in the history
  • Loading branch information
cicorias committed Mar 2, 2016
1 parent 3f19860 commit 12c60c7
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 29 deletions.
91 changes: 91 additions & 0 deletions lib/fauxton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";

module.exports = [{
"path": "/_utils",
"roles": [{
"role": "public",
"verbs": ["get"]
}, {
"role": "user",
"verbs": ["get"]
}]
},
{
"path": "/db",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
},
{
"path": "/_utils/css",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
},
{
"path": "/_utils/js",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
}, {
"path": "/_utils/img",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
}, {
"path": "/_session",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
}, {
"path": "/_utils/fonts",
"roles": [{
"role": "public",
"verbs": ["get"]
}]
}, {
"path": "/foobardb",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
}, {
"path": "/_all_dbs",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
}, {
"path": "/_utils/js/zeroclipboard",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
},
{
"path": "/_uuids",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
},
{
"path": "/favicon.ico",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
}];


///_uuids

///_all_dbs
// /_utils/js/zeroclipboard/Z
//db_utils
//db/css/
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ module.exports = function (acl) {

let verbs = acl[pathExists].roles[roleExists].verbs;
let verbExists = mapIt(verbs, null, req.method.toLowerCase());

debug('path/role: %s %s', pathExists, roleExists);

if (!~verbExists) {
debug('unauthorized3: %s : %s', identity, req.path);
Expand Down
2 changes: 1 addition & 1 deletion lib/indexOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

var secureCompare = require('secure-compare');

var secure = true;
var secure = false;

function compareIt(source, target, secure) {
if (secure) {
Expand Down
52 changes: 29 additions & 23 deletions lib/pouchdb.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
'use strict';
"use strict";

module.exports = [{
"path": '/_utils/',
module.exports = [{
"path": "/_validate",
"roles": [{
"role": "public",
"verbs": ["get", "put", "post"]
}]
},
{
"path": "/foobarrepl",
"roles": [{
"role": 'public',
"verbs": ['get']
}, {
"role": 'user',
"verbs": ['get']
"role": "public",
"verbs": ["get", "post", "put"]
}]
}, {
"path": '/db/',
},
{
"path": "/foobarrepl/_local",
"roles": [{
"role": 'public',
"verbs": ['get']
"role": "public",
"verbs": ["get", "post", "put"]
}]
},
{
"path": '/_utils/css/',
}, {
"path": "/_session",
"roles": [{
"role": 'public',
"verbs": ['get']
"role": "public",
"verbs": ["get"]
}]
},
{
"path": '/_utils/js/',
}, {
"path": "/_all_dbs",
"roles": [{
"role": 'public',
"verbs": ['get']
"role": "public",
"verbs": ["get", "put", "post"]
}]
}];
}];


///_uuids

///_all_dbs
// /_utils/js/zeroclipboard/Z
//db_utils
//db/css/
65 changes: 65 additions & 0 deletions sample/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/node_modules', express.static( path.join(__dirname, 'node_modules')));
app.use('/app', express.static( path.join(__dirname, 'app')));

app.use('/', routes);


app.use('/replicate', require('./routes/replicate'));
app.use('/validate', require('./routes/validate'));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
44 changes: 44 additions & 0 deletions sample/app/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var myApp = angular.module('myApp', []);

myApp.controller('ValidateController', ['$scope', '$http', function ($scope, $http) {
$scope.greeting = 'Welcome to SALTI!';
$scope.errors = 'no errors';
$scope.messages = 'no messages';
$scope.secret = 'foobar';
$scope.newdoc = genDoc();

$scope.createDoc = function () {

var body = { 'secret': 'CLEAR ' + $scope.secret, 'doc' : $scope.newdoc};

$http({
method: 'POST',
url: '/validate',
data: body
}).then(function successCallback(response) {
$scope.newdoc = genDoc();
if (response.data.secret)
$scope.secret = response.data.secret;
else
$scope.messages = JSON.stringify(response);
}, function errorCallback(response) {
$scope.errors = JSON.stringify(response);
});
}

}]);


function genDoc(){
return JSON.stringify({ _id: guid(), "type": "foobar" })
}

function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
14 changes: 11 additions & 3 deletions sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
"author": "Shawn Cicoria",
"license": "MIT",
"dependencies": {
"debug": "^2.2.0",
"express": "^4.13.4",
"angular": "^1.5.0",
"body-parser": "~1.13.2",
"bootstrap": "^3.3.6",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"ejs": "~2.3.3",
"express": "~4.13.1",
"express-pouchdb": "^1.0.2",
"pouchdb": "^5.2.1"
"jquery": "^2.2.1",
"morgan": "~1.6.1",
"pouchdb": "^5.2.1",
"serve-favicon": "~2.3.0"
}
}
8 changes: 8 additions & 0 deletions sample/public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
9 changes: 9 additions & 0 deletions sample/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'SALTI Test Express Site' });
});

module.exports = router;
Loading

0 comments on commit 12c60c7

Please sign in to comment.