Skip to content

Commit

Permalink
fix(auth): remove silly auth message
Browse files Browse the repository at this point in the history
This commit removes the notify.warn() message that shows if you have
been logged in previously and still have a valid session on the client
but not on the server.

It also improves the speed of the checks by converting them to cached
regular expressions.

Closes #250.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 5, 2017
1 parent 4ae364f commit 7f501e3
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,6 @@ function bhimaConfig($stateProvider, $urlMatcherFactoryProvider) {
templateUrl : 'partials/purchases/create/create.html'
})

/* cashbox routes */
// .state('cashboxes', {
// url : '/cashboxes',
// controller : 'CashboxController as CashCtrl',
// templateUrl : 'partials/cash/cashboxes/cashboxes.html'
// })
// .state('cashboxes.currencies', {
// url : '/cashboxes/:uuid/currencies',
// controller : 'cash.cashbox_account',
// templateUrl : 'partials/cash/cashboxes/currencies/currencies.html'
// })

/* transaction type */
.state('transactionType', {
url: '/admin/transaction_type',
Expand Down Expand Up @@ -223,11 +211,17 @@ function localeConfig(tmhDynamicLocaleProvider) {
// redirect to login if not signed in.
function startupConfig($rootScope, $state, $uibModalStack, SessionService, amMoment, Notify, $location) {

var loginStateRegexp = /#\/login$/;
var rootStateRegexp = /#\/$|\/$|#$/;


// make sure the user is logged in and allowed to access states when
// navigating by URL. This is pure an authentication issue.
$rootScope.$on('$locationChangeStart', function (event, next) {
var isLoggedIn = !!SessionService.user;
var isLoginState = next.indexOf('#/login') !== -1;

var isLoginState = loginStateRegexp.test(next);
var isRootState = rootStateRegexp.test(next);

// if the user is logged in and trying to access the login state, deny the
// attempt with a message "Cannot return to login. Please log out from the
Expand All @@ -241,7 +235,11 @@ function startupConfig($rootScope, $state, $uibModalStack, SessionService, amMom
// to the login page.
} else if (!isLoggedIn && !isLoginState) {
event.preventDefault();
Notify.warn('AUTH.UNAUTHENTICATED');

if (!isRootState) {
Notify.warn('AUTH.UNAUTHENTICATED');
}

$state.go('login');
}

Expand Down

0 comments on commit 7f501e3

Please sign in to comment.