diff --git a/openslides/core/static/templates/core/login-form.html b/openslides/core/static/templates/core/login-form.html
index 91ecc11f7..75898a658 100644
--- a/openslides/core/static/templates/core/login-form.html
+++ b/openslides/core/static/templates/core/login-form.html
@@ -17,7 +17,7 @@
placeholder="{{ 'Password' | translate }}">
-
-
-
+
+
diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js
index 9e19f8338..01d41d968 100644
--- a/openslides/users/static/js/users/site.js
+++ b/openslides/users/static/js/users/site.js
@@ -120,10 +120,16 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
})
.state('login', {
template: null,
- onEnter: ['$stateParams', 'ngDialog', function($stateParams, ngDialog) {
+ url: '/login',
+ params: { guest_enabled: false },
+ onEnter: ['$state', 'ngDialog', function($state, ngDialog) {
ngDialog.open({
template: 'static/templates/core/login-form.html',
controller: 'LoginFormCtrl',
+ preCloseCallback: function() {
+ $state.go('dashboard');
+ return true;
+ }
});
}]
});
@@ -139,9 +145,9 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
// Put the operator into the root scope
$http.get('/users/whoami/').success(function(data) {
operator.setUser(data.user_id);
- if (data.user_id == null) {
+ if (data.user_id === null) {
// redirect to login dialog if use is not logged in
- $state.go('login');
+ $state.go('login', {guest_enabled: data.guest_enabled});
}
});
$rootScope.operator = operator;
@@ -716,10 +722,11 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
.controller('LoginFormCtrl', [
'$scope',
'$http',
+ '$stateParams',
'operator',
'gettextCatalog',
'Config',
- function ($scope, $http, operator, gettextCatalog, Config) {
+ function ($scope, $http, $stateParams, operator, gettextCatalog, Config) {
$scope.alerts = [];
// TODO: add welcome message only on first time (or if admin password not changed)
@@ -734,7 +741,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.alerts.splice(index, 1);
};
// check if guest login is allowed
- $scope.guestAllowed = true; //TODO Config.get('general_system_enable_anonymous').value;
+ $scope.guestAllowed = $stateParams.guest_enabled;
// login
$scope.login = function () {
$http.post(
diff --git a/openslides/users/views.py b/openslides/users/views.py
index 85bef6add..905f600ce 100644
--- a/openslides/users/views.py
+++ b/openslides/users/views.py
@@ -229,12 +229,12 @@ class WhoAmIView(APIView):
def get_context_data(self, **context):
"""
- Appends the user id to the context.
-
- Uses None for the anonymous user.
+ Appends the user id to the context. Uses None for the anonymous
+ user. Appends also a flag if guest users are enabled in the config.
"""
return super().get_context_data(
user_id=self.request.user.pk,
+ guest_enabled=config['general_system_enable_anonymous'],
**context)
diff --git a/tests/integration/users/test_views.py b/tests/integration/users/test_views.py
index 97d3b2bb0..97a7678be 100644
--- a/tests/integration/users/test_views.py
+++ b/tests/integration/users/test_views.py
@@ -12,7 +12,9 @@ class TestWhoAmIView(TestCase):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, b'{"user_id":null}')
+ self.assertEqual(
+ json.loads(response.content.decode('utf-8')),
+ {'user_id': None, 'guest_enabled': False})
def test_get_authenticated_user(self):
self.client.login(username='admin', password='admin')
@@ -20,7 +22,9 @@ class TestWhoAmIView(TestCase):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, b'{"user_id":1}')
+ self.assertEqual(
+ json.loads(response.content.decode('utf-8')),
+ {'user_id': 1, 'guest_enabled': False})
def test_post(self):
response = self.client.post(self.url)