From 26ddda1c0a82be47f5ce91b6185388f893f1a0eb Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Fri, 15 Nov 2013 11:13:21 -0500 Subject: [PATCH] Cleanup and refactoring --- .gitignore | 1 + LICENSE | 20 -------------------- README.md | 9 +++++++++ server.js => app.js | 31 +++++++++++++------------------ controllers/{users.js => user.js} | 6 ++++-- models/user.js | 3 ++- package.json | 7 ++++--- public/js/app.js | 3 ++- public/js/controllers.js | 7 +++++++ views/index.jade | 1 + 10 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 LICENSE create mode 100644 README.md rename server.js => app.js (62%) rename controllers/{users.js => user.js} (89%) diff --git a/.gitignore b/.gitignore index 1e17e500ce2..54575623685 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ npm-debug.log node_modules .idea .DS_Store +Thumbs.db public/vendor \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 2adba61b78b..00000000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Sahat Yalkabov - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000000..a82766d8d93 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +Sendgrid +Facebook +Rdio +Tumblr +Twitter +Twilio +Etsy +Foursquare +New York Times \ No newline at end of file diff --git a/server.js b/app.js similarity index 62% rename from server.js rename to app.js index 40c6d2d5473..7a910f7bac4 100755 --- a/server.js +++ b/app.js @@ -3,30 +3,26 @@ var express = require('express'), path = require('path'), fs = require('fs'), mongoose = require('mongoose'), - passport = require('passport'), + passport = require('passport'); - config = require('./config'), +// Configuration (API Keys, Database URI) +var config = require('./config.json'); - // Load controllers - home = require('./controllers/home'), +// Load controllers +var home = require('./controllers/home'), api = require('./controllers/api'), auth = require('./controllers/auth'), - users = require('./controllers/users'); + users = require('./controllers/user'); // Connect to database -mongoose.connect(config.db, function(err, res) { - if (err) { - console.log ('Error connecting to database: ' + err); - } else { - console.log ('Successfully connected to database!'); - } -}); +var db = mongoose.connect(config.db); -var app = module.exports = express(); +// Initialize express application +var app = express(); app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); -app.set('view engine', 'jade'); +app.set('view engine', 'hbs'); app.use(express.logger('dev')); app.use(express.errorHandler()); app.use(express.favicon()); @@ -42,14 +38,13 @@ app.use(app.router); // Routes app.get('/', home.index); -//app.get('/account', auth.ensureAuthenticated, users.account); +app.get('/account', auth.ensureAuthenticated, users.account); app.get('/logout', users.logout); app.post('/login', users.postlogin); -//app.get('/admin', auth.ensureAuthenticated, auth.ensureAdmin(), users.admin); -//app.get('/api/name', api.name); +app.get('/admin', auth.ensureAuthenticated, auth.ensureAdmin(), users.admin); +app.get('/api/name', api.name); app.get('/partials/login', users.getlogin); app.get('/partials/:name', home.partials); - app.get('*', home.index); diff --git a/controllers/users.js b/controllers/user.js similarity index 89% rename from controllers/users.js rename to controllers/user.js index d278e6d7e15..cf1f0b1ae65 100644 --- a/controllers/users.js +++ b/controllers/user.js @@ -1,6 +1,8 @@ var mongoose = require('mongoose'), - passport = require('passport'), - User = require('../models/user'); + passport = require('passport'); + +// Import models +var User = require('../models/user'); exports.account = function(req, res) { res.render('account', { user: req.user }); diff --git a/models/user.js b/models/user.js index b140481af84..e84ad94e970 100644 --- a/models/user.js +++ b/models/user.js @@ -1,5 +1,6 @@ var mongoose = require('mongoose'), - bcrypt = require('bcrypt'); + bcrypt = require('bcrypt'); + var userSchema = new mongoose.Schema({ username: { type: String, required: true, unique: true }, diff --git a/package.json b/package.json index 5e37b07c2f1..9564954c28e 100755 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "passport": "latest", "passport-local": "latest", "underscore": "latest", - "forever": "latest" - } -} \ No newline at end of file + "forever": "latest", + "hbs": "latest" + } +} diff --git a/public/js/app.js b/public/js/app.js index a7bab0fd8c2..29c8010f7bc 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -16,8 +16,9 @@ angular.module('myApp', ['ngRoute', 'myApp.filters', 'myApp.services', 'myApp.di templateUrl: 'partials/login', controller: MyCtrl3 }); - $routeProvider.when('/logout', { + $routeProvider.when('/logout', { + controller: MyCtrl4 }); $routeProvider.otherwise({ redirectTo: '/view1' }); $locationProvider.html5Mode(true); diff --git a/public/js/controllers.js b/public/js/controllers.js index d19f8418b7a..5d8f71892da 100755 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -19,5 +19,12 @@ MyCtrl1.$inject = []; function MyCtrl2() { } MyCtrl2.$inject = []; + function MyCtrl3() {} MyCtrl3.$inject = []; + + +function MyCtrl4($scope, $http) { + $http({ method: 'GET', url: '/logout' }); +} +MyCtrl4.$inject = []; diff --git a/views/index.jade b/views/index.jade index 79870d4afe8..478f8e9d4c3 100644 --- a/views/index.jade +++ b/views/index.jade @@ -26,6 +26,7 @@ block body div(ng-controller='AppCtrl') .jumbotron h1 Hello {{name}} + h2 3 times 3 mod 3 is {{3*3%3}} div(ng-view) br button.btn.btn-labeled.btn-success(type='button')