Skip to content

Commit 51d4244

Browse files
committed
application source files
1 parent f240acb commit 51d4244

Some content is hidden

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

69 files changed

+20119
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

GruntFile.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module.exports = function(grunt) {
2+
3+
grunt.initConfig({
4+
jshint: {
5+
files: ["*.js", "lib/*.js", "test/*.js"],
6+
options: {
7+
esnext: true,
8+
globals: {
9+
jQuery: true
10+
}
11+
}
12+
},
13+
less: {
14+
production: {
15+
files: {
16+
"public/css/style.css": ["public/lib/css/less/*.less","public/lib/css/*.css"],
17+
}
18+
}
19+
},
20+
autoprefixer: {
21+
files: {
22+
'public/css/style.css': 'public/css/style.css',
23+
}
24+
},
25+
browserify: {
26+
client: {
27+
src: ["public/lib/js/printTerms.js"],
28+
dest: "public/js/bundle.js"
29+
}
30+
},
31+
watch: {
32+
css: {
33+
files: ["public/lib/css/*.css","public/lib/css/less/*.less"],
34+
tasks: ["css"]
35+
},
36+
scripts: {
37+
files: ["public/lib/js/printTerms.js"],
38+
tasks: ["jshint", "browserify"]
39+
}
40+
}
41+
42+
});
43+
44+
//Load Tasks
45+
grunt.loadNpmTasks("grunt-contrib-jshint");
46+
grunt.loadNpmTasks("grunt-contrib-less");
47+
grunt.loadNpmTasks("grunt-autoprefixer");
48+
grunt.loadNpmTasks("grunt-browserify");
49+
grunt.loadNpmTasks("grunt-contrib-watch");
50+
51+
//Register Tasks
52+
grunt.registerTask("js", ["browserify"]);
53+
grunt.registerTask("css", ["less","autoprefixer"]);
54+
grunt.registerTask("default", ["jshint","css","js"]);
55+
56+
};

app.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// set up ======================================================================
2+
var express = require('express');
3+
var app = express(); // create our app w/ express
4+
var mongoose = require('mongoose'); // mongoose for mongodb
5+
var port = process.env.PORT || 5000; // set the port
6+
var database = require('./config/database'); // load the database config
7+
var morgan = require('morgan'); // log every request to the console
8+
var bodyParser = require('body-parser');
9+
var methodOverride = require('method-override');
10+
11+
// configuration ===============================================================
12+
// Connect to local MongoDB instance. A remoteUrl is also available (modulus.io)
13+
var promise = mongoose.connect(database.localUrl, {
14+
useMongoClient: true,
15+
/* other options */
16+
});
17+
// Or `createConnection`
18+
//var promise = mongoose.createConnection('mongodb://localhost/myapp', {
19+
// useMongoClient: true,
20+
/* other options */
21+
//});
22+
promise.then(function(db) {
23+
/* Use `db`, for instance `db.model()`
24+
});
25+
// Or, if you already have a connection
26+
connection.openUri('mongodb://localhost/myapp', { /* options */
27+
});
28+
29+
app.use(express.static('./public')); // set the static files location /public/img will be /img for users
30+
app.use(morgan('dev')); // log every request to the console
31+
app.use(bodyParser.urlencoded({'extended': 'true'})); // parse application/x-www-form-urlencoded
32+
app.use(bodyParser.json()); // parse application/json
33+
app.use(bodyParser.json({type: 'application/vnd.api+json'})); // parse application/vnd.api+json as json
34+
app.use(methodOverride('X-HTTP-Method-Override')); // override with the X-HTTP-Method-Override header in the request
35+
36+
37+
// routes ======================================================================
38+
require('./config/routes.js')(app);
39+
40+
// listen (start app with node server.js) ======================================
41+
app.listen(port);
42+
console.log("App listening on port " + port);

app/models/artist.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var mongoose = require('mongoose');
2+
3+
var Schema = mongoose.Schema;
4+
var ObjectId = Schema.ObjectID;
5+
6+
var Artist = new Schema({
7+
name : { type: String, required: true},
8+
email : { type: String, required: true},
9+
password : { type: String, required: true},
10+
accesskey : { type: String, default: ''},
11+
shortname : { type: String, default: '', trim: true},
12+
reknown : { type: String, default: '', trim: true},
13+
bio : { type: String, default: '', trim: true}
14+
});
15+
16+
module.exports = mongoose.model('Artist', Artist);
17+
18+
19+
20+
/*
21+
function validateThis(v){
22+
return v == 'mike';
23+
}
24+
first_name : { type: String, required: true, trim: true, validate: [validateThis, 'your name isnt mike'] }
25+
*/

app/models/author.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var mongoose = require('mongoose');
2+
3+
module.exports = mongoose.model('Author', {
4+
name: {
5+
type: String,
6+
default: ''
7+
},
8+
email: {
9+
type: String,
10+
default: ''
11+
},
12+
password: {
13+
type: String,
14+
default: ''
15+
},
16+
shortname: {
17+
type: String,
18+
default: ''
19+
},
20+
reknown: {
21+
type: String,
22+
default: ''
23+
},
24+
bio: {
25+
type: String,
26+
default: ''
27+
}
28+
});

config/database.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
//remoteUrl : 'mongodb://node:nodeuser@mongo.onmodulus.net:27017/uwO3mypu',
3+
localUrl: 'mongodb://localhost/sampleproject'
4+
};

config/routes.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var Author = require('../app/models/author');
2+
var Artist = require('../app/models/artist');
3+
var crypto = require('crypto');
4+
5+
6+
module.exports = function (app) {
7+
app.get('/api/artists', function (req, res) {
8+
// use mongoose to get all todos in the database
9+
Author.find(function (err, authors) {
10+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
11+
if (err) {
12+
res.send(err);
13+
}
14+
res.json(authors); // return all todos in JSON format
15+
}).limit(1000);
16+
});
17+
18+
19+
//register artist data
20+
app.post('/api/signup', function (req, res) {
21+
// use mongoose to get all todos in the database
22+
var postData = req.body;
23+
var encryptedPassword = crypto.createHash('md5').update(postData.password).digest("hex");
24+
var data = {name:postData.name, email:postData.email, password:encryptedPassword};
25+
var artistdata = new Artist(data);
26+
artistdata.save(function (err, artists) {
27+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
28+
if (err) {
29+
res.send(err);
30+
}
31+
res.json({success:true}); // return all todos in JSON format
32+
});
33+
});
34+
35+
36+
//login artist data
37+
app.post('/api/login', function (req, res) {
38+
// use mongoose to get all todos in the database
39+
var sessionId = null;
40+
var userInfo = null;
41+
var postData = req.body;
42+
var encryptedPassword = crypto.createHash('md5').update(postData.password).digest("hex");
43+
Artist.find({email:postData.username,password:encryptedPassword}, function (err, artists) {
44+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
45+
if (err) {
46+
res.send(err);
47+
}else{
48+
sessionId = crypto.randomBytes(16).toString("hex");
49+
Artist.update({email:postData.username}, {accesskey:sessionId}, { multi: false }, function (err) {
50+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
51+
if (err) {
52+
res.send(err);
53+
}
54+
res.json({sessionId: sessionId}); // return session id
55+
});
56+
}
57+
58+
});
59+
});
60+
61+
//login artist data
62+
app.post('/api/validate', function (req, res) {
63+
// use mongoose to get all todos in the database
64+
var authorized = 'unauthorized';
65+
var postData = req.body;
66+
Artist.find({accesskey:postData.sessionId}, function (err, artists) {
67+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
68+
if (err) {
69+
res.send(err);
70+
}
71+
if(artists){ // if user is authorised
72+
var authorized = 'authorized';
73+
}
74+
res.send(authorized);
75+
});
76+
});
77+
78+
79+
//login artist data
80+
app.post('/api/logout', function (req, res) {
81+
// use mongoose to get all todos in the database
82+
var postData = req.body;
83+
Artist.update({accesskey:postData.sessionId}, {accesskey:"logout"}, { multi: false }, function (err) {
84+
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
85+
if (err) {
86+
res.send(err);
87+
}
88+
res.send("Logout Successfully.");
89+
});
90+
91+
});
92+
93+
94+
95+
// application -------------------------------------------------------------
96+
app.get('*', function (req, res) {
97+
// res.sendFile(__dirname + '/../public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
98+
var path = require('path');
99+
res.sendFile(path.resolve('public/index.html'));
100+
});
101+
102+
};

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "artists-project",
3+
"version": "0.0.1",
4+
"description": "Simple authors application.",
5+
"main": "app.js",
6+
"author": "Avesh Srivastava",
7+
"license": "MIT",
8+
"scripts": {
9+
"prestart": "grunt",
10+
"start": "node app.js",
11+
"predev": "grunt",
12+
"dev": "open http://localhost:8080 & node app & grunt watch",
13+
"predebug": "grunt",
14+
"debug": "open http://localhost:3000 & open http://localhost:8080/debug?port=5858",
15+
"postdebug": "node-inspector & node --debug app"
16+
},
17+
"dependencies": {
18+
"body-parser": "^1.4.3",
19+
"express": "^4.13.4",
20+
"method-override": "^2.1.3",
21+
"mongoose": "^4.4.12",
22+
"morgan": "^1.1.1",
23+
"@uirouter/angularjs": "latest",
24+
"@uirouter/visualizer": "latest"
25+
},
26+
"devDependencies": {
27+
"angular-ui-router": "^1.0.3",
28+
"crypto": "0.0.3",
29+
"grunt": "^1.0.1",
30+
"grunt-autoprefixer": "^3.0.4",
31+
"grunt-browserify": "^5.0.0",
32+
"grunt-contrib-jshint": "^1.1.0",
33+
"grunt-contrib-less": "^1.4.1",
34+
"grunt-contrib-watch": "^1.0.0",
35+
"node-inspector": "^1.1.1"
36+
}
37+
}

public/css/bootstrap.min.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/font-awesome.min.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)