From c07a9ba267e28f33facdd1bb38844c22e9802185 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Mon, 6 Jul 2015 18:56:38 -0700 Subject: [PATCH] fixed logout redirection issue --- app/controllers/forms.server.controller.js | 11 ++++----- .../users.authentication.server.controller.js | 1 + app/routes/forms.server.routes.js | 2 +- public/application.js | 15 ++++++------ .../controllers/header.client.controller.js | 17 ++++++++------ .../controllers/home.client.controller.js | 6 ++--- public/modules/core/css/core.css | 23 ++++++++++++------- .../modules/core/views/home.client.view.html | 2 +- public/modules/users/services/auth.js | 5 ++-- .../authentication/signin.client.view.html | 2 +- .../authentication/signup.client.view.html | 2 ++ 11 files changed, 49 insertions(+), 37 deletions(-) diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index c86bcf9a..87692c5b 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -50,7 +50,7 @@ exports.uploadPDF = function(req, res, next) { } pdfFile.path = path.join(newDestination, pdfFile.name); console.log(pdfFile.name + ' uploaded to ' + pdfFile.path); - res.status(200).send(pdfFile); + res.status(200).send('pdf file successfully uploaded'); }); } else { @@ -79,7 +79,7 @@ exports.createSubmission = function(req, res) { submission.form_fields = req.body.form_fields; submission.title = req.body.title; submission.timeElapsed = req.body.timeElapsed; - console.log(req.body); + // console.log(req.body);s // submission.ipAddr = req.headers['x-forwarded-for'] || req.connection.remoteAddress; if(form.autofillPDFs){ @@ -150,7 +150,7 @@ exports.listSubmissions = function(req, res) { } else { // _form.submissions = _submissions; _form.update({ $set : { submissions: _submissions }}); - + res.status(200); } }); // } @@ -173,7 +173,7 @@ exports.create = function(req, res) { message: errorHandler.getErrorMessage(err) }); } else { - res.json(form); + res.status(200).send('form created'); } }); }; @@ -204,7 +204,6 @@ exports.update = function(req, res) { }); } else { console.log('updated form'); - // res.json(form); res.status(200).send('updated form'); } }); @@ -236,7 +235,7 @@ exports.list = function(req, res) { var searchObj = {admin: req.user}; if(req.user.isAdmin()) searchObj = {}; - Form.find({}).sort('-created').populate('admin').exec(function(err, forms) { + Form.find(searchObj).sort('-created').populate('admin.username', 'admin._id').exec(function(err, forms) { if (err) { res.status(400).send({ message: errorHandler.getErrorMessage(err) diff --git a/app/controllers/users/users.authentication.server.controller.js b/app/controllers/users/users.authentication.server.controller.js index d34642b5..0718d3f0 100755 --- a/app/controllers/users/users.authentication.server.controller.js +++ b/app/controllers/users/users.authentication.server.controller.js @@ -74,6 +74,7 @@ exports.signin = function(req, res, next) { */ exports.signout = function(req, res) { req.logout(); + // res.status(200).send('user successfully logged out'); res.redirect('/'); }; diff --git a/app/routes/forms.server.routes.js b/app/routes/forms.server.routes.js index 57918443..ef80ccb6 100644 --- a/app/routes/forms.server.routes.js +++ b/app/routes/forms.server.routes.js @@ -17,7 +17,7 @@ module.exports = function(app) { app.route('/forms/:formId([a-zA-Z0-9]+)') .get(forms.read) - // .post(forms.createSubmission) + .post(forms.createSubmission) .put(users.requiresLogin, forms.hasAuthorization, forms.update) .delete(users.requiresLogin, forms.hasAuthorization, forms.delete); diff --git a/public/application.js b/public/application.js index f31ecd63..3d6ea9fe 100755 --- a/public/application.js +++ b/public/application.js @@ -11,13 +11,6 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio ]); angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) { - // $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { - // // track the state the user wants to go to; authorization service needs this - // $rootScope.toState = toState; - // $rootScope.toStateParams = toStateParams; - // // if the principal is resolved, do an authorization check immediately. otherwise, - // // it'll be done when the state it resolved. - // }); $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; @@ -25,6 +18,14 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope' // add previous state property $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) { $state.previous = fromState; + + //Redirect home to listForms if user is authenticated + if(toState.name === 'home'){ + if($rootScope.authentication.isAuthenticated()){ + event.preventDefault(); // stop current execution + $state.go('listForms'); // go to login + } + } }); } diff --git a/public/modules/core/controllers/header.client.controller.js b/public/modules/core/controllers/header.client.controller.js index 570efb84..85cf0c2b 100755 --- a/public/modules/core/controllers/header.client.controller.js +++ b/public/modules/core/controllers/header.client.controller.js @@ -5,19 +5,22 @@ angular.module('core').controller('HeaderController', ['$rootScope','$scope','Me $scope.user = $rootScope.user = Auth.ensureHasCurrentUser(User); $scope.authentication = $rootScope.authentication = Auth; $rootScope.languages = $scope.languages = ['english', 'french', 'spanish']; - // console.log('isAuthenticated(): '+$scope.authentication.isAuthenticated()); $scope.isCollapsed = false; $scope.hideNav = false; $scope.menu = Menus.getMenu('topbar'); - $scope.signout = function() { - User.logout(function() { - Auth.logout(); - $rootScope.user = null; - $state.go('home'); - }); + var promise = User.logout(); + promise.then(function() { + Auth.logout(); + // Auth.ensureHasCurrentUser(null); + $rootScope.user = null; + $state.go('home'); + }, + function(reason) { + console.log('Logout Failed: ' + reason); + }); }; $scope.toggleCollapsibleMenu = function() { diff --git a/public/modules/core/controllers/home.client.controller.js b/public/modules/core/controllers/home.client.controller.js index 2bd3cbdd..4f7ced9d 100755 --- a/public/modules/core/controllers/home.client.controller.js +++ b/public/modules/core/controllers/home.client.controller.js @@ -8,9 +8,9 @@ angular.module('core').controller('HomeController', ['$rootScope', '$scope', 'Us $scope.user = Auth.ensureHasCurrentUser(User); $scope.authentication = Auth; - if($scope.authentication.isAuthenticated()){ - $state.go('listForms'); - } + // if($scope.authentication.isAuthenticated()){ + // $state.go('listForms'); + // } } ]); \ No newline at end of file diff --git a/public/modules/core/css/core.css b/public/modules/core/css/core.css index 9c6725d3..7e55b97f 100755 --- a/public/modules/core/css/core.css +++ b/public/modules/core/css/core.css @@ -3,14 +3,10 @@ background-color:#fafafa; border: 0; } -.navbar-inverse .navbar-nav > .active > a, .navbar-inverse .navbar-nav > .active > a:hover { - /*background-color:#ddd;*/ -} .navbar .navbar-brand { font-size: 1.6em; font-weight: 900; - /*color: #FA787E;*/ - color: rgb(300,131,131); + color: rgb(255,131,131); } .navbar .navbar-brand:hover, .navbar .navbar-brand:visited { color: #FA787E; @@ -64,7 +60,7 @@ section.hero-section .jumbotron { position: absolute; top: 0; left: 0; - height: 110%; + height: 230%; width: 100%; z-index: -98; background-image: url(http://yourplaceandmine.ie/wp-content/uploads/2014/09/Daingean-meeting-048_13-1080x675.jpg); @@ -77,8 +73,19 @@ section.hero-section .jumbotron { position: absolute; top: 0; left: 0; - height: 110%; + height: 230%; width: 100%; background-color: rgba(0,0,0,0.5); z-index: -97; - } \ No newline at end of file + } + + section.hero-section .jumbotron .signup-btn { + background-color:#FA787E; + border: none; + font-size: 2em; + padding: 0.3em 0.9em; + color: white; + } + section.hero-section .jumbotron .signup-btn { + background-color:rgba(250, 120, 126, 0.65) #FA787E; + } diff --git a/public/modules/core/views/home.client.view.html b/public/modules/core/views/home.client.view.html index 2b851228..b6517bda 100755 --- a/public/modules/core/views/home.client.view.html +++ b/public/modules/core/views/home.client.view.html @@ -30,7 +30,7 @@
- +
diff --git a/public/modules/users/services/auth.js b/public/modules/users/services/auth.js index 7f18acaa..a60aa595 100644 --- a/public/modules/users/services/auth.js +++ b/public/modules/users/services/auth.js @@ -15,8 +15,8 @@ angular.module('users') // Auth <- $http <- $resource <- LoopBackResource <- User <- Auth ensureHasCurrentUser: function(User) { if (service.currentUser && service.currentUser.displayName) { - console.log('Using local current user.'); - console.log(service.currentUser); + // console.log('Using local current user.'); + // console.log(service.currentUser); return service.currentUser; } else if ($window.user){ @@ -60,7 +60,6 @@ angular.module('users') $window.user = null; userState.isLoggedIn = false; service.currentUser = null; - service.ensureHasCurrentUser(null); }, }; return service; diff --git a/public/modules/users/views/authentication/signin.client.view.html b/public/modules/users/views/authentication/signin.client.view.html index 4a7a6fc1..45831770 100755 --- a/public/modules/users/views/authentication/signin.client.view.html +++ b/public/modules/users/views/authentication/signin.client.view.html @@ -1,5 +1,5 @@
-

Sign in with your account

+

Sign into your account