commit
0701838bc8
@ -17,7 +17,7 @@
|
||||
placeholder="{{ 'Password' | translate }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary pull-right" translate>
|
||||
<button type="submit" class="btn btn-primary" translate>
|
||||
Login
|
||||
</button>
|
||||
<button ng-if="guestAllowed" ng-click="guestLogin()" class="btn btn-default" translate>
|
||||
|
@ -171,8 +171,8 @@
|
||||
</div>
|
||||
</div><!--end col2-->
|
||||
|
||||
</div><!--end content-container-->
|
||||
</div><!--end content-->
|
||||
</div><!--end content-container-->
|
||||
</div><!--end content-->
|
||||
|
||||
</div><!--end wrapper-->
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user