Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication for the Angular App #35

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
eee01b6
set express to 3.5.1 as 4.1.1 seems to now offload many settings to t…
Oct 7, 2014
a9dc8dd
added jquery and bootstrap to this seed project
Oct 8, 2014
e2f2894
removed leading '/' on css refs...(just to be consistent with js file…
Oct 8, 2014
abf9b7a
initial creation
Oct 8, 2014
1205a15
added RegistrationCtrl
Oct 9, 2014
211e7d4
enclosed each angular file's code in anonymous function to hide var n…
Oct 14, 2014
31ff92b
have getaAll, getById, getByNodeId working correctly from the angular…
Oct 15, 2014
ac9363c
setting default on page load to getAll registrations
Oct 21, 2014
027fb35
setting default on page load to getAll registrations -- added more gr…
Oct 24, 2014
597b376
added minified versions of bootstrap and angular
Oct 28, 2014
0d732a8
have local route working but data is not being displayed in the div I…
Oct 31, 2014
0327098
have watable displayed but not displaying the content yet
Nov 3, 2014
075730a
loading data into watable...mock data only.
Nov 4, 2014
3ea6f62
loading data into watable...mock data only.
Nov 4, 2014
29c6452
removed ref to watable object in data mock code
Nov 4, 2014
fa2d792
Merge branch 'use-watable-for-list-display' of https://github.com/rsi…
Nov 4, 2014
1714e38
have live data displaying in WATable plugin...looks good
Nov 6, 2014
58b627f
added some more columns to the table
Nov 6, 2014
f852583
cleaned up the code somewhat
Nov 6, 2014
be2500d
updating with watable list view
Nov 6, 2014
d5fa9e0
Merge branch 'develop'
Nov 6, 2014
0c43950
Merge remote-tracking branch 'origin/master'
Nov 6, 2014
9acf5e8
added usage info for Node-Talking-Admin
Nov 6, 2014
f79118b
added usage info for Node-Talking-Admin
Nov 6, 2014
0c9f3c6
added usage info for Node-Talking-Admin
Nov 6, 2014
9105443
added clickRow event...now can obtain json formatted row data and a c…
Nov 7, 2014
a3a49a4
Merge branch 'develop'
Nov 7, 2014
ccdb842
started using realistic partials: nodes-list.jade and node-detail.jad…
Nov 7, 2014
3f714ff
fixed a bug...missing the partials/nodes-list path...had only nodes-list
Nov 7, 2014
259886a
added partials: nodes-list.jade and node-detail.jade
Nov 8, 2014
8824ff9
added partials: nodes-list.jade and node-detail.jade
Nov 8, 2014
ea018ed
Merge branch 'develop'
Nov 8, 2014
0570859
Added git ignore
Nov 20, 2014
75ff8b8
Added bower components to .gitignore
Nov 20, 2014
1df5768
no semis, this will mess up the commit, but it is only once.
Nov 20, 2014
291ede3
working in the examples from online.
Nov 21, 2014
863f81d
redirecting to login, needs work.
Nov 21, 2014
b5d96c1
small cleanups, still needs more
xqjibz Nov 21, 2014
8eccb65
changed type here, no cleartext
xqjibz Dec 9, 2014
7107f76
added in the rest of the required modules
xqjibz Dec 9, 2014
bb06b9d
this is sort of how I see this working, needs breakout of functions, …
xqjibz Dec 9, 2014
17529ce
finished up angular adds, moved some stuff around
xqjibz Dec 9, 2014
19f46b9
nope
xqjibz Dec 9, 2014
117e074
commit to rebase
xqjibz Dec 9, 2014
fb1b17b
Added git ignore
Nov 20, 2014
4778643
Added bower components to .gitignore
Nov 20, 2014
77ba69b
no semis, this will mess up the commit, but it is only once.
Nov 20, 2014
46fe2f0
working in the examples from online.
Nov 21, 2014
d145d35
redirecting to login, needs work.
Nov 21, 2014
e77c3e2
small cleanups, still needs more
xqjibz Nov 21, 2014
8994051
changed type here, no cleartext
xqjibz Dec 9, 2014
95bcce5
added in the rest of the required modules
xqjibz Dec 9, 2014
5027f94
this is sort of how I see this working, needs breakout of functions, …
xqjibz Dec 9, 2014
32ea6fc
finished up angular adds, moved some stuff around
xqjibz Dec 9, 2014
fb3c260
nope
xqjibz Dec 9, 2014
df39b59
commit to rebase
xqjibz Dec 9, 2014
6de70a4
merge master in
xqjibz Dec 9, 2014
ccec15c
commit to fix my mess up with rebasing off the wrong branch, a-doi
xqjibz Dec 9, 2014
90a100d
added todo for API protection
xqjibz Dec 9, 2014
5b1ed0a
more comments
xqjibz Dec 10, 2014
1507143
meh, I'm no css guy. :)
xqjibz Dec 10, 2014
d5d0ff2
mongoskin add-in
xqjibz Dec 12, 2014
eeca090
adding in bcryptjs, likely never required in the BE
xqjibz Dec 12, 2014
03051ac
remove console.log and fixup names here so this actually works.
xqjibz Dec 12, 2014
375cd22
well that's amazing.
xqjibz Dec 12, 2014
fd1054d
fixup names here, they _are_ important
xqjibz Dec 12, 2014
8654449
with db lookup of names, needs ssl
xqjibz Dec 14, 2014
44c22da
finalized working with bcrypt stored passwords, making PR
xqjibz Dec 14, 2014
a981123
worked in ssl certs...though it needs worked out.
xqjibz Dec 14, 2014
b447103
forgot to remove optiosn here, woops
xqjibz Dec 14, 2014
c1cfcdb
cert and key for others, once we get that working.
xqjibz Dec 14, 2014
bd845fa
remove NPM bcrypt, moving to FE
xqjibz Dec 17, 2014
c435411
moved to bcryptjs, maybe the pure JS guys got it right.
xqjibz Dec 17, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#Ignore class files
*.class
*.classpath

#Ignore some generated directories
gen/
out/

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Eclipse related
.metadata/
.project/

#intelliJ related
*.iml
.idea

#property files
common/build.properties

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

#node items
/node_modules
/bower_components
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#How to use Nodes-Talking-Admin
------------------------------------------------
Usage:

clone the repo
cd <install dir>
npm install
make sure the server is running
nodemon app
navigate to localhost:8000

------------------------------------------------

# Angular Express Seed

Start an awesome app with AngularJS on the front, Express + Node on the back. This project is an
Expand Down
137 changes: 119 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,116 @@
var express = require('express'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
errorHandler = require('error-handler'),
//errorHandler = require('error-handler'),
morgan = require('morgan'),
passport = require('passport'),
routes = require('./routes'),
api = require('./routes/api'),
http = require('http'),
path = require('path');

var app = module.exports = express();
https = require('https'),
path = require('path'),
// the requires for passport
LocalStrategy = require('passport-local').Strategy,
flash = require('connect-flash'),
session = require('express-session'),
bcrypt = require('bcryptjs'),
sift = require('sift'),
fs = require('fs'),
mongo = require('mongoskin'),
db = mongo.db("mongodb://localhost/registration", {safe : true})

var options = {
key : fs.readFileSync('./ssl/privatekey'),
cert : fs.readFileSync('./ssl/certificate')
}

// for passport session management
var users = []

// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing.
passport.serializeUser(function(user, done) {
done(null, user.id);
})

passport.deserializeUser(function(id, done) {
var returnedUserObject = sift({'id' : id}, users)
if(returnedUserObject.length === 1){
return done(null, returnedUserObject)
} else {
return done(new Error('user does not exist for id:', id))
}
})


// Use the LocalStrategy within Passport.
// Strategies in passport require a `verify` function, which accept
// credentials (in this case, a username and password), and invoke a callback
// with a user object. In the real world, this would query a database;
// however, in this example we are using a baked-in set of users.
passport.use(new LocalStrategy(
function(username, password, done) {
// asynchronous verification, for effect...
process.nextTick(function () {

// Find the user by username. If there is no user with the given
// username, or the password is not correct, set the user to `false` to
// indicate failure and set a flash message. Otherwise, return the
// authenticated `user`.
db.collection('users').findOne({'userName' : username}, function(err, userObject){
if(err){
return done(err)
}
if(userObject){

if(bcrypt.compareSync(password, userObject.password)){

// for passport sessions
userObject.id = userObject._id
users.push(userObject)
return done(null, userObject)
} else {
return done(null, false, { message: 'Invalid Password'})
}

} else {
return(done(null, false, {message : 'Unknown user ' + username}))
}
})

})
}
))


var app = module.exports = express()

/**
* Configuration
*/

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(morgan('dev'));
app.use(bodyParser());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.set('port', process.env.PORT || 8000)
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(morgan('dev'))
app.use(bodyParser())
app.use(methodOverride())
app.use(express.static(path.join(__dirname, 'public')))
// session and setup for passport
app.use(session({ secret: 'imalittleteapot' }))
app.use(passport.initialize())
app.use(passport.session())
app.use(flash())

var env = process.env.NODE_ENV || 'development';

// development only
if (env === 'development') {
app.use(express.errorHandler());
app.use(express.errorHandler())
}

// production only
Expand All @@ -47,20 +129,39 @@ if (env === 'production') {
*/

// serve index and view partials
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
app.get('/', routes.ensureAuthenticated, routes.index)
app.get('/partials/:name', routes.ensureAuthenticated, routes.partials)
// I don't know where to put this.
app.get('/api/userinfo', routes.ensureAuthenticated, routes.userinfo)


// login stuff
app.get('/login', function(req, res){

res.render('login')
})
app.post('/login', passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) {
// this happens on success
res.redirect('/')
})

// JSON API
app.get('/api/name', api.name);
//TODO: decide if the API should be protected to, and under what circumstances.
app.get('/api/name', api.name)
app.get('/api/watable_data',api.watable_data)


// redirect all others to the index (HTML5 history)
app.get('*', routes.index);
app.get('*', routes.ensureAuthenticated, routes.index)


/**
* Start Server
*/


//TODO: this needs to be worked out, ALL connections should move to secure, including in angular
//https.createServer(options, app).listen(app.get('port'), function () {
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
console.log('Express server listening on port ' + app.get('port'))
})
27 changes: 27 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "NodesTalkingAdmin",
"version": "0.1",
"homepage": "https://github.com/rsiewert/angular-express-seed",
"authors": [
"Contributors of Nodes-Talking"
],
"description": "Administration App for Nodes-Talking Project",
"main": "app.js",
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap": "*",
"jquery": "*",
"angular" : "*",
"bcryptjs" : "*"


}
}
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@
"private": true,
"dependencies": {
"body-parser": "^1.0.2",
"error-handler": "^0.1.4",
"express": "~4.1.1",
"errorhandler": "*",
"express": "~3.5.1",
"connect": "*",
"jade": "~0.31.2",
"method-override": "^1.0.0",
"morgan": "^1.0.0"
"morgan": "^1.0.0",
"bower" : "*",
"nodemon": "*",
"passport": "~0.2.1",
"passport-local" : "1.0.0",
"connect-flash" : "0.1.1",
"express-session" : "1.9.1",
"mongoskin" : "1.4.1",
"bcryptjs" : "2.1.0",
"sift" : "0.1.0"
},
"scripts": {
"start" : "node app.js"
}
}
Loading