Skip to content

Commit

Permalink
fixed files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Jan 11, 2015
1 parent 54c0bbe commit 96c5746
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 213 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require('fs'),
cmsRouter = require('./routes/cms-router.js'),
config = JSON.parse(fs.readFileSync('./config/config.json')),
LIVERELOAD_PORT = 35729,
SERVER_PORT = 9000;
SERVER_PORT = process.env.PORT || 9000;


var startNodeServer = function(){
Expand Down Expand Up @@ -678,7 +678,7 @@ module.exports = function (grunt) {
'usemin'
]);

grunt.registerTask('docs', ['coffee', 'ngdocs', 'connect:docs', 'watch:ngdocs']);
grunt.registerTask('docs', ['coffee', 'ngdocs', 'connect:docs', 'watch:scripts']);
grunt.registerTask('default', ['newer:jshint', 'test', 'build']);

grunt.registerTask('heroku:production', 'build');
Expand Down
15 changes: 8 additions & 7 deletions app/scripts/directives/cms-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
</file>
</example>
*/
angular.module('angularCmsApp').directive("cmsWidget", function() {
angular.module('angularCmsApp').directive('cmsWidget', function() {
'use strict';
return {
restrict: "E",
restrict: 'ECA',
replace: true,
transclude: true,
scope: {
Expand All @@ -29,22 +30,22 @@ angular.module('angularCmsApp').directive("cmsWidget", function() {
icon: "@"
},
require: '?^cmsWidgets',
template: ' <div class="col-md-{{size}} widget">\n <div id="widget-{{$id}}" class="panel panel-default {{selected ? \'selected\' : \'\'}}">\n <header class="panel-heading clearfix">\n <i class="fa fa-chevron-right toggle" ng-show="icon"></i>\n {{title}}\n </header>\n <section class="panel-body" ng-transclude></section>\n </div>\n</div>',
template: ' <div class="col-md-{{size}} widget"><div id="widget-{{$id}}" class="panel panel-default {{selected ? \'selected\' : \'\'}}">\n <header class="panel-heading clearfix">\n <i class="fa fa-chevron-right toggle" ng-show="icon"></i>\n {{title}}\n </header>\n <section class="panel-body" ng-transclude></section>\n </div>\n</div>',
link: function(scope, element, attrs, ctrl) {
var opened, toggle, widgetTitle;
toggle = function() {
var opened;
opened = !opened;
return element.find("section").slideToggle(function() {
return element.toggleClass((opened ? "closed" : "opened"));
element.find('section').slideToggle(function() {
element.toggleClass((opened ? 'closed' : 'opened'));
});
};
widgetTitle = element.find("header");
widgetTitle = element.find('header');
widgetTitle.css({
cursor: 'move'
});
opened = true;
return widgetTitle.bind("click", toggle);
widgetTitle.bind('click', toggle);
}
};
});
15 changes: 7 additions & 8 deletions app/scripts/directives/cms-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
This is the container for widgets.
@example
<example module="angularCmsApp" >
<example module="angularCmsApp" >
<file name="jdx.html" >
HTML example come here ==> `<div class="lior" ></div >`
</file >
</example >
*/
'use strict';

angular.module('angularCmsApp').directive('cmsWidgets', function() {
var postLink;
'use strict';
return {
restrict: 'EMA',
replace: true,
Expand All @@ -35,13 +35,12 @@ angular.module('angularCmsApp').directive('cmsWidgets', function() {
}
return widgets.push(widget);
};
return $scope.select = function(widget) {
$scope.select = function(widget) {
angular.forEach(widgets, function(widget) {
return widget.selected = false;
widget.selected = false;
});
return widget.selected = true;
widget.selected = true;
};
},
link: postLink = function(scope, element, attrs) {}
}
};
});
15 changes: 7 additions & 8 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"baseurl":"http://js2coffee.org",
"baseurl":"http://localhost:8181",
"sitetitle":"angular-cms",
"sitedesc":"This is the description",
"sitebrand":"/images/angular-cms-brand.png",
Expand All @@ -17,14 +17,13 @@
"key": "./config/apache.key",
"cert":"./config/apache.crt"
},

"db":{
"name":"angular-cms",
"username":"amadmin",
"password":"fred",
"host":"localhost",
"port":27017,
"url":"localhost/angular-cms"
"username":"angularcms-dev",
"password":"angularcms-dev",
"host":"paulo.mongohq.com:10089",
"port":31711,
"url":"angularcms-dev:[email protected]:10089/app19632340"
},
"email":{
"username":"[email protected]",
Expand All @@ -34,7 +33,7 @@
"hostname":"localhost",
"port":5001
},
"staticDir":"www",
"staticDir":"dist",
"publicDir":"www",
"uploadsTmpDir":".tmp",
"uploadsDestDir":"www/cms-content/uploads",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"emailjs": "~0.3.6",
"express": "~4.0.0",
"express-session": "^1.9.3",
"finalhandler": "^0.3.3",
"fs-extra": "^0.12.0",
"http-proxy": "^1.3.0",
"jps-ds": "~0.0.2",
Expand All @@ -59,6 +60,7 @@
"promised-io": "~0.3.4",
"q": "^1.1.2",
"request": "~2.34.0",
"serve-static": "^1.8.0",
"socket.io": "~0.9.16",
"websocket": "^1.0.14"
},
Expand Down Expand Up @@ -133,6 +135,6 @@
},
"scripts": {
"test": "grunt test",
"start": "node web.js"
"start": "node server.js"
}
}
74 changes: 44 additions & 30 deletions routes/cms-auth.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
var bodyParser = require('body-parser'),
mongoose = require('mongoose'),
util = require('util'),
User = require('./models/user'),
session = require('express-session'),
crypto = require('crypto'),
bcrypt = require('bcrypt-nodejs');
var bodyParser = require('body-parser'), mongoose = require('mongoose'), util = require('util'), User = require('./models/user'), session = require('express-session'),
crypto = require('crypto'),
bcrypt = require('bcrypt-nodejs');


var cmsAuth = function (config, app) {
var cmsAuth = function(config, app) {
console.warn('cms-auth');


//### hashPassword
//Hash password using basic sha1 hash.
var hashPassword = function (pass, salt) {
var hashPassword = function(pass, salt) {
return bcrypt.hashSync(pass);
};

Expand All @@ -25,7 +19,7 @@ var cmsAuth = function (config, app) {
* @param res
* @param next
*/
login: function (req, res, next) {
login : function(req, res, next) {
var query = {};
if (req.body.username) {
query.username = req.body.username;
Expand All @@ -35,7 +29,9 @@ var cmsAuth = function (config, app) {
}
query.password = hashPassword(req.body.password, query.username);
console.warn('trying to login', query);
User.findOne({username: query.username}, function (err, data) {
User.findOne({
username : query.username
}, function(err, data) {
if (err) {
return res.jsonp(400, err);
}
Expand All @@ -44,10 +40,14 @@ var cmsAuth = function (config, app) {
req.session.user = data;
return res.json(200, data);
} else {
return res.json(404, {message: 'Wrong username/password!'});
return res.json(404, {
message : 'Wrong username/password!'
});
}
} catch (error) {
return res.json(404, {message: error});
return res.json(404, {
message : error
});
}
});
},
Expand All @@ -57,7 +57,7 @@ var cmsAuth = function (config, app) {
* @param res
* @param next
*/
register: function (req, res, next) {
register : function(req, res, next) {
var data = req.body;

//TODO: Need to make this externalized.
Expand All @@ -76,21 +76,30 @@ var cmsAuth = function (config, app) {

console.warn('trying to register', data);


//Try and find user
User.find({username: data.username}, function (err, u) {
console.log('found user', err, util.inspect(u, {colors: true}));
User.find({
username : data.username
}, function(err, u) {
console.log('found user', err, util.inspect(u, {
colors : true
}));
var user = new User(data);
if (err) {
res.jsonp(400, {message: 'Problem registering!'});
res.jsonp(400, {
message : 'Problem registering!'
});
}

if (u.length) {
res.jsonp(400, {message: 'Username already exists!'});
res.jsonp(400, {
message : 'Username already exists!'
});
} else {
user.save(function (er, ok) {
user.save(function(er, ok) {
if (er) {
return res.jsonp(400, {message: 'Problem registering!'});
return res.jsonp(400, {
message : 'Problem registering!'
});
} else {
return res.jsonp(201, ok);
}
Expand All @@ -99,21 +108,26 @@ var cmsAuth = function (config, app) {

});
},
session: function (req, res, next) {
session : function(req, res, next) {
var user = req.session;
if (req.session && req.session.user) {
user = req.session.user
user = req.session.user;
}
console.warn(util.inspect(user, {colors: true}));
return res.send({message: 'Your session', data: user});
console.warn(util.inspect(user, {
colors : true
}));
return res.send({
message : 'Your session',
data : user
});
}
};

//Always users table
app.use(session({
secret: 'angular-cms',
resave: true,
saveUninitialized: true
secret : 'angular-cms',
resave : true,
saveUninitialized : true
}));
app.get(config.apiBase + '/login', bodyParser.json(), cmsAuth.login);
app.post(config.apiBase + '/login', bodyParser.json(), cmsAuth.login);
Expand Down
Loading

0 comments on commit 96c5746

Please sign in to comment.