Skip to content

Updated to Express 4 (most other packages updated as well) #4

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ module.exports = function (grunt) {
html: ['<%= yeoman.views %>/*.html']
}
},
ngmin: {
ngAnnotate: {
dist: {
files: [{
expand: true,
Expand Down Expand Up @@ -383,7 +383,7 @@ module.exports = function (grunt) {
'concurrent:dist',
'autoprefixer',
'concat',
'ngmin',
'ngAnnotate',
'copy:dist',
'cdnify',
'cssmin',
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Try out the app: <http://angular-passport.herokuapp.com> (Heroku app may have go

## How to use angular-passport

Before you continue, make sure you have MongoDB installed <http://www.mongodb.org/downloads/>.
Before you continue, make sure you have the following installed;

* MongoDB <http://www.mongodb.org/downloads/>
* Ruby <https://www.ruby-lang.org/en/downloads/>
* compass (gem install compass) <http://compass-style.org/install/>
* grunt-cli (npm install -g grunt-cli) <http://gruntjs.com/getting-started>

### Setup
Run `npm install`, followed by `bower install` to grab the dependencies.
Expand Down
21 changes: 16 additions & 5 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('angularPassportApp', [
'http-auth-interceptor',
'ui.bootstrap'
])
.config(function ($routeProvider, $locationProvider) {
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'partials/main.html',
Expand Down Expand Up @@ -42,15 +42,26 @@ angular.module('angularPassportApp', [
redirectTo: '/'
});
$locationProvider.html5Mode(true);
})
}])

.run(function ($rootScope, $location, Auth) {
.run(['$rootScope', '$location', 'Auth', function ($rootScope, $location, Auth) {

//watching the value of the currentUser variable.
$rootScope.$watch('currentUser', function(currentUser) {
// if no currentUser and on a page that requires authorization then try to update it
// will trigger 401s if user does not have a valid session
if (!currentUser && (['/', '/login', '/logout', '/signup'].indexOf($location.path()) == -1 )) {
var isValidPath = false, validPaths = [/^\/$/, /^\/blogs$/, /^\/blogs\/[0-9a-zA-Z]*$/, /^\/login$/, /^\/logout$/, /^\/signup$/];
var path = $location.path();
// because /blogs/create matches one of the regular expressions, leave isValidPath=false
if (path != '/blogs/create') {
for (var i = 0; i < validPaths.length; i++) {
if (path.search(validPaths[i]) >= 0) {
isValidPath = true;
break;
}
}
}
if (!currentUser && !isValidPath) {
Auth.currentUser();
}
});
Expand All @@ -60,4 +71,4 @@ angular.module('angularPassportApp', [
$location.path('/login');
return false;
});
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/controllers/blogs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.controller('BlogsCtrl', function ($scope, Blogs, $location, $routeParams, $rootScope) {
.controller('BlogsCtrl', ['$scope', 'Blogs', '$location', '$routeParams', '$rootScope', function ($scope, Blogs, $location, $routeParams, $rootScope) {

$scope.create = function() {
var blog = new Blogs({
Expand Down Expand Up @@ -46,4 +46,4 @@ angular.module('angularPassportApp')
$scope.blog = blog;
});
};
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/controllers/login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.controller('LoginCtrl', function ($scope, Auth, $location) {
.controller('LoginCtrl', ['$scope', 'Auth', '$location', function ($scope, Auth, $location) {
$scope.error = {};
$scope.user = {};

Expand All @@ -24,4 +24,4 @@ angular.module('angularPassportApp')
}
});
};
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

angular.module('angularPassportApp')
.controller('MainCtrl', function ($scope) {
});
.controller('MainCtrl', ['$scope', function ($scope) {
}]);
4 changes: 2 additions & 2 deletions app/scripts/controllers/navbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.controller('NavbarCtrl', function ($scope, Auth, $location) {
.controller('NavbarCtrl', ['$scope', 'Auth', '$location', function ($scope, Auth, $location) {
$scope.menu = [{
"title": "Blogs",
"link": "blogs"
Expand All @@ -19,4 +19,4 @@ angular.module('angularPassportApp')
}
});
};
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/controllers/signup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.controller('SignupCtrl', function ($scope, Auth, $location) {
.controller('SignupCtrl', ['$scope', 'Auth', '$location', function ($scope, Auth, $location) {
$scope.register = function(form) {
Auth.createUser({
email: $scope.user.email,
Expand All @@ -22,4 +22,4 @@ angular.module('angularPassportApp')
}
);
};
});
}]);
5 changes: 2 additions & 3 deletions app/scripts/directives/uniqueUsername.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.directive('uniqueUsername', function ($http) {
.directive('uniqueUsername', ['$http', function ($http) {
return {
restrict: 'A',
require: 'ngModel',
Expand All @@ -25,5 +25,4 @@ angular.module('angularPassportApp')
}, validate);
}
};
});

}]);
4 changes: 2 additions & 2 deletions app/scripts/services/Auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('angularPassportApp')
.factory('Auth', function Auth($location, $rootScope, Session, User, $cookieStore) {
.factory('Auth', ['$location', '$rootScope', 'Session', 'User', '$cookieStore', function Auth($location, $rootScope, Session, User, $cookieStore) {
$rootScope.currentUser = $cookieStore.get('user') || null;
$cookieStore.remove('user');

Expand Down Expand Up @@ -78,4 +78,4 @@ angular.module('angularPassportApp')
});
}
};
})
}]);
4 changes: 2 additions & 2 deletions app/scripts/services/Blogs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

angular.module('angularPassportApp')
.factory('Blogs', function ($resource) {
.factory('Blogs', ['$resource', function ($resource) {
return $resource('api/blogs/:blogId', {
blogId: '@_id'
}, {
update: {
method: 'PUT'
}
});
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/services/Session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('angularPassportApp')
.factory('Session', function ($resource) {
.factory('Session', ['$resource', function ($resource) {
return $resource('/auth/session/');
});
}]);
4 changes: 2 additions & 2 deletions app/scripts/services/User.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

angular.module('angularPassportApp')
.factory('User', function ($resource) {
.factory('User', ['$resource', function ($resource) {
return $resource('/auth/users/:id/', {},
{
'update': {
method:'PUT'
}
});
});
}]);
66 changes: 34 additions & 32 deletions app/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
</head>
<body ng-app="angularPassportApp">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
Expand All @@ -31,41 +31,43 @@
<div class="container" ng-view=""></div>

<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
<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),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
<!--
<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),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
</script>
-->

<script src="bower_components/angular/angular.js"></script>

<!-- build:js(app) scripts/modules.js -->
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/angular-http-auth/src/http-auth-interceptor.js"></script>
<!-- endbuild -->
<!-- build:js(app) scripts/modules.js -->
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/angular-http-auth/src/http-auth-interceptor.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/login.js"></script>
<script src="scripts/controllers/navbar.js"></script>
<script src="scripts/controllers/signup.js"></script>
<script src="scripts/controllers/blogs.js"></script>
<script src="scripts/directives/uniqueUsername.js"></script>
<script src="scripts/services/Auth.js"></script>
<script src="scripts/services/User.js"></script>
<script src="scripts/directives/onFocus.js"></script>
<script src="scripts/directives/mongooseError.js"></script>
<script src="scripts/services/Session.js"></script>
<script src="scripts/services/Blogs.js"></script>
<!-- endbuild -->
</body>
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/login.js"></script>
<script src="scripts/controllers/navbar.js"></script>
<script src="scripts/controllers/signup.js"></script>
<script src="scripts/controllers/blogs.js"></script>
<script src="scripts/directives/uniqueUsername.js"></script>
<script src="scripts/services/Auth.js"></script>
<script src="scripts/services/User.js"></script>
<script src="scripts/directives/onFocus.js"></script>
<script src="scripts/directives/mongooseError.js"></script>
<script src="scripts/services/Session.js"></script>
<script src="scripts/services/Blogs.js"></script>
<!-- endbuild -->
</body>
</html>
2 changes: 1 addition & 1 deletion app/views/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<li class="dropdown">
<a class="dropdown-toggle">Welcome, {{ currentUser.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a ng-click="logout()"><span class="glyphicon-log-out"></span> Logout</a></li>
<li><a ng-click="logout()"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</li>
</ul>
Expand Down
29 changes: 16 additions & 13 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
"name": "angular-passport",
"version": "0.0.0",
"dependencies": {
"angular": "~1.2.1",
"json3": "~3.2.4",
"es5-shim": "~2.1.0",
"jquery": "~1.10.2",
"sass-bootstrap": "~3.0.0",
"angular-resource": "~1.2.0",
"angular-cookies": "~1.2.0",
"angular-sanitize": "~1.2.0",
"angular-route": "~1.2.0",
"angular-http-auth": "*",
"angular-bootstrap": "~0.7.0"
"angular": "~1.2.23",
"json3": "~3.3.2",
"es5-shim": "~4.0.3",
"jquery": "~1.11.1",
"sass-bootstrap": "*",
"angular-resource": "~1.2.23",
"angular-cookies": "~1.2.23",
"angular-sanitize": "~1.2.23",
"angular-route": "~1.2.23",
"angular-http-auth": "~1.2.1",
"angular-bootstrap": "~0.11.0"
},
"devDependencies": {
"angular-mocks": "~1.2.0",
"angular-scenario": "~1.2.0"
"angular-mocks": "~1.2.23",
"angular-scenario": "~1.2.23"
},
"resolutions": {
"angular": "~1.2.23"
}
}
5 changes: 2 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'app/bower_components/jquery/jquery.js',
'app/bower_components/jquery/dist/jquery.js',
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
Expand All @@ -21,8 +21,7 @@ module.exports = function(config) {
'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'app/bower_components/angular-http-auth/src/http-auth-interceptor.js',
'app/scripts/*.js',
'app/scripts/**/*.js',
'test/mock/**/*.js',
'app/scripts/**/*.js', //'test/mock/**/*.js',
'test/spec/**/*.js'
],

Expand Down
4 changes: 2 additions & 2 deletions lib/config/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
exports.ensureAuthenticated = function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.send(401);
res.status(401).end();
}

/**
Expand All @@ -14,7 +14,7 @@ exports.ensureAuthenticated = function ensureAuthenticated(req, res, next) {
exports.blog = {
hasAuthorization: function(req, res, next) {
if (req.blog.creator._id.toString() !== req.user._id.toString()) {
return res.send(403);
return res.status(403).end();
}
next();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
port: process.env.PORT || 3000,
port: process.env.PORT || 3000,
db: process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
'mongodb://localhost/test'
Expand Down
Loading