From e6d387f92fd58bb035cbd46f29d18d8bc392f7c2 Mon Sep 17 00:00:00 2001 From: "Spratley, Jonnie" Date: Fri, 19 Dec 2014 13:06:02 -0800 Subject: [PATCH] fixed jshint errors --- app/scripts/app.js | 8 +- app/scripts/config.js | 246 ++++++++++----------- app/scripts/controllers/admin.js | 2 +- app/scripts/controllers/dashboard.js | 2 +- app/scripts/controllers/docs.js | 2 +- app/scripts/controllers/forgot-password.js | 2 +- app/scripts/controllers/help.js | 10 +- app/scripts/controllers/login.js | 31 +-- app/scripts/controllers/pages.js | 106 ++++----- app/scripts/controllers/plugins.js | 2 +- app/scripts/controllers/settings.js | 66 +++--- app/scripts/directives/cms-formgroup.js | 7 +- app/scripts/directives/cms-gravatar.js | 6 +- app/scripts/services/cmssocketservice.js | 2 +- app/scripts/services/dataservice.js | 12 +- routes/cms-auth.js | 69 +++--- routes/cms-passport.js | 40 ++-- test/routes/cms-passport-spec.js | 8 +- test/spec/services/dataservice.js | 2 +- 19 files changed, 298 insertions(+), 325 deletions(-) diff --git a/app/scripts/app.js b/app/scripts/app.js index b2ad642..63a8618 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -10,16 +10,16 @@ * Resize textarea automatically to the size of its text content. * * @example - - - + + +
{{text}}
*/ var app; -Parse.initialize("fYHs4Flnj7vgVHm9vaFiFTSKt5Mj2Bxf9e93mTOB", "QPFGBNHs0QQHFS54atV71oKppd3gTgaFfQIHP2VW"); +Parse.initialize('fYHs4Flnj7vgVHm9vaFiFTSKt5Mj2Bxf9e93mTOB', 'QPFGBNHs0QQHFS54atV71oKppd3gTgaFfQIHP2VW'); app = angular.module('angularCmsApp', ['ngCookies', 'ngResource', 'ngSanitize', 'ngRoute', 'ngAnimate', 'mgcrea.ngStrap', 'fg']).config(function($routeProvider) { var routeResolver; diff --git a/app/scripts/config.js b/app/scripts/config.js index cf37c9e..b18399e 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -1,47 +1,47 @@ window.Config = { baseurl: document.location.origin, - sitetitle: "angular-cms", - sitedesc: "This is the description", - sitebrand: "/images/angular-cms-brand.png", - sitecopy: "2014 ", - version: "0.1", - email: "jonniespratley@me.com", + sitetitle: 'angular-cms', + sitedesc: 'This is the description', + sitebrand: '/images/angular-cms-brand.png', + sitecopy: '2014 ', + version: '0.1', + email: 'jonniespratley@me.com', debug: true, feature: { - title: "angular-cms", - body: "A content management system of some sort." + title: 'angular-cms', + body: 'A content management system of some sort.' }, features: [ { id: 1, - title: "HTML5", - body: "Using HTML5 in every way to make a better user experience.", - image: "/images/feature-html5.png" + title: 'HTML5', + body: 'Using HTML5 in every way to make a better user experience.', + image: '/images/feature-html5.png' }, { id: 2, - title: "AngularJS", - body: "The client-side framework of choice is Angular, its a full-stack.", - image: "/images/feature-angular.png" + title: 'AngularJS', + body: 'The client-side framework of choice is Angular, its a full-stack.', + image: '/images/feature-angular.png' }, { id: 3, - title: "Twitter Bootstrap", - body: "The client-side UI of choice is Twitter Bootstrap 3.0.", - image: "/images/feature-bootstrap.png" + title: 'Twitter Bootstrap', + body: 'The client-side UI of choice is Twitter Bootstrap 3.0.', + image: '/images/feature-bootstrap.png' }, { id: 4, - title: "PhantomJS", - body: "Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.", - image: "/images/feature-phantomjs.png" + title: 'PhantomJS', + body: 'Fully testable with Jasmine Karma Runner Unit e2e with PhantomJS.', + image: '/images/feature-phantomjs.png' }, { id: 5, - title: "NodeJS", - body: "The server of choice is NodeJS, its fast and scalable.", - image: "/images/feature-nodejs.png" + title: 'NodeJS', + body: 'The server of choice is NodeJS, its fast and scalable.', + image: '/images/feature-nodejs.png' }, { id: 6, - title: "MongoDB", - body: "The database of choice is Mongo, its fast and scalable.", - image: "/images/feature-mongodb.png" + title: 'MongoDB', + body: 'The database of choice is Mongo, its fast and scalable.', + image: '/images/feature-mongodb.png' } ], session: { @@ -49,97 +49,97 @@ window.Config = { user: null }, layout: { - header: "views/_header.html", - sidebar: "views/_sidebar.html", - content: "views/_content.html", - footer: "views/_footer.html" + header: 'views/_header.html', + sidebar: 'views/_sidebar.html', + content: 'views/_content.html', + footer: 'views/_footer.html' }, - theme: "default", + theme: 'default', templates: { - compiled: "/dist/templates.html", - uncompiled: "/views" + compiled: '/dist/templates.html', + uncompiled: '/views' }, menu: { admin: [ { id: 1, - title: "Pages", - href: "/pages", - icon: "edit" + title: 'Pages', + href: '/pages', + icon: 'edit' }, { id: 1, - title: "Plugins", - href: "/plugins", - icon: "folder-open" + title: 'Plugins', + href: '/plugins', + icon: 'folder-open' }, { id: 1, - title: "Widgets", - href: "/widgets", - icon: "puzzle-piece" + title: 'Widgets', + href: '/widgets', + icon: 'puzzle-piece' }, { id: 1, - title: "Media", - href: "/media", - icon: "cloud-download" + title: 'Media', + href: '/media', + icon: 'cloud-download' }, { id: 1, - title: "Users", - href: "/users", - icon: "group" + title: 'Users', + href: '/users', + icon: 'group' }, { id: 1, - title: "Themes", - href: "/themes", - icon: "camera" + title: 'Themes', + href: '/themes', + icon: 'camera' }, { id: 1, - title: "Settings", - href: "/settings", - icon: "cog" + title: 'Settings', + href: '/settings', + icon: 'cog' } ], pub: [], user: [ { id: 1, - title: "Dashboard", - icon: "dashboard", - href: "/dashboard" + title: 'Dashboard', + icon: 'dashboard', + href: '/dashboard' }, { id: 2, - title: "My Profile", - icon: "user", - href: "/profile" + title: 'My Profile', + icon: 'user', + href: '/profile' }, { id: 3, - title: "Help", - icon: "book", - href: "/help" + title: 'Help', + icon: 'book', + href: '/help' } ] }, settings: { currentdate: new Date(), - dateformats: ["medium", "short", "fullDate", "longDate", "mediumDate", "shortDate"], - timeformats: ["mediumTime", "shortTime"], - dateformat: "medium", - timeformat: "shortTime", + dateformats: ['medium', 'short', 'fullDate', 'longDate', 'mediumDate', 'shortDate'], + timeformats: ['mediumTime', 'shortTime'], + dateformat: 'medium', + timeformat: 'shortTime', timezone: null, servers: [ { - name: "apiv1", - host: "127.1.0.1", + name: 'apiv1', + host: '127.1.0.1', port: 3000, - body: "This is the v1 api server" + body: 'This is the v1 api server' }, { - name: "apiv2", - host: "127.1.0.1", + name: 'apiv2', + host: '127.1.0.1', port: 3000, - body: "This is the v2 api server" + body: 'This is the v2 api server' } ], socketio: { - host: "127.1.0.1", + host: '127.1.0.1', port: 8081 }, network: { @@ -147,106 +147,106 @@ window.Config = { cache: true }, database: { - host: "127.1.0.1", + host: '127.1.0.1', port: 27017, - name: "angular-cms" + name: 'angular-cms' }, api: { - url: "", - endpoint: "/api/", - version: "v2", - versions: ["v1", "v2"] + url: '', + endpoint: '/api/', + version: 'v2', + versions: ['v1', 'v2'] }, live: false, debug: true, - version: "0.0.1", - formFactor: "desktop", + version: '0.0.1', + formFactor: 'desktop', currentOrientation: null, - cdn: "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", + cdn: 'http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms', cdns: { - http: "http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms", - https: "https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms", - streaming: "http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms" + http: 'http://a481ab4f6ea4dd65cff0-b2b68ced242ecf1cb9bc1021688e3775.r49.cf1.rackcdn.com/angular-cms', + https: 'https://4ac535c4a3d1d3359bbc-b2b68ced242ecf1cb9bc1021688e3775.ssl.cf1.rackcdn.com/angular-cms', + streaming: 'http://df86ce1cf0cf1f552fe2-b2b68ced242ecf1cb9bc1021688e3775.r49.stream.cf1.rackcdn.com/angular-cms' } }, options: { layouts: [ { id: 0, - name: "Fixed", - value: "container" + name: 'Fixed', + value: 'container' }, { id: 1, - name: "Fluid", - value: "container-fluid" + name: 'Fluid', + value: 'container-fluid' } ], sidebars: [ { id: 1, - name: "Default", - value: "sidebar", - url: "/views/partials/sidebar.html" + name: 'Default', + value: 'sidebar', + url: '/views/partials/sidebar.html' } ], navbars: [ { id: 1, - name: "Default", - value: "navbar", - url: "/views/partials/navbar.html" + name: 'Default', + value: 'navbar', + url: '/views/partials/navbar.html' } ], backgrounds: [ { id: 0, - title: "Default" + title: 'Default' } ], - themes: ["Default", "Amelia", "Cerulean", "Cosmo", "Cyborg", "Flatly", "Journal", "Readable", "Simplex", "Slate", "Spacelab", "United", "Yeti"] + themes: ['Default', 'Amelia', 'Cerulean', 'Cosmo', 'Cyborg', 'Flatly', 'Journal', 'Readable', 'Simplex', 'Slate', 'Spacelab', 'United', 'Yeti'] }, logout: { - redirect: "#/login", - message: "Good bye..." + redirect: '#/login', + message: 'Good bye...' }, login: { - logo: "https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png", - redirect: "/#/home", + logo: 'https://7fd8f70e662929940bdd-79dc9bd5ca0b6e6cb6f16ffd7b1e05e2.ssl.cf1.rackcdn.com/img/logo-login-med.png', + redirect: '/#/home', user: { - username: "", - password: "" + username: '', + password: '' }, - message: "Welcome {{user.username}}" + message: 'Welcome {{user.username}}' }, server: { - host: "http://localhost", + host: 'http://localhost', port: 8181, - apiBase: "/api/v2", - version: "v2", + apiBase: '/api/v2', + version: 'v2', security: { - salt: "angular-cms" + salt: 'angular-cms' }, - mongodb: "angularcms:angularcms@paulo.mongohq.com:10089/app19632340", + mongodb: 'angularcms:angularcms@paulo.mongohq.com:10089/app19632340', db: { - name: "angular-cms", - username: "amadmin", - password: "fred", - host: "localhost", + name: 'angular-cms', + username: 'amadmin', + password: 'fred', + host: 'localhost', port: 27017 }, email: { - username: "angular.cms@gmail.com", - password: "isyourdaughter18?" + username: 'angular.cms@gmail.com', + password: 'isyourdaughter18?' }, proxy: { - hostname: "localhost", + hostname: 'localhost', port: 5001 }, - staticDir: "www", - publicDir: "www", - uploadsTmpDir: ".tmp", - uploadsDestDir: "www/cms-content/uploads", - uploadsUrl: ":8181/cms-content/", - logFormat: "[:date] - [:method] - :url - :status - :response-time ms" + staticDir: 'www', + publicDir: 'www', + uploadsTmpDir: '.tmp', + uploadsDestDir: 'www/cms-content/uploads', + uploadsUrl: ':8181/cms-content/', + logFormat: '[:date] - [:method] - :url - :status - :response-time ms' } }; diff --git a/app/scripts/controllers/admin.js b/app/scripts/controllers/admin.js index c07ebb7..603255d 100644 --- a/app/scripts/controllers/admin.js +++ b/app/scripts/controllers/admin.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('AdminCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/dashboard.js b/app/scripts/controllers/dashboard.js index a026bb2..5e30648 100644 --- a/app/scripts/controllers/dashboard.js +++ b/app/scripts/controllers/dashboard.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('angularCmsApp').controller('DashboardCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; - return $scope.fullscreen = function() { + $scope.fullscreen = function() { var i; i = document.getElementById("dashboard"); if (i.requestFullscreen) { diff --git a/app/scripts/controllers/docs.js b/app/scripts/controllers/docs.js index 9a1b814..807ce9b 100644 --- a/app/scripts/controllers/docs.js +++ b/app/scripts/controllers/docs.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('DocsCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/forgot-password.js b/app/scripts/controllers/forgot-password.js index 5bdff39..44448f6 100644 --- a/app/scripts/controllers/forgot-password.js +++ b/app/scripts/controllers/forgot-password.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('angularCmsApp').controller('ForgotPasswordCtrl', function($scope) { - return $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; + $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; }); diff --git a/app/scripts/controllers/help.js b/app/scripts/controllers/help.js index 28a108c..533cb5e 100644 --- a/app/scripts/controllers/help.js +++ b/app/scripts/controllers/help.js @@ -1,13 +1,7 @@ 'use strict'; -angular.module('angularCmsApp').controller('HelpCtrl', function($scope, $http) { +angular.module('angularCmsApp').controller('HelpCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; $scope.readmeEl = angular.element('#readme'); - return $scope.loadReadme = function() { - - /* - $http.get('/api/v2/README').success((data) -> - $scope.readmeEl.html(data) - ) - */ + $scope.loadReadme = function() { }; }); diff --git a/app/scripts/controllers/login.js b/app/scripts/controllers/login.js index 8d4e746..7aef9db 100644 --- a/app/scripts/controllers/login.js +++ b/app/scripts/controllers/login.js @@ -9,7 +9,6 @@ angular.module('angularCmsApp').controller('LoginCtrl', function($scope, $rootSc password: null, remember: false }; - /** login - This functionality should be moved into the session service that handles setting the session and changing the location of the page. @@ -17,36 +16,8 @@ angular.module('angularCmsApp').controller('LoginCtrl', function($scope, $rootSc $scope.login = function(u) { return cmsAuthService.login(u); }; - - /* - Login Method to set the session. - @param {Object} user - A user model containing username and password - - $scope._login = (u) -> - console.log(u) - Parse.User.logIn u.username, u.password, - success: (user) -> - console.log user - $scope.$apply(()-> - *Set user session - session = - user: user.attributes - authorized: true - - console.log('save sessin', session) - *Set user cookie - $cookieStore.put('App.session', session) if u.remember - $rootScope.App.session = session - *Change location - $rootScope.App.location.path('/dashboard') - ) - error: (user, error) -> - $scope.$apply(()-> - $scope.error = error; - ) - */ $scope.logout = function(user) { return cmsAuthService.logout(user); }; - return $scope.name = 'login'; + $scope.name = 'login'; }); diff --git a/app/scripts/controllers/pages.js b/app/scripts/controllers/pages.js index 2b4fbbe..19b04ff 100644 --- a/app/scripts/controllers/pages.js +++ b/app/scripts/controllers/pages.js @@ -22,7 +22,7 @@ angular.module('angularCmsApp').controller('PagesCtrl', function($scope, $log, p return DataService.save('pages', p).then(function(res) { $scope.getPages(); $scope.page = {}; - cmsNotify('.alerts', 'success', 'Success!', "Page Update.", 5000); + cmsNotify('.alerts', 'success', 'Success!', 'Page Update.', 5000); return $log.info(res); }); }; @@ -33,80 +33,80 @@ angular.module('angularCmsApp').controller('PagesCtrl', function($scope, $log, p }); }; return $scope.pageSchema = { - "fields": [ + 'fields': [ { - "type": "text", - "name": "title", - "displayName": "Title:", - "validation": { - "messages": {}, - "required": true, - "minlength": 2, - "maxlength": 18 + 'type': 'text', + 'name': 'title', + 'displayName': 'Title:', + 'validation': { + 'messages': {}, + 'required': true, + 'minlength': 2, + 'maxlength': 18 }, - "placeholder": "Enter title here", - "tooltip": "Enter the page title here" + 'placeholder': 'Enter title here', + 'tooltip': 'Enter the page title here' }, { - "type": "selectlist", - "name": "parent", - "displayName": "Parent:", - "options": [ + 'type': 'selectlist', + 'name': 'parent', + 'displayName': 'Parent:', + 'options': [ { - "value": "1", - "text": "Option 1" + 'value': '1', + 'text': 'Option 1' }, { - "value": "2", - "text": "Option 2" + 'value': '2', + 'text': 'Option 2' }, { - "value": "3", - "text": "Option 3" + 'value': '3', + 'text': 'Option 3' } ], - "value": "1" + 'value': '1' }, { - "type": "selectlist", - "name": "template", - "displayName": "Template:", - "options": [ + 'type': 'selectlist', + 'name': 'template', + 'displayName': 'Template:', + 'options': [ { - "value": "1", - "text": "Option 1" + 'value': '1', + 'text': 'Option 1' }, { - "value": "2", - "text": "Option 2" + 'value': '2', + 'text': 'Option 2' }, { - "value": "3", - "text": "Option 3" + 'value': '3', + 'text': 'Option 3' } ], - "value": "1" + 'value': '1' }, { - "type": "textarea", - "name": "body", - "displayName": "Body:", - "validation": { - "messages": {} + 'type': 'textarea', + 'name': 'body', + 'displayName': 'Body:', + 'validation': { + 'messages': {} }, - "placeholder": "Enter body here", - "tooltip": "Enter page body here" + 'placeholder': 'Enter body here', + 'tooltip': 'Enter page body here' }, { - "type": "checkboxlist", - "name": "status", - "displayName": "Status:", - "options": [ + 'type': 'checkboxlist', + 'name': 'status', + 'displayName': 'Status:', + 'options': [ { - "value": "published", - "text": "Published" + 'value': 'published', + 'text': 'Published' }, { - "value": "draft", - "text": "Draft" + 'value': 'draft', + 'text': 'Draft' }, { - "value": "private", - "text": "Private" + 'value': 'private', + 'text': 'Private' } ], - "value": "draft", - "tooltip": "Select the page status" + 'value': 'draft', + 'tooltip': 'Select the page status' } ] }; diff --git a/app/scripts/controllers/plugins.js b/app/scripts/controllers/plugins.js index 2b0adf6..8c3564e 100644 --- a/app/scripts/controllers/plugins.js +++ b/app/scripts/controllers/plugins.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('angularCmsApp').controller('PluginsCtrl', function($scope) { $scope.awesomeThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma']; - return $scope.plugins = [ + $scope.plugins = [ { id: 1, title: 'Google Chart Widgets', diff --git a/app/scripts/controllers/settings.js b/app/scripts/controllers/settings.js index 61859c2..1036e4b 100644 --- a/app/scripts/controllers/settings.js +++ b/app/scripts/controllers/settings.js @@ -16,65 +16,65 @@ angular.module('angularCmsApp').controller('SettingsCtrl', function($scope, mySc ]; }); -angular.module('angularCmsApp').value("mySchema", { +angular.module('angularCmsApp').value('mySchema', { fields: [ { - type: "text", - name: "firstName", - displayName: "First name", + type: 'text', + name: 'firstName', + displayName: 'First name', validation: { messages: {}, required: true }, - placeholder: "Enter your first name here", - tooltip: "Enter your first name here" + placeholder: 'Enter your first name here', + tooltip: 'Enter your first name here' }, { - type: "text", - name: "lastName", - displayName: "Last name", + type: 'text', + name: 'lastName', + displayName: 'Last name', validation: { messages: {}, required: true }, - placeholder: "Enter your last name here", - tooltip: "Enter your last name here" + placeholder: 'Enter your last name here', + tooltip: 'Enter your last name here' }, { - type: "radiobuttonlist", - name: "sex", - displayName: "Sex", + type: 'radiobuttonlist', + name: 'sex', + displayName: 'Sex', options: [ { - value: "male", - text: "Male" + value: 'male', + text: 'Male' }, { - value: "female", - text: "Female" + value: 'female', + text: 'Female' } ], - value: "male" + value: 'male' }, { - type: "email", - name: "email", - displayName: "Email", + type: 'email', + name: 'email', + displayName: 'Email', validation: { messages: {} }, - placeholder: "Enter your email address here", - tooltip: "Enter your email address here" + placeholder: 'Enter your email address here', + tooltip: 'Enter your email address here' }, { - type: "checkboxlist", - name: "color", - displayName: "Colors", + type: 'checkboxlist', + name: 'color', + displayName: 'Colors', options: [ { - value: "red", - text: "Red" + value: 'red', + text: 'Red' }, { - value: "blue", - text: "Blue" + value: 'blue', + text: 'Blue' }, { - value: "green", - text: "Green" + value: 'green', + text: 'Green' } ], value: {} diff --git a/app/scripts/directives/cms-formgroup.js b/app/scripts/directives/cms-formgroup.js index 845d941..89b952e 100644 --- a/app/scripts/directives/cms-formgroup.js +++ b/app/scripts/directives/cms-formgroup.js @@ -4,11 +4,11 @@ @name angularCmsApp.directive:cmsFormGroup @element div @function - + @description Resize textarea automatically to the size of its text content. **Note:** ie<9 needs pollyfill for window.getComputedStyle - + @example @@ -20,7 +20,7 @@ 'use strict'; angular.module('angularCmsApp').directive('cmsFormGroup', function() { return { - template: "
\n \n
\n
\n
", + template: '
', restrict: 'E', replace: true, transclude: true, @@ -29,6 +29,7 @@ angular.module('angularCmsApp').directive('cmsFormGroup', function() { hint: '@' }, link: function(scope, element, attrs) { + console.log(attrs); return element.find('input').addClass('form-control'); } }; diff --git a/app/scripts/directives/cms-gravatar.js b/app/scripts/directives/cms-gravatar.js index 7949aa9..678baaa 100644 --- a/app/scripts/directives/cms-gravatar.js +++ b/app/scripts/directives/cms-gravatar.js @@ -4,12 +4,12 @@ @name angularCmsApp.directive:cmsGravatar @element div @function - + @description This is a Gravatar directive for displaying an image by a users email address. @example - + HTML example come here ==> `
` @@ -25,7 +25,7 @@ angular.module('angularCmsApp').directive('cmsGravatar', function() { scope: { email: '@' }, - link: function(scope, element, attrs) { + link: function(scope, element) { return element.text('this is the cmsGravatar directive'); } }; diff --git a/app/scripts/services/cmssocketservice.js b/app/scripts/services/cmssocketservice.js index d9710ad..3c322e3 100644 --- a/app/scripts/services/cmssocketservice.js +++ b/app/scripts/services/cmssocketservice.js @@ -23,7 +23,7 @@ angular.module('angularCmsApp').service('cmsSocketService', function() { return console.log(e); }; _ws.onopen = function(e) { - _ws.send("update"); + _ws.send('update'); }; return { instance: _ws, diff --git a/app/scripts/services/dataservice.js b/app/scripts/services/dataservice.js index 7951352..3c255c0 100644 --- a/app/scripts/services/dataservice.js +++ b/app/scripts/services/dataservice.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('angularCmsApp').service('DataService', [ - '$http', '$q', '$resource', function($http, $q, $resource) { + '$http', '$q', '$resource', function($http) { var DataService; DataService = { endpoint: '/api/v2/angular-cms', @@ -17,10 +17,10 @@ angular.module('angularCmsApp').service('DataService', [ return $http(defaults); }, fetch: function(collection, params) { - return this.request("/" + collection, 'GET', params); + return this.request('/' + collection, 'GET', params); }, get: function(collection, id, params) { - return this.request("/" + collection + "/" + id, 'GET', params); + return this.request('/' + collection + '/' + id, 'GET', params); }, save: function(collection, data) { if (data._id) { @@ -30,13 +30,13 @@ angular.module('angularCmsApp').service('DataService', [ } }, destroy: function(collection, data) { - return this.request("/" + collection + "/" + data._id, 'DELETE'); + return this.request('/' + collection + '/' + data._id, 'DELETE'); }, _create: function(collection, data) { - return this.request("/" + collection, 'POST', null, data); + return this.request('/' + collection, 'POST', null, data); }, _update: function(collection, data) { - return this.request("/" + collection + "/" + data._id, 'PUT', null, data); + return this.request('/' + collection + '/' + data._id, 'PUT', null, data); } }; return DataService; diff --git a/routes/cms-auth.js b/routes/cms-auth.js index 554f0d5..520ce11 100644 --- a/routes/cms-auth.js +++ b/routes/cms-auth.js @@ -1,16 +1,14 @@ -var bodyParser = require( 'body-parser' ), - mongoose = require( 'mongoose' ), +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' ); - + User = require('./models/user'), + session = require('express-session'), + crypto = require('crypto'), + bcrypt = require('bcrypt-nodejs'); var cmsAuth = function (config, app) { - console.warn( 'cms-auth' ); - + console.warn('cms-auth'); //### hashPassword @@ -35,23 +33,23 @@ var cmsAuth = function (config, app) { if (req.body.email) { query.username = req.body.email; } - query.password = hashPassword( req.body.password, query.username ); + query.password = hashPassword(req.body.password, query.username); console.warn('trying to login', query); - User.findOne( {username: query.username}, function (err, data) { + User.findOne({username: query.username}, function (err, data) { if (err) { - return res.jsonp( 400, err ); + return res.jsonp(400, err); } try { if (data && bcrypt.compareSync(req.body.password, data.password)) { req.session.user = data; - return res.json( 200, data ); + return res.json(200, data); } else { - return res.json( 404, {message: 'Wrong username/password!'} ); + return res.json(404, {message: 'Wrong username/password!'}); } } catch (error) { - return res.json( 404, {message: error} ); + return res.json(404, {message: error}); } - } ); + }); }, /** * Handle registering a new user @@ -70,7 +68,7 @@ var cmsAuth = function (config, app) { data.email = req.body.email; } - data.password = hashPassword( req.body.password, data.username ); + data.password = hashPassword(req.body.password, data.username); data.created_at = new Date(); data.updated_at = new Date(); data.active = false; @@ -79,32 +77,31 @@ var cmsAuth = function (config, app) { console.warn('trying to register', data); - //Try and find user - User.find( {username: data.username}, function (err, u) { - console.log( 'found user', err, util.inspect(u, {colors: true})); - var user = new User( data ); - if(err){ - res.jsonp( 400, {message: 'Problem registering!'} ); + User.find({username: data.username}, function (err, u) { + console.log('found user', err, util.inspect(u, {colors: true})); + var user = new User(data); + if (err) { + res.jsonp(400, {message: 'Problem registering!'}); } if (u.length) { - res.jsonp( 400, {message: 'Username already exists!'} ); + res.jsonp(400, {message: 'Username already exists!'}); } else { - user.save( function (er, ok) { + user.save(function (er, ok) { if (er) { - return res.jsonp( 400, {message: 'Problem registering!'} ); + return res.jsonp(400, {message: 'Problem registering!'}); } else { - return res.jsonp( 201, ok ); + return res.jsonp(201, ok); } - } ); + }); } - } ); + }); }, session: function (req, res, next) { var user = req.session; - if(req.session && req.session.user){ + if (req.session && req.session.user) { user = req.session.user } console.warn(util.inspect(user, {colors: true})); @@ -113,15 +110,15 @@ var cmsAuth = function (config, app) { }; //Always users table - app.use( session( { + app.use(session({ secret: 'angular-cms', resave: true, saveUninitialized: true - } ) ); - app.get( config.apiBase + '/login', bodyParser.json(), cmsAuth.login ); - app.post( config.apiBase + '/login', bodyParser.json(), cmsAuth.login ); - app.post( config.apiBase + '/register', bodyParser.json(), cmsAuth.register ); - app.get( config.apiBase + '/session', bodyParser.json(), cmsAuth.session ); + })); + app.get(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); + app.post(config.apiBase + '/login', bodyParser.json(), cmsAuth.login); + app.post(config.apiBase + '/register', bodyParser.json(), cmsAuth.register); + app.get(config.apiBase + '/session', bodyParser.json(), cmsAuth.session); }; module.exports = cmsAuth; diff --git a/routes/cms-passport.js b/routes/cms-passport.js index 3e69655..b4a51aa 100644 --- a/routes/cms-passport.js +++ b/routes/cms-passport.js @@ -38,7 +38,7 @@ var ensureAuthenticated = function (req, res, next) { */ var cmsPassport = function (config, app) { -var user = new User(); + var user = new User(); if (!app) { throw new Error('Must provide express application!'); @@ -46,20 +46,22 @@ var user = new User(); /* - */ - var findOrCreate = function(u, done){ + */ + var findOrCreate = function (u, done) { console.log('find', u); for (var i = 0; i < u.emails.length; i++) { var email = u.emails[i].value - User.findOne({ email: email }, function (err, user) { - if (err) { return done(err); } + User.findOne({email: email}, function (err, user) { + if (err) { + return done(err); + } if (!user) { console.warn('create user', u); return done(null, false); } - return done(null, user); - }); + return done(null, user); + }); } }; @@ -88,15 +90,21 @@ var user = new User(); passport.deserializeUser(deserializeUser); -var strategy = function(username, password, done) { - console.warn('find user', username, password); - User.findOne({ username: username }, function (err, user) { - if (err) { return done(err); } - if (!user) { return done(null, false); } - if (!user.validPassword(password)) { return done(null, false); } - return done(null, user); - }); - }; + var strategy = function (username, password, done) { + console.warn('find user', username, password); + User.findOne({username: username}, function (err, user) { + if (err) { + return done(err); + } + if (!user) { + return done(null, false); + } + if (!user.validPassword(password)) { + return done(null, false); + } + return done(null, user); + }); + }; passport.use(new BasicStrategy(strategy)); passport.use(new LocalStrategy(strategy)); diff --git a/test/routes/cms-passport-spec.js b/test/routes/cms-passport-spec.js index 88f2972..1530e9f 100644 --- a/test/routes/cms-passport-spec.js +++ b/test/routes/cms-passport-spec.js @@ -36,7 +36,7 @@ define([ this.skip(); }, 'POST - /register - should return user on successful registration': function () { - this.skip(); + var dfd = this.async(); request(app) .post('/auth/register') @@ -49,7 +49,8 @@ define([ "name": "Jonnie Dollas" } }) - .expect("Content-Type", /json/) + .set('Accept', 'application/json') + .expect('Content-Type', /json/) .expect(201, dfd.resolve()); }, 'POST - /login - should return user on successful login': function () { @@ -61,7 +62,8 @@ define([ request(app) .post('/auth/login') .send(validUser) - .expect("Content-Type", /json/) + .set('Accept', 'application/json') + .expect('Content-Type', /json/) .expect(200) .end(function(err, res){ if (err) {throw err;} diff --git a/test/spec/services/dataservice.js b/test/spec/services/dataservice.js index eba6b0b..3d5a407 100644 --- a/test/spec/services/dataservice.js +++ b/test/spec/services/dataservice.js @@ -101,7 +101,7 @@ describe('Service: DataService', function() { expect(successCallback).toHaveBeenCalled(); return expect(errorCallback).not.toHaveBeenCalled(); }); - return it('DELETE - /collection/id - should reject promise on error', function() { + it('DELETE - /collection/id - should reject promise on error', function() { $httpBackend.expectDELETE("" + baseUrl + "/posts/1").respond(404, { message: 'Error deleting object' });