commit
0701838bc8
@ -17,7 +17,7 @@
|
|||||||
placeholder="{{ 'Password' | translate }}">
|
placeholder="{{ 'Password' | translate }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button type="submit" class="btn btn-primary pull-right" translate>
|
<button type="submit" class="btn btn-primary" translate>
|
||||||
Login
|
Login
|
||||||
</button>
|
</button>
|
||||||
<button ng-if="guestAllowed" ng-click="guestLogin()" class="btn btn-default" translate>
|
<button ng-if="guestAllowed" ng-click="guestLogin()" class="btn btn-default" translate>
|
||||||
|
@ -120,10 +120,16 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
})
|
})
|
||||||
.state('login', {
|
.state('login', {
|
||||||
template: null,
|
template: null,
|
||||||
onEnter: ['$stateParams', 'ngDialog', function($stateParams, ngDialog) {
|
url: '/login',
|
||||||
|
params: { guest_enabled: false },
|
||||||
|
onEnter: ['$state', 'ngDialog', function($state, ngDialog) {
|
||||||
ngDialog.open({
|
ngDialog.open({
|
||||||
template: 'static/templates/core/login-form.html',
|
template: 'static/templates/core/login-form.html',
|
||||||
controller: 'LoginFormCtrl',
|
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
|
// Put the operator into the root scope
|
||||||
$http.get('/users/whoami/').success(function(data) {
|
$http.get('/users/whoami/').success(function(data) {
|
||||||
operator.setUser(data.user_id);
|
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
|
// redirect to login dialog if use is not logged in
|
||||||
$state.go('login');
|
$state.go('login', {guest_enabled: data.guest_enabled});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$rootScope.operator = operator;
|
$rootScope.operator = operator;
|
||||||
@ -716,10 +722,11 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
.controller('LoginFormCtrl', [
|
.controller('LoginFormCtrl', [
|
||||||
'$scope',
|
'$scope',
|
||||||
'$http',
|
'$http',
|
||||||
|
'$stateParams',
|
||||||
'operator',
|
'operator',
|
||||||
'gettextCatalog',
|
'gettextCatalog',
|
||||||
'Config',
|
'Config',
|
||||||
function ($scope, $http, operator, gettextCatalog, Config) {
|
function ($scope, $http, $stateParams, operator, gettextCatalog, Config) {
|
||||||
$scope.alerts = [];
|
$scope.alerts = [];
|
||||||
|
|
||||||
// TODO: add welcome message only on first time (or if admin password not changed)
|
// 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);
|
$scope.alerts.splice(index, 1);
|
||||||
};
|
};
|
||||||
// check if guest login is allowed
|
// check if guest login is allowed
|
||||||
$scope.guestAllowed = true; //TODO Config.get('general_system_enable_anonymous').value;
|
$scope.guestAllowed = $stateParams.guest_enabled;
|
||||||
// login
|
// login
|
||||||
$scope.login = function () {
|
$scope.login = function () {
|
||||||
$http.post(
|
$http.post(
|
||||||
|
@ -229,12 +229,12 @@ class WhoAmIView(APIView):
|
|||||||
|
|
||||||
def get_context_data(self, **context):
|
def get_context_data(self, **context):
|
||||||
"""
|
"""
|
||||||
Appends the user id to the context.
|
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.
|
||||||
Uses None for the anonymous user.
|
|
||||||
"""
|
"""
|
||||||
return super().get_context_data(
|
return super().get_context_data(
|
||||||
user_id=self.request.user.pk,
|
user_id=self.request.user.pk,
|
||||||
|
guest_enabled=config['general_system_enable_anonymous'],
|
||||||
**context)
|
**context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ class TestWhoAmIView(TestCase):
|
|||||||
response = self.client.get(self.url)
|
response = self.client.get(self.url)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
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):
|
def test_get_authenticated_user(self):
|
||||||
self.client.login(username='admin', password='admin')
|
self.client.login(username='admin', password='admin')
|
||||||
@ -20,7 +22,9 @@ class TestWhoAmIView(TestCase):
|
|||||||
response = self.client.get(self.url)
|
response = self.client.get(self.url)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
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):
|
def test_post(self):
|
||||||
response = self.client.post(self.url)
|
response = self.client.post(self.url)
|
||||||
|
Loading…
Reference in New Issue
Block a user