Merge pull request #616 from meanjs/master_to_0.4.0

Master to 0.4.0
This commit is contained in:
Liran Tal
2015-07-08 21:13:58 +03:00
30 changed files with 448 additions and 242 deletions

View File

@@ -1,6 +1,6 @@
# EditorConfig is awesome: http://EditorConfig.org
# Howto with your editor:
# Howto with your editor: http://editorconfig.org/#download
# Sublime: https://github.com/sindresorhus/editorconfig-sublime
# top-most EditorConfig file
@@ -34,3 +34,9 @@ indent_style = tab
# Standard at:
[Makefile]
indent_style = tab
# The indentation in package.json will always need to be 2 spaces
# https://github.com/npm/npm/issues/4718
[package.json, bower.json]
indent_style = space
indent_size = 2

56
.gitignore vendored
View File

@@ -1,13 +1,63 @@
# OS
# ===========
.DS_Store
ehthumbs.db
Icon?
Thumbs.db
# Node and related ecosystem
# ==========================
.nodemonignore
.sass-cache/
*.log
node_modules/
public/lib/
config/env/local.js
public/dist/
app/tests/coverage/
.bower-*/
.idea/
# MEAN.js app and assets
# ======================
public/dist/
uploads
modules/users/client/img/profile/uploads
config/env/local.js
*.pem
# Sublime editor
# ==============
.sublime-project
*.sublime-project
*.sublime-workspace
# Eclipse project files
# =====================
.project
.settings/
.*.md.html
.metadata
*~.nib
local.properties
# IntelliJ
# ========
*.iml
# Cloud9 IDE
# =========
.c9/
data/
mongod
# General
# =======
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.tmp
*.bak
*.swp
logs/
build/

View File

@@ -1,6 +1,7 @@
language: node_js
node_js:
- "0.10"
- "0.12"
env:
- NODE_ENV=travis
services:

View File

@@ -2,68 +2,69 @@
[![Build Status](https://travis-ci.org/meanjs/mean.svg?branch=master)](https://travis-ci.org/meanjs/mean)
[![Dependencies Status](https://david-dm.org/meanjs/mean.svg)](https://david-dm.org/meanjs/mean)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/meanjs/mean?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
MEAN.JS is a full-stack JavaScript open-source solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [Node.js](http://www.nodejs.org/), [Express](http://expressjs.com/), and [AngularJS](http://angularjs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.
MEAN.JS is a full-stack JavaScript open-source solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [Node.js](http://www.nodejs.org/), [Express](http://expressjs.com/), and [AngularJS](http://angularjs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.
## Before You Begin
Before you begin we recommend you read about the basic building blocks that assemble a MEAN.JS application:
## Before You Begin
Before you begin we recommend you read about the basic building blocks that assemble a MEAN.JS application:
* MongoDB - Go through [MongoDB Official Website](http://mongodb.org/) and proceed to their [Official Manual](http://docs.mongodb.org/manual/), which should help you understand NoSQL and MongoDB better.
* Express - The best way to understand express is through its [Official Website](http://expressjs.com/), particularly [The Express Guide](http://expressjs.com/guide.html); you can also go through this [StackOverflow Thread](http://stackoverflow.com/questions/8144214/learning-express-for-node-js) for more resources.
* Express - The best way to understand express is through its [Official Website](http://expressjs.com/), which has a [Getting Started](http://expressjs.com/starter/installing.html) guide, as well as an [ExpressJS Guide](http://expressjs.com/guide/error-handling.html) guide for general express topics. You can also go through this [StackOverflow Thread](http://stackoverflow.com/questions/8144214/learning-express-for-node-js) for more resources.
* AngularJS - Angular's [Official Website](http://angularjs.org/) is a great starting point. You can also use [Thinkster Popular Guide](http://www.thinkster.io/), and the [Egghead Videos](https://egghead.io/).
* Node.js - Start by going through [Node.js Official Website](http://nodejs.org/) and this [StackOverflow Thread](http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js), which should get you going with the Node.js platform in no time.
## Prerequisites
Make sure you have installed all these prerequisites on your development machine.
* Node.js - [Download & Install Node.js](http://www.nodejs.org/download/) and the npm package manager, if you encounter any problems, you can also use this [Github Gist](https://gist.github.com/isaacs/579814) to install Node.js.
Make sure you have installed all of the following prerequisites on your development machine:
* Node.js - [Download & Install Node.js](http://www.nodejs.org/download/) and the npm package manager. If you encounter any problems, you can also use this [GitHub Gist](https://gist.github.com/isaacs/579814) to install Node.js.
* MongoDB - [Download & Install MongoDB](http://www.mongodb.org/downloads), and make sure it's running on the default port (27017).
* Bower - You're going to use the [Bower Package Manager](http://bower.io/) to manage your front-end packages, in order to install it make sure you've installed Node.js and npm, then install bower globally using npm:
* Bower - You're going to use the [Bower Package Manager](http://bower.io/) to manage your front-end packages. Make sure you've installed Node.js and npm first, then install bower globally using npm:
```
```bash
$ npm install -g bower
```
* Grunt - You're going to use the [Grunt Task Runner](http://gruntjs.com/) to automate your development process, in order to install it make sure you've installed Node.js and npm, then install grunt globally using npm:
* Grunt - You're going to use the [Grunt Task Runner](http://gruntjs.com/) to automate your development process. Make sure you've installed Node.js and npm first, then install grunt globally using npm:
```
$ sudo npm install -g grunt-cli
```bash
$ npm install -g grunt-cli
```
## Downloading MEAN.JS
There are several ways you can get the MEAN.JS boilerplate:
There are several ways you can get the MEAN.JS boilerplate:
### Yo Generator
The recommended way would be to use the [Official Yo Generator](http://meanjs.org/generator.html) which will generate the latest stable copy of the MEAN.JS boilerplate and supplies multiple sub-generators to ease your daily development cycles.
### Yo Generator
The recommended way would be to use the [Official Yo Generator](http://meanjs.org/generator.html), which generates the latest stable copy of the MEAN.JS boilerplate and supplies multiple sub-generators to ease your daily development cycles.
### Cloning The GitHub Repository
You can also use Git to directly clone the MEAN.JS repository:
```
```bash
$ git clone https://github.com/meanjs/mean.git meanjs
```
This will clone the latest version of the MEAN.JS repository to a **meanjs** folder.
### Downloading The Repository Zip File
Another way to use the MEAN.JS boilerplate is to download a zip copy from the [master branch on github](https://github.com/meanjs/mean/archive/master.zip). You can also do this using `wget` command:
```
Another way to use the MEAN.JS boilerplate is to download a zip copy from the [master branch on GitHub](https://github.com/meanjs/mean/archive/master.zip). You can also do this using `wget` command:
```bash
$ wget https://github.com/meanjs/mean/archive/master.zip -O meanjs.zip; unzip meanjs.zip; rm meanjs.zip
```
Don't forget to rename **mean-master** after your project name.
## Quick Install
Once you've downloaded the boilerplate and installed all the prerequisites, you're just a few steps away from starting to develop you MEAN application.
Once you've downloaded the boilerplate and installed all the prerequisites, you're just a few steps away from starting to develop your MEAN application.
The first thing you should do is install the Node.js dependencies. The boilerplate comes pre-bundled with a package.json file that contains the list of modules you need to start your application, to learn more about the modules installed visit the NPM & Package.json section.
The first thing you should do is install the Node.js dependencies. The boilerplate comes pre-bundled with a package.json file that contains the list of modules you need to start your application. To learn more about the modules installed visit the NPM & Package.json section.
To install Node.js dependencies you're going to use npm again, in the application folder run this in the command-line:
To install Node.js dependencies you're going to use npm again. In the application folder run this in the command-line:
```
```bash
$ npm install
```
This command does a few things:
* First it will install the dependencies needed for the application to run.
* If you're running in a development environment, it will then also install development dependencies needed for testing and running your application.
* Finally, when the install process is over, npm will initiate a bower installcommand to install all the front-end modules needed for the application
* Finally, when the install process is over, npm will initiate a bower install command to install all the front-end modules needed for the application
## Running Your Application
After the install process is over, you'll be able to run your application using Grunt, just run grunt default task:
@@ -72,17 +73,38 @@ After the install process is over, you'll be able to run your application using
$ grunt
```
Your application should run on the 3000 port so in your browser just go to [http://localhost:3000](http://localhost:3000)
That's it! your application should be running by now, to proceed with your development check the other sections in this documentation.
If you encounter any problem try the Troubleshooting section.
Your application should run on port 3000, so in your browser just go to [http://localhost:3000](http://localhost:3000)
That's it! Your application should be running. To proceed with your development, check the other sections in this documentation.
If you encounter any problems, try the Troubleshooting section.
## Testing Your Application
You can run the full test suite included with MEAN.JS with the test task:
```
$ grunt test
```
This will run both the server-side tests (located in the app/tests/ directory) and the client-side tests (located in the public/modules/*/tests/).
To execute only the server tests, run the test:server task:
```
$ grunt test:server
```
And to run only the client tests, run the test:client task:
```
$ grunt test:client
```
## Development and deployment With Docker
* Install [Docker](http://www.docker.com/)
* Install [Fig](https://github.com/orchardup/fig)
* Local development and testing with fig:
* Local development and testing with fig:
```bash
$ fig up
```
@@ -95,17 +117,25 @@ $ docker run -p 3000:3000 --link db:db_1 mean
$
```
* To enable live reload forward 35729 port and mount /app and /public as volumes:
* To enable live reload, forward port 35729 and mount /app and /public as volumes:
```bash
$ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspa/mean-stack/mean/app:/home/mean/app --link db:db_1 mean
$ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspace/mean-stack/mean/app:/home/mean/app --link db:db_1 mean
```
## Running in a secure environment
To run your application in a secure manner you'll need to use OpenSSL and generate a set of self-signed certificates. Unix-based users can use the following command:
```bash
$ sh ./scripts/generate-ssl-certs.sh
```
Windows users can follow instructions found [here](http://www.websense.com/support/article/kbarticle/How-to-use-OpenSSL-and-Microsoft-Certification-Authority).
After you've generated the key and certificate, place them in the *config/sslcerts* folder.
## Getting Started With MEAN.JS
You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html).
In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development procees. We tried covering as many aspects as possible, and will keep update it by your request, you can also help us develop the documentation better by checking out the *gh-pages* branch of this repository.
You have your application running, but there is a lot of stuff to understand. We recommend you go over the [Official Documentation](http://meanjs.org/docs.html).
In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development process. We tried covering as many aspects as possible, and will keep it updated by your request. You can also help us develop and improve the documentation by checking out the *gh-pages* branch of this repository.
## Community
* Use to [Offical Website](http://meanjs.org) to learn about changes and the roadmap.
* Use the [Official Website](http://meanjs.org) to learn about changes and the roadmap.
* Join #meanjs on freenode.
* Discuss it in the new [Google Group](https://groups.google.com/d/forum/meanjs)
* Ping us on [Twitter](http://twitter.com/meanjsorg) and [Facebook](http://facebook.com/meanjs)

View File

@@ -1,16 +1,19 @@
{
"name": "meanjs",
"version": "0.4.0",
"description": "Fullstack JavaScript with MongoDB, Express, AngularJS, and Node.js.",
"dependencies": {
"bootstrap": "~3",
"angular": "~1.2",
"angular-resource": "~1.2",
"angular-animate": "~1.2",
"angular-mocks": "~1.2",
"angular-bootstrap": "~0.11.0",
"angular-ui-utils": "~0.1.1",
"angular-ui-router": "~0.2.10",
"angular-file-upload": "~1.1.5"
}
"name": "meanjs",
"version": "0.4.0",
"description": "Fullstack JavaScript with MongoDB, Express, AngularJS, and Node.js.",
"dependencies": {
"bootstrap": "~3",
"angular": "~1.3",
"angular-resource": "~1.3",
"angular-animate": "~1.3",
"angular-mocks": "~1.3",
"angular-bootstrap": "~0.13",
"angular-ui-utils": "bower",
"angular-ui-router": "~0.2",
"angular-file-upload": "~1.1.5"
},
"resolutions": {
"angular": "~1.3"
}
}

View File

@@ -1,7 +1,22 @@
'use strict';
module.exports = {
db: 'mongodb://localhost/mean-dev',
db: {
uri: 'mongodb://localhost/mean-test',
options: {
user: '',
pass: ''
}
},
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'dev',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
//stream: 'access.log'
}
},
app: {
title: 'MEAN.JS - Development Environment'
},

View File

@@ -1,42 +1,75 @@
'use strict';
module.exports = {
secure: true,
secure: true,
port: process.env.PORT || 8443,
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/facebook/callback'
},
twitter: {
clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY',
clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET',
callbackURL: '/api/auth/twitter/callback'
},
google: {
clientID: process.env.GOOGLE_ID || 'APP_ID',
clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/google/callback'
},
linkedin: {
clientID: process.env.LINKEDIN_ID || 'APP_ID',
clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/linkedin/callback'
},
github: {
clientID: process.env.GITHUB_ID || 'APP_ID',
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/github/callback'
},
mailer: {
from: process.env.MAILER_FROM || 'MAILER_FROM',
options: {
service: process.env.MAILER_SERVICE_PROVIDER || 'MAILER_SERVICE_PROVIDER',
auth: {
user: process.env.MAILER_EMAIL_ID || 'MAILER_EMAIL_ID',
pass: process.env.MAILER_PASSWORD || 'MAILER_PASSWORD'
}
}
}
db: {
uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
options: {
user: '',
pass: ''
}
},
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'combined',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
stream: 'access.log'
}
},
assets: {
lib: {
css: [
'public/lib/bootstrap/dist/css/bootstrap.min.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.min.css',
],
js: [
'public/lib/angular/angular.min.js',
'public/lib/angular-resource/angular-resource.min.js',
'public/lib/angular-animate/angular-animate.min.js',
'public/lib/angular-ui-router/release/angular-ui-router.min.js',
'public/lib/angular-ui-utils/ui-utils.min.js',
'public/lib/angular-bootstrap/ui-bootstrap-tpls.min.js'
]
},
css: 'public/dist/application.min.css',
js: 'public/dist/application.min.js'
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/facebook/callback'
},
twitter: {
clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY',
clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET',
callbackURL: '/api/auth/twitter/callback'
},
google: {
clientID: process.env.GOOGLE_ID || 'APP_ID',
clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/google/callback'
},
linkedin: {
clientID: process.env.LINKEDIN_ID || 'APP_ID',
clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/linkedin/callback'
},
github: {
clientID: process.env.GITHUB_ID || 'APP_ID',
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/github/callback'
},
mailer: {
from: process.env.MAILER_FROM || 'MAILER_FROM',
options: {
service: process.env.MAILER_SERVICE_PROVIDER || 'MAILER_SERVICE_PROVIDER',
auth: {
user: process.env.MAILER_EMAIL_ID || 'MAILER_EMAIL_ID',
pass: process.env.MAILER_PASSWORD || 'MAILER_PASSWORD'
}
}
}
};

8
config/env/test.js vendored
View File

@@ -1,7 +1,13 @@
'use strict';
module.exports = {
db: 'mongodb://localhost/mean-test',
db: {
uri: 'mongodb://localhost/mean-test',
options: {
user: '',
pass: ''
}
},
port: 3001,
app: {
title: 'MEAN.JS - Test Environment'

View File

@@ -20,7 +20,7 @@ module.exports.loadModels = function() {
module.exports.connect = function(cb) {
var _this = this;
var db = mongoose.connect(config.db, function (err) {
var db = mongoose.connect(config.db.uri, config.db.options, function (err) {
// Log Error
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));

View File

@@ -231,6 +231,8 @@ module.exports = function (grunt) {
// Run the project tests
grunt.registerTask('test', ['env:test', 'copy:localConfig', 'mongoose', 'mochaTest', 'karma:unit']);
grunt.registerTask('test:server', ['env:test', 'mongoose', 'mochaTest']);
grunt.registerTask('test:client', ['env:test', 'mongoose', 'karma:unit']);
// Run the project in development mode
grunt.registerTask('default', ['env:dev', 'lint', 'copy:localConfig', 'concurrent:default']);

View File

@@ -18,7 +18,6 @@ module.exports = function(karmaConfig) {
// Test results reporter to use
// Possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
//reporters: ['progress'],
reporters: ['progress'],
// Web server port

View File

@@ -1,17 +1,23 @@
'use strict';
// Articles controller
angular.module('articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles',
function($scope, $stateParams, $location, Authentication, Articles) {
$scope.authentication = Authentication;
// Create new Article
$scope.create = function() {
// Create new Article object
var article = new Articles({
title: this.title,
content: this.content
});
// Redirect after save
article.$save(function(response) {
$location.path('articles/' + response._id);
// Clear form fields
$scope.title = '';
$scope.content = '';
}, function(errorResponse) {
@@ -19,6 +25,7 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
});
};
// Remove existing Article
$scope.remove = function(article) {
if (article) {
article.$remove();
@@ -35,6 +42,7 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
}
};
// Update existing Article
$scope.update = function() {
var article = $scope.article;
@@ -45,10 +53,12 @@ angular.module('articles').controller('ArticlesController', ['$scope', '$statePa
});
};
// Find a list of Articles
$scope.find = function() {
$scope.articles = Articles.query();
};
// Find existing Article
$scope.findOne = function() {
$scope.article = Articles.get({
articleId: $stateParams.articleId

View File

@@ -89,10 +89,21 @@ exports.list = function(req, res) {
* Article middleware
*/
exports.articleByID = function(req, res, next, id) {
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(400).send({
message: 'Article is invalid'
});
}
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
if (!article) {
return res.status(404).send({
message: errorHandler.getErrorMessage(err)
});
}
req.article = article;
next();
});
};
};

View File

@@ -2,7 +2,7 @@
(function() {
// Articles Controller Spec
describe('ArticlesController', function() {
describe('Articles Controller Tests', function() {
// Initialize global variables
var ArticlesController,
scope,

View File

@@ -16,8 +16,8 @@ var app, agent, credentials, user, article;
/**
* Article routes tests
*/
describe('Article CRUD tests', function() {
before(function(done) {
describe('Article CRUD tests', function () {
before(function (done) {
// Get application
app = express.init(mongoose);
agent = request.agent(app);
@@ -25,7 +25,7 @@ describe('Article CRUD tests', function() {
done();
});
beforeEach(function(done) {
beforeEach(function (done) {
// Create user credentials
credentials = {
username: 'username',
@@ -44,7 +44,7 @@ describe('Article CRUD tests', function() {
});
// Save a user to the test db and create new article
user.save(function() {
user.save(function () {
article = {
title: 'Article Title',
content: 'Article Content'
@@ -54,11 +54,11 @@ describe('Article CRUD tests', function() {
});
});
it('should be able to save an article if logged in', function(done) {
it('should be able to save an article if logged in', function (done) {
agent.post('/api/auth/signin')
.send(credentials)
.expect(200)
.end(function(signinErr, signinRes) {
.end(function (signinErr, signinRes) {
// Handle signin error
if (signinErr) done(signinErr);
@@ -69,13 +69,13 @@ describe('Article CRUD tests', function() {
agent.post('/api/articles')
.send(article)
.expect(200)
.end(function(articleSaveErr, articleSaveRes) {
.end(function (articleSaveErr, articleSaveRes) {
// Handle article save error
if (articleSaveErr) done(articleSaveErr);
// Get a list of articles
agent.get('/api/articles')
.end(function(articlesGetErr, articlesGetRes) {
.end(function (articlesGetErr, articlesGetRes) {
// Handle article save error
if (articlesGetErr) done(articlesGetErr);
@@ -93,24 +93,24 @@ describe('Article CRUD tests', function() {
});
});
it('should not be able to save an article if not logged in', function(done) {
it('should not be able to save an article if not logged in', function (done) {
agent.post('/api/articles')
.send(article)
.expect(403)
.end(function(articleSaveErr, articleSaveRes) {
.end(function (articleSaveErr, articleSaveRes) {
// Call the assertion callback
done(articleSaveErr);
});
});
it('should not be able to save an article if no title is provided', function(done) {
it('should not be able to save an article if no title is provided', function (done) {
// Invalidate title field
article.title = '';
agent.post('/api/auth/signin')
.send(credentials)
.expect(200)
.end(function(signinErr, signinRes) {
.end(function (signinErr, signinRes) {
// Handle signin error
if (signinErr) done(signinErr);
@@ -121,7 +121,7 @@ describe('Article CRUD tests', function() {
agent.post('/api/articles')
.send(article)
.expect(400)
.end(function(articleSaveErr, articleSaveRes) {
.end(function (articleSaveErr, articleSaveRes) {
// Set message assertion
(articleSaveRes.body.message).should.match('Title cannot be blank');
@@ -131,11 +131,11 @@ describe('Article CRUD tests', function() {
});
});
it('should be able to update an article if signed in', function(done) {
it('should be able to update an article if signed in', function (done) {
agent.post('/api/auth/signin')
.send(credentials)
.expect(200)
.end(function(signinErr, signinRes) {
.end(function (signinErr, signinRes) {
// Handle signin error
if (signinErr) done(signinErr);
@@ -146,7 +146,7 @@ describe('Article CRUD tests', function() {
agent.post('/api/articles')
.send(article)
.expect(200)
.end(function(articleSaveErr, articleSaveRes) {
.end(function (articleSaveErr, articleSaveRes) {
// Handle article save error
if (articleSaveErr) done(articleSaveErr);
@@ -157,7 +157,7 @@ describe('Article CRUD tests', function() {
agent.put('/api/articles/' + articleSaveRes.body._id)
.send(article)
.expect(200)
.end(function(articleUpdateErr, articleUpdateRes) {
.end(function (articleUpdateErr, articleUpdateRes) {
// Handle article update error
if (articleUpdateErr) done(articleUpdateErr);
@@ -172,17 +172,17 @@ describe('Article CRUD tests', function() {
});
});
it('should be able to get a list of articles if not signed in', function(done) {
it('should be able to get a list of articles if not signed in', function (done) {
// Create new article model instance
var articleObj = new Article(article);
// Save the article
articleObj.save(function() {
articleObj.save(function () {
// Request articles
request(app).get('/api/articles')
.end(function(req, res) {
.end(function (req, res) {
// Set assertion
res.body.should.be.an.Array.with.lengthOf(1);
res.body.should.be.instanceof(Array).and.have.lengthOf(1);
// Call the assertion callback
done();
@@ -192,16 +192,16 @@ describe('Article CRUD tests', function() {
});
it('should be able to get a single article if not signed in', function(done) {
it('should be able to get a single article if not signed in', function (done) {
// Create new article model instance
var articleObj = new Article(article);
// Save the article
articleObj.save(function() {
articleObj.save(function () {
request(app).get('/api/articles/' + articleObj._id)
.end(function(req, res) {
.end(function (req, res) {
// Set assertion
res.body.should.be.an.Object.with.property('title', article.title);
res.body.should.be.instanceof(Object).and.have.property('title', article.title);
// Call the assertion callback
done();
@@ -209,11 +209,23 @@ describe('Article CRUD tests', function() {
});
});
it('should be able to delete an article if signed in', function(done) {
it('should return proper error for single article which doesnt exist, if not signed in', function (done) {
request(app).get('/api/articles/test')
.end(function (req, res) {
console.log(res.body);
// Set assertion
res.body.should.be.instanceof(Object).and.have.property('message', 'Article is invalid');
// Call the assertion callback
done();
});
});
it('should be able to delete an article if signed in', function (done) {
agent.post('/api/auth/signin')
.send(credentials)
.expect(200)
.end(function(signinErr, signinRes) {
.end(function (signinErr, signinRes) {
// Handle signin error
if (signinErr) done(signinErr);
@@ -224,7 +236,7 @@ describe('Article CRUD tests', function() {
agent.post('/api/articles')
.send(article)
.expect(200)
.end(function(articleSaveErr, articleSaveRes) {
.end(function (articleSaveErr, articleSaveRes) {
// Handle article save error
if (articleSaveErr) done(articleSaveErr);
@@ -232,7 +244,7 @@ describe('Article CRUD tests', function() {
agent.delete('/api/articles/' + articleSaveRes.body._id)
.send(article)
.expect(200)
.end(function(articleDeleteErr, articleDeleteRes) {
.end(function (articleDeleteErr, articleDeleteRes) {
// Handle article error error
if (articleDeleteErr) done(articleDeleteErr);
@@ -246,31 +258,31 @@ describe('Article CRUD tests', function() {
});
});
it('should not be able to delete an article if not signed in', function(done) {
// Set article user
it('should not be able to delete an article if not signed in', function (done) {
// Set article user
article.user = user;
// Create new article model instance
var articleObj = new Article(article);
// Save the article
articleObj.save(function() {
articleObj.save(function () {
// Try deleting article
request(app).delete('/api/articles/' + articleObj._id)
.expect(403)
.end(function(articleDeleteErr, articleDeleteRes) {
// Set message assertion
(articleDeleteRes.body.message).should.match('User is not authorized');
.expect(403)
.end(function (articleDeleteErr, articleDeleteRes) {
// Set message assertion
(articleDeleteRes.body.message).should.match('User is not authorized');
// Handle article error error
done(articleDeleteErr);
});
// Handle article error error
done(articleDeleteErr);
});
});
});
afterEach(function(done) {
User.remove().exec(function() {
afterEach(function (done) {
User.remove().exec(function () {
Article.remove().exec(done);
});
});

View File

@@ -10,11 +10,8 @@
</div>
<nav class="collapse navbar-collapse" collapse="!isCollapsed" role="navigation">
<ul class="nav navbar-nav" data-ng-if="menu.shouldRender(authentication.user);">
<li data-ng-repeat="item in menu.items | orderBy: 'position'" data-ng-if="item.shouldRender(authentication.user);" ng-switch="item.type" data-ng-class="{active: $state.includes(item.state)}" class="{{item.class}}" dropdown="item.type === 'dropdown'">
<a ng-switch-when="dropdown" class="dropdown-toggle">
<span data-ng-bind="item.title"></span>
<b class="caret"></b>
</a>
<li data-ng-repeat="item in menu.items | orderBy: 'position'" data-ng-if="item.shouldRender(authentication.user);" ng-switch="item.type" data-ng-class="{ active: $state.includes(item.state), dropdown: item.type === 'dropdown' }" class="{{item.class}}" dropdown="item.type === 'dropdown'">
<a ng-switch-when="dropdown" class="dropdown-toggle" dropdown-toggle role="button">{{::item.title}}&nbsp;<span class="caret"></span></a>
<ul ng-switch-when="dropdown" class="dropdown-menu">
<li data-ng-repeat="subitem in item.items | orderBy: 'position'" data-ng-if="subitem.shouldRender(authentication.user);" data-ui-sref-active="active">
<a data-ui-sref="{{subitem.state}}" data-ng-bind="subitem.title"></a>
@@ -33,12 +30,12 @@
</li>
</ul>
<ul class="nav navbar-nav navbar-right" data-ng-show="authentication.user">
<li class="dropdown">
<a href="#" class="dropdown-toggle user-header-dropdown-toggle" data-toggle="dropdown">
<li class="dropdown" dropdown>
<a class="dropdown-toggle user-header-dropdown-toggle" dropdown-toggle role="button">
<img data-ng-src="{{authentication.user.profileImageURL}}" alt="{{authentication.user.displayName}}" class="header-profile-image"/>
<span data-ng-bind="authentication.user.displayName"></span> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<ul class="dropdown-menu" role="menu">
<li data-ui-sref-active="active">
<a data-ui-sref="settings.profile">Edit Profile</a>
</li>

View File

@@ -54,7 +54,7 @@
<h2>
<strong>E</strong>xpress
</h2>
<p><a target="_blank" href="http://expressjs.com/"> Express</a> is an app server. Check out <a target="_blank" href="http://expressjs.com/guide.html">The Express Guide</a> or <a target="_blank" href="http://stackoverflow.com/questions/8144214/learning-express-for-node-js">StackOverflow</a> for more info.</p>
<p><a target="_blank" href="http://expressjs.com/"> Express</a> is an app server. Check out <a target="_blank" href="http://expressjs.com/4x/api.html">The ExpressJS API reference for more information</a> or <a target="_blank" href="http://stackoverflow.com/questions/8144214/learning-express-for-node-js">StackOverflow</a> for more info.</p>
</div>
<div class="col-md-3">
<h2>

View File

@@ -6,6 +6,7 @@
<!-- General META -->
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="fragment" content="!">
<base href="/">
@@ -69,17 +70,6 @@
<!--Livereload script rendered -->
<script type="text/javascript" src="{{host}}:35729/livereload.js"></script>
{% endif %}
<!-- Google Analytics -->
<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', '{{googleAnalyticsTrackingID}}', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

View File

@@ -12,7 +12,7 @@
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify Password">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Update Password</button>
<button type="submit" class="btn btn-lg btn-primary">Update Password</button>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong>{{error}}</strong>

View File

@@ -15,7 +15,7 @@
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify Password">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Save Password</button>
<button type="submit" class="btn btn-lg btn-primary">Save Password</button>
</div>
<div data-ng-show="success" class="text-center text-success">
<strong>Password Changed Successfully</strong>

View File

@@ -19,7 +19,7 @@
<input type="text" id="username" name="username" class="form-control" data-ng-model="user.username" placeholder="Username">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Save Profile</button>
<button type="submit" class="btn btn-lg btn-primary">Save Profile</button>
</div>
<div data-ng-show="success" class="text-center text-success">
<strong>Profile Saved Successfully</strong>

View File

@@ -22,8 +22,15 @@ module.exports = function(config) {
providerData.refreshToken = refreshToken;
// Create the user OAuth profile
var displayName = profile.displayName.trim();
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';
var providerUserProfile = {
displayName: profile.displayName,
firstName: firstName,
lastName: lastName,
displayName: displayName,
email: profile.emails[0].value,
username: profile.username,
profileImageURL: (providerData.avatar_url) ? providerData.avatar_url : undefined,

View File

@@ -22,8 +22,15 @@ module.exports = function(config) {
providerData.tokenSecret = tokenSecret;
// Create the user OAuth profile
var displayName = profile.displayName.trim();
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';
var providerUserProfile = {
displayName: profile.displayName,
firstName: firstName,
lastName: lastName,
displayName: displayName,
username: profile.username,
profileImageURL: profile.photos[0].value.replace('normal', 'bigger'),
provider: 'twitter',

View File

@@ -8,6 +8,9 @@ var passport = require('passport'),
path = require('path'),
config = require(path.resolve('./config/config'));
/**
* Module init function.
*/
module.exports = function(app, db) {
// Serialize sessions
passport.serializeUser(function(user, done) {

View File

@@ -24,7 +24,7 @@ exports.signup = function(req, res) {
user.provider = 'local';
user.displayName = user.firstName + ' ' + user.lastName;
// Then save the user
// Then save the user
user.save(function(err) {
if (err) {
return res.status(400).send({

View File

@@ -12,6 +12,8 @@ var path = require('path'),
async = require('async'),
crypto = require('crypto');
var smtpTransport = nodemailer.createTransport(config.mailer.options);
/**
* Forgot for reset password (forgot POST)
*/
@@ -64,7 +66,6 @@ exports.forgot = function(req, res, next) {
},
// If valid email, send reset email using service
function(emailHTML, user, done) {
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var mailOptions = {
to: user.email,
from: config.mailer.from,
@@ -76,6 +77,10 @@ exports.forgot = function(req, res, next) {
res.send({
message: 'An email has been sent to the provided email with further instructions.'
});
} else {
return res.status(400).send({
message: 'Failure sending email'
});
}
done(err);
@@ -167,7 +172,6 @@ exports.reset = function(req, res, next) {
},
// If valid email, send reset email using service
function(emailHTML, user, done) {
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var mailOptions = {
to: user.email,
from: config.mailer.from,

View File

@@ -50,7 +50,7 @@ var UserSchema = new Schema({
},
username: {
type: String,
unique: 'testing error message',
unique: 'Username already exists',
required: 'Please fill in a username',
trim: true
},

View File

@@ -9,8 +9,8 @@
"url": "https://github.com/meanjs/mean.git"
},
"engines": {
"node": "0.10.x",
"npm": "1.4.x"
"node": ">=0.10.28",
"npm": ">=1.4.28"
},
"scripts": {
"start": "grunt",
@@ -18,81 +18,81 @@
"postinstall": "bower install --config.interactive=false"
},
"dependencies": {
"express": "~4.12.3",
"express-session": "~1.10.4",
"serve-favicon": "~2.1.6",
"body-parser": "~1.12.2",
"cookie-parser": "~1.3.2",
"compression": "~1.4.3",
"method-override": "~2.3.0",
"morgan": "~1.5.2",
"multer": "0.1.6",
"connect-mongo": "~0.8.0",
"connect-flash": "~0.1.1",
"helmet": "~0.7.1",
"consolidate": "~0.11.0",
"swig": "~1.4.1",
"mongoose": "~3.8.8",
"passport": "~0.2.0",
"passport-local": "~1.0.0",
"passport-facebook": "~1.0.2",
"passport-twitter": "~1.0.2",
"passport-linkedin": "~0.1.3",
"passport-google-oauth": "~0.1.5",
"passport-github": "~0.1.5",
"acl": "~0.4.4",
"socket.io": "~1.1.0",
"lodash": "~2.4.1",
"forever": "~0.11.0",
"bower": "~1.3.8",
"async": "^1.3.0",
"body-parser": "^1.13.1",
"bower": "^1.4.1",
"chalk": "^1.1.0",
"compression": "^1.5.0",
"connect-flash": "~0.1.1",
"connect-mongo": "~0.8.1",
"consolidate": "~0.13.1",
"cookie-parser": "^1.3.2",
"express": "^4.13.0",
"express-session": "^1.11.3",
"forever": "~0.14.2",
"glob": "^5.0.13",
"grunt-cli": "~0.1.13",
"chalk": "~0.5.1",
"glob": "~5.0.0",
"async": "~0.9.0",
"nodemailer": "~1.3.0"
"helmet": "~0.9.1",
"lodash": "^3.10.0",
"method-override": "^2.3.3",
"mongoose": "^4.0.6",
"morgan": "^1.6.1",
"multer": "0.1.8",
"nodemailer": "^1.4.0",
"passport": "~0.2.2",
"passport-facebook": "^2.0.0",
"passport-github": "~0.1.5",
"passport-google-oauth": "~0.2.0",
"passport-linkedin": "~0.1.3",
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.2",
"serve-favicon": "^2.3.0",
"socket.io": "^1.3.5",
"swig": "^1.4.2"
},
"devDependencies": {
"supertest": "~0.14.0",
"should": "~4.1.0",
"grunt-env": "~0.4.1",
"grunt-node-inspector": "~0.1.3",
"grunt-concurrent": "^2.0.0",
"grunt-contrib-copy": "~0.8.0",
"grunt-contrib-csslint": "~0.4.0",
"grunt-contrib-cssmin": "~0.12.3",
"grunt-contrib-jshint": "~0.11.2",
"grunt-contrib-less": "^1.0.1",
"grunt-contrib-sass": "~0.9.2",
"grunt-contrib-uglify": "~0.9.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-csslint": "^0.3.1",
"grunt-ng-annotate": "~0.4.0",
"grunt-contrib-uglify": "~0.6.0",
"grunt-contrib-cssmin": "~0.10.0",
"grunt-nodemon": "~0.3.0",
"grunt-contrib-copy": "0.8",
"grunt-concurrent": "~1.0.0",
"grunt-mocha-test": "~0.12.1",
"grunt-karma": "~0.9.0",
"grunt-protractor-runner": "1.1.4",
"grunt-contrib-sass": "~0.8.1",
"grunt-contrib-less": "~0.12.0",
"load-grunt-tasks": "~1.0.0",
"gulp": "~3.8.9",
"run-sequence": "~1.0.1",
"gulp-rename": "~1.2.0",
"gulp-concat": "~2.4.1",
"gulp-nodemon": "~1.0.4",
"gulp-livereload": "~2.1.1",
"gulp-jshint": "~1.8.6",
"grunt-env": "~0.4.4",
"grunt-karma": "~0.11.2",
"grunt-mocha-test": "~0.12.7",
"grunt-ng-annotate": "^1.0.1",
"grunt-node-inspector": "~0.2.0",
"grunt-nodemon": "~0.4.0",
"grunt-protractor-runner": "^2.0.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-csslint": "~0.1.5",
"gulp-ng-annotate": "~0.3.3",
"gulp-uglify": "~1.0.1",
"gulp-cssmin": "~0.1.6",
"gulp-mocha": "~1.1.1",
"gulp-cssmin": "~0.1.7",
"gulp-jshint": "^1.11.2",
"gulp-karma": "~0.0.4",
"gulp-protractor": "~0.0.11",
"gulp-sass": "~1.3.3",
"gulp-less": "~1.3.6",
"gulp-load-plugins": "~0.7.0",
"karma": "~0.12.0",
"karma-jasmine": "~0.2.1",
"karma-coverage": "~0.2.0",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.2"
"gulp-less": "^3.0.3",
"gulp-livereload": "^3.8.0",
"gulp-load-plugins": "^1.0.0-rc.1",
"gulp-mocha": "^2.1.2",
"gulp-ng-annotate": "^1.0.0",
"gulp-nodemon": "^2.0.3",
"gulp-protractor": "^1.0.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.0.3",
"gulp-uglify": "^1.2.0",
"karma": "~0.12.37",
"karma-chrome-launcher": "~0.2.0",
"karma-coverage": "~0.4.2",
"karma-firefox-launcher": "~0.1.6",
"karma-jasmine": "~0.3.6",
"karma-phantomjs-launcher": "~0.2.0",
"load-grunt-tasks": "^3.2.0",
"run-sequence": "^1.1.1",
"should": "^7.0.1",
"supertest": "^1.0.1"
}
}

16
scripts/generate-ssl-certs.sh Executable file → Normal file
View File

@@ -1,11 +1,17 @@
#!/bin/bash
if [ ! -e server.js ]
then
echo "Error: could not find main application server.js file"
echo "You should run the generate-ssl-certs.sh script from the main MEAN application root directory"
echo "i.e: bash scripts/generate-ssl-certs.sh"
exit -1
fi
echo "Generating self-signed certificates..."
mkdir -p ./config/sslcerts
openssl genrsa -out ./config/sslcerts/key.pem -aes256 1024
openssl req -new -key ./config/sslcerts/key.pem -out ./config/sslcerts/csr.pem
openssl x509 -req -days 9999 -in ./config/sslcerts/csr.pem -signkey ./config/sslcerts/key.pem -out ./config/sslcerts/cert.pem
rm ./config/sslcerts/csr.pem
# resolve issue with bad password...
# Error: error:0906A068:PEM routines:PEM_do_header:bad password read
# reference: http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/
openssl rsa -in ./config/sslcerts/key.pem -out ./config/sslcerts/newkey.pem && mv ./config/sslcerts/newkey.pem ./config/sslcerts/key.pem
chmod 0400 ./config/sslcerts/key.pem ./config/sslcerts/cert.pem
chmod 600 ./config/sslcerts/key.pem ./config/sslcerts/cert.pem

View File

@@ -5,7 +5,13 @@
*/
var config = require('./config/config'),
mongoose = require('./config/lib/mongoose'),
express = require('./config/lib/express');
express = require('./config/lib/express'),
chalk = require('chalk');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
// Initialize mongoose
mongoose.connect(function (db) {
@@ -16,5 +22,13 @@ mongoose.connect(function (db) {
app.listen(config.port);
// Logging initialization
console.log('MEAN.JS application started on port ' + config.port);
console.log('--');
console.log(chalk.green(config.app.title + ' application started'));
console.log(chalk.green('Environment:\t\t\t' + process.env.NODE_ENV));
console.log(chalk.green('Port:\t\t\t\t' + config.port));
console.log(chalk.green('Database:\t\t\t' + config.db.uri));
if (process.env.NODE_ENV === 'secure') {
console.log(chalk.green('HTTPs:\t\t\t\ton'));
}
console.log('--');
});