fixed logout redirection issue

This commit is contained in:
David Baldwynn 2015-07-06 18:56:38 -07:00
parent 78b08af8c7
commit c07a9ba267
11 changed files with 49 additions and 37 deletions

View file

@ -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)

View file

@ -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('/');
};

View file

@ -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);

View file

@ -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
}
}
});
}

View file

@ -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() {

View file

@ -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');
// }
}
]);

View file

@ -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;
}
}
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;
}

View file

@ -30,7 +30,7 @@
</div>
<div class="col-xs-12" style="margin-top:7%;">
<a class="btn btn-info" href="/#!/signup" style="background-color:#FA787E; border: none; font-size: 2em; padding: 0.3em 0.9em; color: white;">
<a class="btn btn-info signup-btn" href="/#!/signup" style="background-color:#FA787E; border: none; font-size: 2em; padding: 0.3em 0.9em; color: white;">
sign me up!
</a>
</div>

View file

@ -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;

View file

@ -1,5 +1,5 @@
<section class="row auth" data-ng-controller="AuthenticationController">
<h3 class="col-md-12 text-center">Sign in with your account</h3>
<h3 class="col-md-12 text-center">Sign into your account</h3>
<!-- <div class="col-md-12 text-center">
<a href="/auth/facebook" class="undecorated-link">
<img src="/modules/users/img/buttons/facebook.png">

View file

@ -33,6 +33,7 @@
<label for="lastName">Last Name</label>
<input type="text" id="lastName" name="lastName" class="form-control" data-ng-model="credentials.lastName" placeholder="Last Name">
</div>
<hr>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" class="form-control" data-ng-model="credentials.email" placeholder="Email">
@ -41,6 +42,7 @@
<label for="username">Username</label>
<input type="text" id="username" name="username" class="form-control" data-ng-model="credentials.username" placeholder="Username">
</div>
<hr>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" class="form-control" data-ng-model="credentials.password" placeholder="Password">