This commit is contained in:
kevgliss 2016-07-04 13:03:46 -07:00 committed by GitHub
parent 300e2d0b7d
commit c8eca56690
4 changed files with 56 additions and 42 deletions

View File

@ -864,7 +864,7 @@ class Rolling(Command):
def main(): def main():
manager.add_command("start", LemurServer()) manager.add_command("start", LemurServer())
manager.add_command("runserver", Server(host='127.0.0.1')) manager.add_command("runserver", Server(host='127.0.0.1', threaded=True))
manager.add_command("clean", Clean()) manager.add_command("clean", Clean())
manager.add_command("show_urls", ShowUrls()) manager.add_command("show_urls", ShowUrls())
manager.add_command("db", MigrateCommand) manager.add_command("db", MigrateCommand)

View File

@ -149,9 +149,17 @@
}); });
}); });
lemur.run(['$templateCache', function ($templateCache) { lemur.run(function ($templateCache, $location, $rootScope, $auth, $state) {
$templateCache.put('ng-table/pager.html', '<div class="ng-cloak ng-table-pager"> <div ng-if="params.settings().counts.length" class="ng-table-counts btn-group pull-left"> <button ng-repeat="count in params.settings().counts" type="button" ng-class="{\'active\':params.count()==count}" ng-click="params.count(count)" class="btn btn-default"> <span ng-bind="count"></span> </button></div><div class="pull-right"><ul style="margin: 0; padding: 0;" class="pagination ng-table-pagination"> <li ng-class="{\'disabled\': !page.active}" ng-repeat="page in pages" ng-switch="page.type"> <a ng-switch-when="prev" ng-click="params.page(page.number)" href="">&laquo;</a> <a ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="more" ng-click="params.page(page.number)" href="">&#8230;</a> <a ng-switch-when="last" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="next" ng-click="params.page(page.number)" href="">&raquo;</a> </li> </ul> </div></div>'); $templateCache.put('ng-table/pager.html', '<div class="ng-cloak ng-table-pager"> <div ng-if="params.settings().counts.length" class="ng-table-counts btn-group pull-left"> <button ng-repeat="count in params.settings().counts" type="button" ng-class="{\'active\':params.count()==count}" ng-click="params.count(count)" class="btn btn-default"> <span ng-bind="count"></span> </button></div><div class="pull-right"><ul style="margin: 0; padding: 0;" class="pagination ng-table-pagination"> <li ng-class="{\'disabled\': !page.active}" ng-repeat="page in pages" ng-switch="page.type"> <a ng-switch-when="prev" ng-click="params.page(page.number)" href="">&laquo;</a> <a ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="more" ng-click="params.page(page.number)" href="">&#8230;</a> <a ng-switch-when="last" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="next" ng-click="params.page(page.number)" href="">&raquo;</a> </li> </ul> </div></div>');
}]); $rootScope.$on('$stateChangeStart', function(event, toState, toParams) {
if (toState.name !== 'login') {
if (!$auth.isAuthenticated()) {
event.preventDefault();
$state.go('login', {'toState': toState.name, 'toParams': toParams, notify: false});
}
}
});
});
}()); }());

View File

@ -5,12 +5,48 @@ angular.module('lemur')
$stateProvider.state('login', { $stateProvider.state('login', {
url: '/login', url: '/login',
templateUrl: '/angular/authentication/login/login.tpl.html', templateUrl: '/angular/authentication/login/login.tpl.html',
controller: 'LoginController' controller: 'LoginController',
params: {
'toState': 'certificates',
'toParams': {}
}
}); });
}) })
.controller('LoginController', function ($rootScope, $scope, AuthenticationService, UserService, providers) { .controller('LoginController', function ($rootScope, $scope, $state, $auth, AuthenticationService, UserService, providers, toaster) {
$scope.login = AuthenticationService.login; $scope.login = function (username, password) {
$scope.authenticate = AuthenticationService.authenticate; return AuthenticationService.login(username, password).then(
function (user) {
$auth.setToken(user.token, true);
$rootScope.$emit('user:login');
$state.go($state.params.toState, $state.params.toParams);
},
function (response) {
toaster.pop({
type: 'error',
title: 'Whoa there',
body: response.data.message,
showCloseButton: true
});
});
};
$scope.authenticate = function (provider) {
return AuthenticationService.authenticate(provider).then(
function (user) {
$auth.setToken(user.token, true);
$rootScope.$emit('user:login');
$state.go($state.params.toState, $state.params.toParams);
},
function (response) {
toaster.pop({
type: 'error',
title: 'Whoa there',
body: response.data.message,
showCloseButton: true
});
});
};
$scope.logout = AuthenticationService.logout; $scope.logout = AuthenticationService.logout;
$scope.providers = providers; $scope.providers = providers;
@ -28,4 +64,4 @@ angular.module('lemur')
$rootScope.$on('user:logout', function () { $rootScope.$on('user:logout', function () {
$scope.currentUser = null; $scope.currentUser = null;
}); });
}); });

View File

@ -7,40 +7,11 @@ angular.module('lemur')
var AuthenticationService = this; var AuthenticationService = this;
AuthenticationService.login = function (username, password) { AuthenticationService.login = function (username, password) {
AuthenticationApi.customPOST({'username': username, 'password': password}, 'login') return AuthenticationApi.customPOST({'username': username, 'password': password}, 'login');
.then(
function (user) {
$auth.setToken(user.token, true);
$rootScope.$emit('user:login');
$location.url('/certificates');
},
function (response) {
toaster.pop({
type: 'error',
title: 'Whoa there',
body: response.data.message,
showCloseButton: true
});
}
);
}; };
AuthenticationService.authenticate = function (provider) { AuthenticationService.authenticate = function (provider) {
$auth.authenticate(provider) return $auth.authenticate(provider);
.then(
function () {
UserService.getCurrentUser();
$rootScope.$emit('user:login');
$location.url('/certificates');
},
function (response) {
toaster.pop({
type: 'error',
title: 'Something went wrong',
body: response.data.message
});
}
);
}; };
AuthenticationService.logout = function () { AuthenticationService.logout = function () {
@ -55,8 +26,7 @@ angular.module('lemur')
title: 'Good job!', title: 'Good job!',
body: 'You have been successfully logged out.' body: 'You have been successfully logged out.'
}); });
$location.path('/'); $location.path('/login');
}); });
}; };
});
});