2015-04-08 22:43:59 +00:00
|
|
|
(function () {
|
|
|
|
|
2015-04-28 23:08:20 +00:00
|
|
|
function UserLoginCtrl($scope, $window) {
|
|
|
|
// attempts to extract an error message from
|
|
|
|
// the URL hash in format #error=?
|
|
|
|
$scope.error = $window.location.hash.substr(7);
|
|
|
|
}
|
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
/**
|
|
|
|
* UserCtrl is responsible for managing user settings.
|
2015-04-28 23:08:20 +00:00
|
|
|
*/
|
2015-04-13 23:33:29 +00:00
|
|
|
function UserCtrl($scope, users, tokens) {
|
2015-04-08 22:43:59 +00:00
|
|
|
|
2015-04-28 23:08:20 +00:00
|
|
|
// Gets the currently authenticated user
|
2015-04-08 22:43:59 +00:00
|
|
|
users.getCurrent().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
2015-04-13 23:33:29 +00:00
|
|
|
|
|
|
|
// Gets the user tokens
|
|
|
|
tokens.list().then(function(payload){
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.tokens = payload.data || [];
|
2015-04-13 23:33:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.newToken={Label: ""};
|
|
|
|
$scope.createToken = function(newToken) {
|
|
|
|
tokens.post(newToken).then(function(payload) {
|
|
|
|
$scope.tokens.push(payload.data);
|
|
|
|
$scope.newToken={Label: ""};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.revokeToken = function(token) {
|
|
|
|
tokens.delete(token).then(function() {
|
|
|
|
var index = $scope.tokens.indexOf(token);
|
|
|
|
$scope.tokens.splice(index, 1);
|
|
|
|
});
|
|
|
|
}
|
2015-04-08 22:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UsersCtrl is responsible for managing user accounts.
|
|
|
|
* This part of the site is for administrators only.
|
2015-04-28 23:08:20 +00:00
|
|
|
*/
|
2015-04-08 22:43:59 +00:00
|
|
|
function UsersCtrl($scope, users) {
|
2015-07-30 02:51:55 +00:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.waiting = false;
|
|
|
|
|
2015-04-28 23:08:20 +00:00
|
|
|
// Gets the currently authenticated user
|
2015-04-08 22:43:59 +00:00
|
|
|
users.getCached().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
|
|
|
|
2015-07-30 02:51:55 +00:00
|
|
|
// Gets the list of all system users
|
2015-04-08 22:43:59 +00:00
|
|
|
users.list().then(function(payload){
|
2015-07-30 02:51:55 +00:00
|
|
|
$scope.loading = true;
|
2015-04-08 22:43:59 +00:00
|
|
|
$scope.users = payload.data;
|
|
|
|
});
|
|
|
|
|
2015-07-30 02:51:55 +00:00
|
|
|
$scope.add = function(event, login) {
|
|
|
|
$scope.error = undefined;
|
|
|
|
if (event.which && event.which !== 13) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$scope.waiting = true;
|
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
users.post(login).then(function(payload){
|
|
|
|
$scope.users.push(payload.data);
|
2015-07-30 02:51:55 +00:00
|
|
|
$scope.search_text=undefined;
|
|
|
|
$scope.waiting = false;
|
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
$scope.waiting = false;
|
|
|
|
$scope.search_text = undefined;
|
2015-04-08 22:43:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.toggle = function(user) {
|
|
|
|
user.admin = !user.admin;
|
|
|
|
users.put(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.remove = function(user) {
|
|
|
|
users.delete(user).then(function(){
|
2015-04-13 23:33:29 +00:00
|
|
|
var index = $scope.users.indexOf(user);
|
|
|
|
$scope.users.splice(index, 1);
|
2015-04-08 22:43:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('drone')
|
2015-04-28 23:08:20 +00:00
|
|
|
.controller('UserLoginCtrl', UserLoginCtrl)
|
2015-04-08 22:43:59 +00:00
|
|
|
.controller('UserCtrl', UserCtrl)
|
|
|
|
.controller('UsersCtrl', UsersCtrl);
|
2015-04-28 23:08:20 +00:00
|
|
|
})();
|