Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 3758bb3

Browse files
author
Matt Karl
committed
Initial commit
1 parent b9a8b62 commit 3758bb3

File tree

127 files changed

+7234
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+7234
-2
lines changed

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "components"
3+
}

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.bowerrc export-ignore
4+
db export-ignore
5+
tasks export-ignore
6+
src export-ignore
7+
bower.json export-ignore
8+
Gruntfile.js export-ignore
9+
project.json export-ignore

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
components
2+
node_modules
3+
*.map
4+
.env

Gruntfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function(grunt)
2+
{
3+
// Load modules
4+
require('project-grunt')(grunt,
5+
{
6+
jsFolder: 'app/public/js',
7+
cssFolder: 'app/public/css'
8+
});
9+
};

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
# SpringRollConnect
2-
Deployment management app for SpringRoll apps and games.
1+
# SpringRoll Connect
2+
3+
SpringRoll Connect is a content management system built using [NodeJS](https://nodejs.org/), [Express](http://expressjs.com/) and [MongoDB](https://www.mongodb.org/). This app allows the easy deployment of SpringRoll apps and games.
4+
5+
## Requirements
6+
7+
* [NodeJS](https://nodejs.org/)
8+
* [MongoDB](https://www.mongodb.org/)
9+
10+
## Installation
11+
12+
* Download the latest version of SpringRoll Connect
13+
* Make sure MongoDB is running
14+
* Run the server `node server.js` (suggest using [nodemon](http://nodemon.io/), [forever](https://www.npmjs.org/package/forever) or [Amazon OpsWorks](http://aws.amazon.com/opsworks/))
15+
* Navigate to your server in a browser and follow the instructions
16+
17+
## License
18+
19+
Copyright (c) 2015 [CloudKid](https://github.com/cloudkidstudio)
20+
21+
Released under the MIT License.

app/config/environment.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
development:
3+
{
4+
spaces: 4,
5+
errorHandlerOptions: {
6+
dumpExceptions: true,
7+
showStack: true
8+
}
9+
},
10+
production:
11+
{
12+
spaces: 0,
13+
errorHandlerOptions: {
14+
dumpExceptions: false,
15+
showStack: false
16+
}
17+
}
18+
};

app/helpers/access.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var _ = require('lodash');
2+
var privilege = {
3+
subscriber: 0,
4+
editor: 1,
5+
admin: 2
6+
};
7+
8+
module.exports = {
9+
10+
// The privilege map
11+
privilege: privilege,
12+
13+
// If the user is logged in
14+
isAuthenticated : function(req, res, next)
15+
{
16+
if (req.isAuthenticated())
17+
return next();
18+
req.flash('redirect', req.originalUrl);
19+
res.redirect('/login');
20+
},
21+
22+
// Access function if user is not logged in
23+
isAnonymous: function(req, res, next)
24+
{
25+
if (!req.isAuthenticated())
26+
return next();
27+
res.redirect('/');
28+
},
29+
// Editor privilege can:
30+
// - create a new project
31+
// - delete a project
32+
// - manage groups for which you're a member
33+
isEditor: function(req, res, next)
34+
{
35+
if (req.isAuthenticated())
36+
{
37+
if (req.user.privilege >= privilege.editor)
38+
return next();
39+
res.redirect('/');
40+
}
41+
req.flash('redirect', req.originalUrl);
42+
res.redirect('/login');
43+
},
44+
// Admin can:
45+
// - create a new group
46+
// - manage existing groups
47+
// - change group permissions
48+
isAdmin: function(req, res, next)
49+
{
50+
if (req.isAuthenticated())
51+
{
52+
if (req.user.privilege >= privilege.admin)
53+
return next();
54+
return res.redirect('/');
55+
}
56+
req.flash('redirect', req.originalUrl);
57+
res.redirect('/login');
58+
}
59+
};

app/helpers/auth.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var Group = require('../models/group');
2+
var User = require('../models/user');
3+
var LocalStrategy = require('passport-local');
4+
var crypto = require('crypto');
5+
var async = require('async');
6+
7+
module.exports = function(passport)
8+
{
9+
// Passport also needs to serialize and deserialize
10+
// user instance from a session store in order to
11+
// support login sessions, so that every subsequent
12+
// request will not contain the user credentials.
13+
// It provides two method:
14+
passport.serializeUser(function(user, done){
15+
done(null, user._id);
16+
});
17+
18+
passport.deserializeUser(function(id, done){
19+
User.getById(id, function(err, user){
20+
done(err, user);
21+
});
22+
});
23+
24+
passport.use('login', new LocalStrategy({
25+
passReqToCallback : true
26+
},
27+
function(req, username, password, done)
28+
{
29+
// check in mongo if a user with username exists or not
30+
User.getByUsername(username, function(err, user)
31+
{
32+
// In case of any error, return using the done method
33+
if (err) return done(err);
34+
35+
if (!user)
36+
{
37+
err = 'User Not Found';
38+
}
39+
else if (!user.active)
40+
{
41+
err = 'Deactivated Account';
42+
}
43+
else if (!user.comparePassword(password))
44+
{
45+
err = 'Invalid Password';
46+
}
47+
48+
// Check for error
49+
if (err)
50+
{
51+
return done(null, false, req.flash('error', err));
52+
}
53+
54+
// User and password both match, return user from
55+
// done method which will be treated like success
56+
return done(null, user);
57+
});
58+
})
59+
);
60+
61+
// Handle the signup process
62+
passport.use('register', new LocalStrategy({
63+
passReqToCallback : true
64+
},
65+
function(req, username, password, done)
66+
{
67+
// Delay the execution of addUser and execute
68+
// the method in the next tick of the event loop
69+
process.nextTick(function()
70+
{
71+
User.addUser(
72+
{
73+
username: username,
74+
password: password,
75+
email: req.body.email,
76+
name: req.body.name,
77+
confirm: req.body.confirm,
78+
privilege: req.body.privilege
79+
},
80+
function(err, user)
81+
{
82+
if (err)
83+
{
84+
console.error(err);
85+
return done(null, false, req.flash('error', err));
86+
}
87+
done(null, user);
88+
}
89+
);
90+
});
91+
})
92+
);
93+
};

app/helpers/concat-url.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Generate the MySQL select parameter for creating
3+
* a release URL, which is a combination of
4+
* the game location, commit id and if we should
5+
* be a release, debug or archive
6+
* @method concat-url
7+
* @param {request} req The express request object
8+
*/
9+
module.exports = function(req)
10+
{
11+
var game = require('../models/game.js'),
12+
release = require('../models/release.js');
13+
14+
var path = '';
15+
if (req.query.debug)
16+
path += 'debug/index.html';
17+
else
18+
path += 'release/index.html';
19+
20+
if (req.query.archive)
21+
path += '.zip';
22+
23+
var table = release.commitId.table.getName();
24+
var name = release.commitId.name;
25+
26+
return 'CONCAT(' +
27+
game.location.toNode() + ", " +
28+
"`" + table + "`.`" + name + "`, '/" +
29+
path + "') as `url`";
30+
};

app/helpers/database.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var mongoose = require('mongoose'),
2+
mongooseTypes = require('mongoose-types'),
3+
expressMongoose = require('express-mongoose'),
4+
passport = require('passport'),
5+
routes = require('../routes'),
6+
flash = require('connect-flash'),
7+
session = require('express-session'),
8+
log = require('./logger');
9+
10+
// Database connection bootstrap
11+
module.exports = function(app)
12+
{
13+
log.info('Springroll API is now operational');
14+
15+
// Attempt to connect to database
16+
mongoose.connect(process.env.MONGO_DATABASE, function()
17+
{
18+
// Include models once
19+
require('../models/release');
20+
require('../models/game');
21+
require('../models/group');
22+
require('../models/user');
23+
});
24+
25+
// Load the types for URL and Email
26+
mongooseTypes.loadTypes(mongoose);
27+
28+
// Listen for errors
29+
var db = mongoose.connection;
30+
db.on('error', function(err)
31+
{
32+
console.error(String("Connection error : " + err).red);
33+
});
34+
35+
// Authentication stuff
36+
app.use(session(
37+
{
38+
secret: process.env.SECRET_KEY,
39+
saveUninitialized: true,
40+
resave: true
41+
}));
42+
app.use(flash());
43+
app.use(passport.initialize());
44+
app.use(passport.session());
45+
require('./auth')(passport);
46+
47+
// Load all the routes
48+
routes(app);
49+
};

0 commit comments

Comments
 (0)