Redirect to login dialog if user is not logged in (Fixes #1750)

This commit is contained in:
Emanuel Schuetze 2015-12-09 20:45:52 +01:00
parent 5e3ff74575
commit f050e04f0a
2 changed files with 16 additions and 8 deletions

View File

@ -91,7 +91,7 @@
</div>
<!-- Login button -->
<div ng-if="!operator.isAuthenticated()">
<a href ng-click="openLoginForm()" class="headerlink" uib-dropdown-toggle>
<a href ui-sref="login" class="headerlink" uib-dropdown-toggle>
<i class="fa fa-sign-in"></i>
<translate>Login</translate>
</a>

View File

@ -117,6 +117,15 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' });
}
}
})
.state('login', {
template: null,
onEnter: ['$stateParams', 'ngDialog', function($stateParams, ngDialog) {
ngDialog.open({
template: 'static/templates/core/login-form.html',
controller: 'LoginFormCtrl',
});
}]
});
})
@ -124,11 +133,16 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'operator',
'$rootScope',
'$http',
'$state',
'Group',
function(operator, $rootScope, $http, Group) {
function(operator, $rootScope, $http, $state, Group) {
// Put the operator into the root scope
$http.get('/users/whoami/').success(function(data) {
operator.setUser(data.user_id);
if (data.user_id == null) {
// redirect to login dialog if use is not logged in
$state.go('login');
}
});
$rootScope.operator = operator;
// Load all Groups. They are needed later
@ -696,12 +710,6 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
// DS.flush();
});
};
$scope.openLoginForm = function () {
ngDialog.open({
template: 'static/templates/core/login-form.html',
controller: 'LoginFormCtrl',
});
};
}
])