This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sessionid = ''; | |
var sessionrole = ''; | |
var socket = io(); | |
/* selector functions to interact with the HTML and server via socket.io */ | |
$(document).ready(function() { | |
// when user picks a role | |
$("select").on("change", function() { | |
sessionrole = $("select option:selected").text() | |
socket.emit('loggedin', {"role": sessionrole}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = require('./config').config; | |
var appbaseRef = config(); | |
var createTable = function(){ | |
console.log('\n\nLets create some empty table for you\n\n' ) | |
appbaseRef.index({ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var app = express(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
var path = require('path'); | |
var config = require('./config').config; | |
var appbaseRef = config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('form').submit(function(){ | |
var jsonObject = { | |
"role":$("select option:selected").text(), | |
"title":$('#title').val(), | |
"post":$('#post').val() | |
}; | |
socket.emit('on_blog_post', jsonObject); | |
$('#title').val(''); | |
$('#post').val(''); | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sockbase.prototype.onBlogPost = function(io, socket, msg){ | |
var role = msg.role; | |
var self = this; | |
this.acl.isAllowed(role, 'pendingpost', 'write', function(result){ | |
if (result){ | |
console.log(msg); | |
self.appbaseRef.index({ | |
type: 'pendingpost', | |
body: msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acl.addPermission('admin', 'pendingpost', 'read'); | |
acl.addPermission('admin', 'pendingpost', 'write'); | |
acl.addPermission('admin', 'pendingpost', 'delete'); | |
acl.addPermission('user', 'pendingpost', 'write'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var permissions = []; | |
function Acl(){ | |
} | |
Acl.prototype.addPermission = function(role, model, permission){ | |
permissions.push([role, model, permission]); | |
} | |
Acl.prototype.isAllowed = function(role, model, permission, cb){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sockbase.prototype.onBlogPost = function(io, socket, msg){ | |
appbaseRef.index({ | |
type: 'pendingpost', | |
body: msg | |
}).on('data', function(response){ | |
console.log(response); | |
}).on('error', function(error){ | |
console.log(error); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wildcard = require('socketio-wildcard'); | |
var nsp; | |
io.on('connection', function(socket){ | |
console.log('a user connected'); | |
var middleware = wildcard(); | |
nsp = io.of('/sockbase'); | |
io.use(middleware); | |
nsp.use(middleware); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var callbacks = { | |
'subscribe_approved': sockbase.onSubscribeApproved.bind(sockbase), | |
'subscribe_pending' : sockbase.onSubscribePending.bind(sockbase), | |
'on_blog_post': sockbase.onBlogPost.bind(sockbase), | |
'approve_pending': sockbase.onApprovePost.bind(sockbase), | |
'disconnect': sockbase.onDisconnect.bind(sockbase) | |
}; |