From 3aa913e8c0550ca684311bf6123d055d2351a224 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 14 Apr 2015 02:53:54 +0000 Subject: [PATCH] cleanup --- .gitignore | 3 +- bin/wdiff | Bin 62 -> 14 bytes client/app/app.js | 38 ----- client/components/auth/auth.service.js | 146 ------------------ client/components/auth/user.service.js | 22 --- client/components/navbar/navbar.controller.js | 7 +- client/index.html | 2 - .../api/comparison/comparison.controller.js | 1 - 8 files changed, 7 insertions(+), 212 deletions(-) delete mode 100644 client/components/auth/auth.service.js delete mode 100644 client/components/auth/user.service.js diff --git a/.gitignore b/.gitignore index 46a00f5..3251f27 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +bin node_modules public .tmp @@ -5,5 +6,5 @@ public .idea client/bower_components dist -/server/config/local.env.js +server/config/local.env.js wdiff-1.2.2 diff --git a/bin/wdiff b/bin/wdiff index 86321c0bd99eeb3f4f43bd263e0923fbd222725b..084566395a520ea1c96ae0e502c159e3ab18464c 120000 GIT binary patch literal 14 VcmdNdEiTee%FNR*PsvP60{|u01u*~s literal 62 zcmY$iDXz@T$;`{P`~OdmL61S7p`0OwA(J5u2z40@fg(m=tj|!)P{fdoBG1480P;W$ A4*&oF diff --git a/client/app/app.js b/client/app/app.js index ff25ee9..ed887e2 100644 --- a/client/app/app.js +++ b/client/app/app.js @@ -15,42 +15,4 @@ angular.module('markdownFormatWdiffApp', [ }); $locationProvider.html5Mode(true); - $httpProvider.interceptors.push('authInterceptor'); }) - - .factory('authInterceptor', function ($rootScope, $q, $cookieStore, $location) { - return { - // Add authorization token to headers - request: function (config) { - config.headers = config.headers || {}; - if ($cookieStore.get('token')) { - config.headers.Authorization = 'Bearer ' + $cookieStore.get('token'); - } - return config; - }, - - // Intercept 401s and redirect you to login - responseError: function(response) { - if(response.status === 401) { - $location.path('/login'); - // remove any stale tokens - $cookieStore.remove('token'); - return $q.reject(response); - } - else { - return $q.reject(response); - } - } - }; - }) - - .run(function ($rootScope, $location, Auth) { - // Redirect to login if route requires auth and you're not logged in - $rootScope.$on('$routeChangeStart', function (event, next) { - Auth.isLoggedInAsync(function(loggedIn) { - if (next.authenticate && !loggedIn) { - $location.path('/login'); - } - }); - }); - }); diff --git a/client/components/auth/auth.service.js b/client/components/auth/auth.service.js deleted file mode 100644 index 0d1a79c..0000000 --- a/client/components/auth/auth.service.js +++ /dev/null @@ -1,146 +0,0 @@ -'use strict'; - -angular.module('markdownFormatWdiffApp') - .factory('Auth', function Auth($location, $rootScope, $http, User, $cookieStore, $q) { - var currentUser = {}; - if($cookieStore.get('token')) { - currentUser = User.get(); - } - - return { - - /** - * Authenticate user and save token - * - * @param {Object} user - login info - * @param {Function} callback - optional - * @return {Promise} - */ - login: function(user, callback) { - var cb = callback || angular.noop; - var deferred = $q.defer(); - - $http.post('/auth/local', { - email: user.email, - password: user.password - }). - success(function(data) { - $cookieStore.put('token', data.token); - currentUser = User.get(); - deferred.resolve(data); - return cb(); - }). - error(function(err) { - this.logout(); - deferred.reject(err); - return cb(err); - }.bind(this)); - - return deferred.promise; - }, - - /** - * Delete access token and user info - * - * @param {Function} - */ - logout: function() { - $cookieStore.remove('token'); - currentUser = {}; - }, - - /** - * Create a new user - * - * @param {Object} user - user info - * @param {Function} callback - optional - * @return {Promise} - */ - createUser: function(user, callback) { - var cb = callback || angular.noop; - - return User.save(user, - function(data) { - $cookieStore.put('token', data.token); - currentUser = User.get(); - return cb(user); - }, - function(err) { - this.logout(); - return cb(err); - }.bind(this)).$promise; - }, - - /** - * Change password - * - * @param {String} oldPassword - * @param {String} newPassword - * @param {Function} callback - optional - * @return {Promise} - */ - changePassword: function(oldPassword, newPassword, callback) { - var cb = callback || angular.noop; - - return User.changePassword({ id: currentUser._id }, { - oldPassword: oldPassword, - newPassword: newPassword - }, function(user) { - return cb(user); - }, function(err) { - return cb(err); - }).$promise; - }, - - /** - * Gets all available info on authenticated user - * - * @return {Object} user - */ - getCurrentUser: function() { - return currentUser; - }, - - /** - * Check if a user is logged in - * - * @return {Boolean} - */ - isLoggedIn: function() { - return currentUser.hasOwnProperty('role'); - }, - - /** - * Waits for currentUser to resolve before checking if user is logged in - */ - isLoggedInAsync: function(cb) { - if(currentUser.hasOwnProperty('$promise')) { - currentUser.$promise.then(function() { - cb(true); - }).catch(function() { - cb(false); - }); - } else if(currentUser.hasOwnProperty('role')) { - cb(true); - } else { - cb(false); - } - }, - - /** - * Check if a user is an admin - * - * @return {Boolean} - */ - isAdmin: function() { - return currentUser.role === 'admin'; - }, - - /** - * Get auth token - */ - getToken: function() { - return $cookieStore.get('token'); - } - }; - }); diff --git a/client/components/auth/user.service.js b/client/components/auth/user.service.js deleted file mode 100644 index 5641abe..0000000 --- a/client/components/auth/user.service.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -angular.module('markdownFormatWdiffApp') - .factory('User', function ($resource) { - return $resource('/api/users/:id/:controller', { - id: '@_id' - }, - { - changePassword: { - method: 'PUT', - params: { - controller:'password' - } - }, - get: { - method: 'GET', - params: { - id:'me' - } - } - }); - }); diff --git a/client/components/navbar/navbar.controller.js b/client/components/navbar/navbar.controller.js index 8569095..87f3782 100644 --- a/client/components/navbar/navbar.controller.js +++ b/client/components/navbar/navbar.controller.js @@ -1,13 +1,15 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('NavbarCtrl', function ($scope, $location, Auth) { + .controller('NavbarCtrl', function ($scope, $location , /*Auth*/) { $scope.menu = [{ 'title': 'Home', 'link': '/' }]; $scope.isCollapsed = true; + + /* $scope.isLoggedIn = Auth.isLoggedIn; $scope.isAdmin = Auth.isAdmin; $scope.getCurrentUser = Auth.getCurrentUser; @@ -16,8 +18,9 @@ angular.module('markdownFormatWdiffApp') Auth.logout(); $location.path('/login'); }; + */ $scope.isActive = function(route) { return route === $location.path(); }; - }); \ No newline at end of file + }); diff --git a/client/index.html b/client/index.html index cc9ad68..f39c098 100644 --- a/client/index.html +++ b/client/index.html @@ -65,8 +65,6 @@ - - diff --git a/server/api/comparison/comparison.controller.js b/server/api/comparison/comparison.controller.js index 55af56f..f1867dc 100644 --- a/server/api/comparison/comparison.controller.js +++ b/server/api/comparison/comparison.controller.js @@ -27,7 +27,6 @@ exports.wdiffMarkdownComparison = function wdiffMarkdownComparison(req, res) { return handleError(res, err); _.merge(result, comparison._doc) - console.log(result); return res.json(result); }); });