Skip to content

Commit

Permalink
fixed login
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniespratley committed Jul 16, 2015
1 parent 5d171a7 commit bc1136d
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 119 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var proxyConfig = {
};


//var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function(connect, dir) {
return connect.static(require('path').resolve(dir));
};
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = function(grunt) {
open: true,
base: ['.tmp', '<%= yeoman.app %>'],
middleware: function(connect, options) {
startNodeServer(options, connect);
//startNodeServer(options, connect);
return [
require('json-proxy').initialize(proxyConfig),
mountFolder(connect, '.grunt'),
Expand Down
16 changes: 8 additions & 8 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<link rel="icon" type="image/png" href="images/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32">



<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-TileImage" content="images/mstile-144x144.png">
<meta name="msapplication-square70x70logo" content="images/mstile-70x70.png">
Expand All @@ -53,7 +53,7 @@
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
<link rel="stylesheet" ng-href="{{App.settings.cdn}}/bootswatch.com/{{App.theme | lowercase}}/bootstrap.min.css"/>
<link rel="stylesheet" ng-href="cms-content/themes/bootswatch.com/{{App.theme | lowercase}}/bootstrap.min.css"/>

<!--[if lt IE 9]>
<script src="bower_components/es5-shim/es5-shim.js"></script>
Expand All @@ -80,7 +80,7 @@

</div>


<!--
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand All @@ -89,8 +89,8 @@
ga('create', 'UA-52162355-1', 'angular-cms.herokuapp.com');
ga('send', 'pageview');
</script>
-->


<!-- build:js({.tmp,app}) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/jquery.js"></script>
Expand All @@ -102,7 +102,7 @@
<script src="libs/md5.js"></script>
<script src="libs/markdown.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/modules.js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-utils/ui-utils.js"></script>
Expand All @@ -115,7 +115,7 @@
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-form-gen/dist/angular-form-gen.js"></script>
<!-- endbuild -->

<!-- endbower -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
Expand Down
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"port": 5001
},
"staticDir": "./app",
"publicDir": "./www",
"publicDir": "./app",
"uploadsTmpDir": "./.tmp",
"uploadsDestDir": "./www/cms-content/uploads",
"uploadsUrl": "/cms-content/",
Expand Down
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
{
"name": "angular-cms",
"productName": "angular-cms-app",
"version": "0.0.2",
"description": "This is a lightweight CMS built with Angular.js, Twitter Bootstrap and Node.js.",
"author": "Jonnie Spratley",
"license": "MIT",
"readmeFilename": "README.md",
"main": "index.js",
"homepage": "https://github.com/jonniespratley/angular-cms",
"main": "Gruntfile.js",
"bugs": {
"url": "https://github.com/jonniespratley/angular-cms/issues"
},
"engines": {
"node": "0.10.x",
"npm": "1.3.x"
},
"scripts": {
"test": "grunt test",
"start": "electron .",
"build": "electron-packager . $npm_package_productName --prune --asar --all --version=0.29.1"
},
"directories": {
"doc": "docs",
"test": "test"
Expand Down Expand Up @@ -64,11 +74,12 @@
"request": "~2.34.0",
"serve-static": "^1.8.0",
"socket.io": "~0.9.16",
"websocket": "^1.0.14"
"websocket": "^1.0.14",
"electron-debug": "^0.1.1"
},
"devDependencies": {
"chai": "^1.10.0",
"connect-proxy": "~1.0.2",

"del": "^1.1.0",
"grunt": "~0.4.4",
"grunt-angular-templates": "~0.5.1",
Expand Down Expand Up @@ -127,18 +138,12 @@
"mocha": "^2.0.1",
"protractor": "^1.5.0",
"supertest": "^0.15.0",
"time-grunt": "~0.2.1"
"time-grunt": "~0.2.1",
"electron-packager": "^5.0.0",
"electron-prebuilt": "^0.29.1"
},
"peerDependencies": {
"grunt": "0.4.x",
"karma": "~0.12.0"
},
"engines": {
"node": "0.10.x",
"npm": "1.3.x"
},
"scripts": {
"start": "node server.js",
"test": "grunt test"
}
}
48 changes: 42 additions & 6 deletions routes/cms-auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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');
Expand All @@ -15,6 +14,8 @@ var cmsAuth = function(config, app) {
return bcrypt.hashSync(pass);
};

var UserModel = require('./models/user');
var User = new UserModel(config, app);
var cmsAuth = {
/**
* //### login
Expand All @@ -33,11 +34,25 @@ var cmsAuth = function(config, app) {
}
query.password = hashPassword(req.body.password, query.username);
console.warn('trying to login', query);

query._id = 'user-'+ query.username;

app.locals.db.get(query._id).then(function(resp){
console.log('found user', resp);
res.status(200).json(resp);
}).catch(function(err){
console.log('No user so creating');
res.status(404).json(err);
});


/*
User.findOne({
username: query.username
}, function(err, data) {
if (err) {
return res.jsonp(400, err);
return res.json(400, err);
}
try {
if (data && bcrypt.compareSync(req.body.password, data.password)) {
Expand All @@ -54,6 +69,7 @@ var cmsAuth = function(config, app) {
});
}
});
*/
},
/**
* Handle registering a new user
Expand All @@ -71,7 +87,7 @@ var cmsAuth = function(config, app) {
if (req.body.email) {
data.email = req.body.email;
}

data._id = 'user-'+ data.username;
data.password = hashPassword(req.body.password, data.username);
data.created_at = new Date();
data.updated_at = new Date();
Expand All @@ -80,6 +96,22 @@ var cmsAuth = function(config, app) {

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

app.locals.db.get(data._id).then(function(resp){
console.log('found user', resp);
res.status(404).json({
message: 'User already exists'
});
}).catch(function(err){
console.log('No user so creating');
app.locals.db.put(data).then(function(resp){
res.status(201).json(resp);
});
})




/*
//Try and find user
User.find({
username: data.username
Expand All @@ -89,7 +121,7 @@ var cmsAuth = function(config, app) {
}));
var user = new User(data);
if (err) {
res.jsonp(400, {
res.json(400, {
message: 'Problem registering!'
});
}
Expand All @@ -101,7 +133,7 @@ var cmsAuth = function(config, app) {
} else {
user.save(function(er, ok) {
if (er) {
return res.jsonp(400, {
return res.json(400, {
message: 'Problem registering!'
});
} else {
Expand All @@ -111,7 +143,11 @@ var cmsAuth = function(config, app) {
}
});
*/
},



session: function(req, res, next) {
var user = req.session;
if (req.session && req.session.user) {
Expand Down
1 change: 0 additions & 1 deletion routes/cms-db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var mongoose = require('mongoose');

module.exports = function(config) {
console.warn('cms-db initialized');
Expand Down
2 changes: 1 addition & 1 deletion routes/cms-rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function(config, app) {
var router = express.Router();

router.use(function(req, res, next) {
console.log('cms-rest Time:', Date.now());
console.log('cms-rest Time:', Date.now(), req.params, req.method, req.body);
next();
});

Expand Down
43 changes: 41 additions & 2 deletions routes/cms-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,52 @@ module.exports = function(config, app) {
// TODO: Using pouchdb
var PouchDB = require('pouchdb');
PouchDB.debug('*');

var db = new PouchDB(config.db.local);
var db2 = new PouchDB(config.db.remote);
PouchDB.sync(db, db2);
app.locals.db = db;

console.log('Connected to', config.db.local);

// TODO:

/*
router.route('/users/:user_id')
.all(function(req, res, next) {
// runs for all HTTP verbs first
// think of it as route specific middleware!
next();
})
.get(function(req, res, next) {
res.json(req.user);
})
.put(function(req, res, next) {
// just an example of maybe updating the user
req.user.name = req.params.name;
// save user ... etc
res.json(req.user);
})
.post(function(req, res, next) {
next(new Error('not implemented'));
})
.delete(function(req, res, next) {
next(new Error('not implemented'));
})
var replication = PouchDB.replicate('mydb', 'http://localhost:5984/mydb', {live: true})
.on('change', function (info) {
// handle change
}).on('complete', function (info) {
// handle complete
}).on('uptodate', function (info) {
// handle up-to-date
}).on('error', function (err) {
// handle error
});
replication.cancel(); // whenever you want to cancel
*/

var serverPort = process.env.PORT || config.port;
var serverHost = process.env.IP || config.host;
Expand All @@ -32,7 +71,7 @@ module.exports = function(config, app) {
require('./cms-db')(config);
require('./cms-auth')(config, app);
// require('./cms-passport')(config, app);
require('./cms-upload')(config, app);
//require('./cms-upload')(config, app);
require('./cms-server')(config, app);
require('./cms-rest')(config, app);
//require('./cms-proxy')(config, app);
Expand Down
14 changes: 1 addition & 13 deletions routes/models/upload.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
var mongoose = require( 'mongoose' );


module.exports = mongoose.model( 'Upload', mongoose.Schema( {
name: String,
filename: String,
size: Number,
url: String,
type: String,
path: String,
meta: Object,
created: Date,
updated: Date
} ) );
module.exports = function(){};
Loading

0 comments on commit bc1136d

Please sign in to comment.