Merge pull request #3172 from FinnStutzenstein/logout

Do not reload on logout (fixes #2868).
This commit is contained in:
Norman Jäckel 2017-04-07 16:32:41 +02:00 committed by GitHub
commit 66ad801bad
4 changed files with 58 additions and 29 deletions

View File

@ -10,6 +10,10 @@ Version 2.2 (unreleased)
Motions: Motions:
- New export dialog. - New export dialog.
Core:
- No reload on logoff. OpenSlides is now a full single page application.
Version 2.1.1 (2017-04-05) Version 2.1.1 (2017-04-05)
========================== ==========================
[https://github.com/OpenSlides/OpenSlides/milestones/2.1.1] [https://github.com/OpenSlides/OpenSlides/milestones/2.1.1]

View File

@ -76,11 +76,6 @@ angular.module('OpenSlidesApp.core', [
Autoupdate.onMessage = function (receiver) { Autoupdate.onMessage = function (receiver) {
Autoupdate.messageReceivers.push(receiver); Autoupdate.messageReceivers.push(receiver);
}; };
Autoupdate.reconnect = function () {
if (socket) {
socket.close();
}
};
Autoupdate.newConnect = function () { Autoupdate.newConnect = function () {
socket = new WebSocket(websocketProtocol + '//' + location.host + websocketPath); socket = new WebSocket(websocketProtocol + '//' + location.host + websocketPath);
clearInterval(recInterval); clearInterval(recInterval);
@ -89,7 +84,9 @@ angular.module('OpenSlidesApp.core', [
recInterval = setInterval(function () { recInterval = setInterval(function () {
Autoupdate.newConnect(); Autoupdate.newConnect();
}, 1000); }, 1000);
ErrorMessage.setConnectionError(); if (event.code !== 1000) { // 1000 is a normal close, like the close on logout
ErrorMessage.setConnectionError();
}
}; };
socket.onmessage = function (event) { socket.onmessage = function (event) {
_.forEach(Autoupdate.messageReceivers, function (receiver) { _.forEach(Autoupdate.messageReceivers, function (receiver) {
@ -102,6 +99,12 @@ angular.module('OpenSlidesApp.core', [
ErrorMessage.clearConnectionError(); ErrorMessage.clearConnectionError();
}; };
}; };
Autoupdate.closeConnection = function () {
if (socket) {
socket.close();
}
Autoupdate.firstMessageDeferred = $q.defer();
};
return Autoupdate; return Autoupdate;
} }
]) ])

View File

@ -4,31 +4,55 @@
angular.module('OpenSlidesApp.core.start', []) angular.module('OpenSlidesApp.core.start', [])
.run([ .factory('OpenSlides', [
'$http', '$http',
'$rootScope', '$rootScope',
'$state', '$state',
'DS',
'autoupdate', 'autoupdate',
'operator', 'operator',
'Group', 'Group',
'mainMenu', 'mainMenu',
function($http, $rootScope, $state, autoupdate, operator, Group, mainMenu) { function($http, $rootScope, $state, DS, autoupdate, operator, Group, mainMenu) {
$rootScope.openslidesBootstrapDone = false; return {
$http.get('/users/whoami/').then(function (success) { bootup: function () {
$rootScope.guest_enabled = success.data.guest_enabled; $rootScope.openslidesBootstrapDone = false;
if (success.data.user_id === null && !success.data.guest_enabled) { $http.get('/users/whoami/').then(function (success) {
// Redirect to login dialog if user is not logged in. $rootScope.guest_enabled = success.data.guest_enabled;
$state.go('login', {guest_enabled: success.data.guest_enabled}); if (success.data.user_id === null && !success.data.guest_enabled) {
} else { // Redirect to login dialog if user is not logged in.
autoupdate.newConnect(); $state.go('login', {guest_enabled: success.data.guest_enabled});
autoupdate.firstMessageDeferred.promise.then(function () { } else {
operator.setUser(success.data.user_id, success.data.user); autoupdate.newConnect();
$rootScope.operator = operator; autoupdate.firstMessageDeferred.promise.then(function () {
mainMenu.updateMainMenu(); operator.setUser(success.data.user_id, success.data.user);
$rootScope.openslidesBootstrapDone = true; $rootScope.operator = operator;
mainMenu.updateMainMenu();
$rootScope.openslidesBootstrapDone = true;
});
}
}); });
} },
}); shutdown: function () {
// Close connection, clear the store and show the OS overlay.
autoupdate.closeConnection();
DS.clear();
operator.setUser(null);
$rootScope.openslidesBootstrapDone = false;
$rootScope.operator = operator;
},
reboot: function () {
this.shutdown();
this.bootup();
},
};
}
])
.run([
'OpenSlides',
function (OpenSlides) {
OpenSlides.bootup();
} }
]) ])

View File

@ -1397,17 +1397,15 @@ angular.module('OpenSlidesApp.users.site', [
.controller('userMenu', [ .controller('userMenu', [
'$scope', '$scope',
'$http', '$http',
'DS', 'OpenSlides',
'User',
'operator',
'ngDialog', 'ngDialog',
'UserProfileForm', 'UserProfileForm',
'UserPasswordForm', 'UserPasswordForm',
function($scope, $http, DS, User, operator, ngDialog, UserProfileForm, UserPasswordForm) { function($scope, $http, OpenSlides, ngDialog, UserProfileForm, UserPasswordForm) {
$scope.logout = function () { $scope.logout = function () {
$http.post('/users/logout/').then(function (response) { $http.post('/users/logout/').then(function (response) {
operator.setUser(null); // Success: User logged out, so reboot OpenSlides.
window.location.reload(); OpenSlides.reboot();
}); });
}; };
$scope.editProfile = function () { $scope.editProfile = function () {