Work on Maatma interface
This commit is contained in:
parent
9cb1ad6e97
commit
e965705bfe
6 changed files with 403 additions and 15 deletions
159
token-validator/htdocs/js/adlin-main.js
Normal file
159
token-validator/htdocs/js/adlin-main.js
Normal file
|
@ -0,0 +1,159 @@
|
|||
angular.module("AdLinApp", ["ngRoute", "ngResource", "ngSanitize"])
|
||||
.config(function($routeProvider, $locationProvider) {
|
||||
$routeProvider
|
||||
.when("/auth", {
|
||||
controller: "AuthController",
|
||||
templateUrl: "views/auth.html"
|
||||
})
|
||||
.when("/domains", {
|
||||
controller: "DomainsController",
|
||||
templateUrl: "views/domains.html"
|
||||
})
|
||||
.when("/tunnels", {
|
||||
controller: "TunnelsController",
|
||||
templateUrl: "views/tunnels.html"
|
||||
})
|
||||
.when("/", {
|
||||
templateUrl: "views/home.html"
|
||||
});
|
||||
$locationProvider.html5Mode(true);
|
||||
});
|
||||
|
||||
angular.module("AdLinApp")
|
||||
.factory("Student", function($resource) {
|
||||
return $resource("/api/students/:studentId", { studentId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("Progression", function($resource) {
|
||||
return $resource("/api/progress")
|
||||
})
|
||||
.factory("Challenge", function($resource) {
|
||||
return $resource("/challenge/:challengeId", { challengeId: '@id' })
|
||||
});
|
||||
|
||||
angular.module("AdLinApp")
|
||||
.run(function($rootScope, $interval, $http) {
|
||||
$rootScope.checkLoginState = function() {
|
||||
if (sessionStorage.token === undefined) {
|
||||
$rootScope.isLogged = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var token = sessionStorage.token;
|
||||
$http({
|
||||
method: 'GET',
|
||||
url: "/api/auth",
|
||||
headers: {
|
||||
'Authorization': "Bearer " + token
|
||||
}
|
||||
}).then(function(response) {
|
||||
$rootScope.isLogged = response.data;
|
||||
}, function(response) {
|
||||
$rootScope.isLogged = false;
|
||||
});
|
||||
};
|
||||
$rootScope.checkLoginState();
|
||||
$interval($rootScope.checkLoginState, 20000);
|
||||
|
||||
$rootScope.disconnectCurrentUser = function() {
|
||||
sessionStorage.token = undefined;
|
||||
delete sessionStorage.token;
|
||||
$rootScope.isLogged = false;
|
||||
}
|
||||
})
|
||||
|
||||
.controller("AuthController", function($scope, $rootScope, $http, $location) {
|
||||
$scope.auth = {
|
||||
"username": "",
|
||||
"password": "",
|
||||
};
|
||||
|
||||
$scope.logmein = function() {
|
||||
$scope.pleaseWait = true;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "/api/auth",
|
||||
data: $scope.auth
|
||||
}).then(function(response) {
|
||||
sessionStorage.token = response.data.id_session
|
||||
$scope.pleaseWait = false;
|
||||
$rootScope.checkLoginState();
|
||||
$location.url("/");
|
||||
}, function(response) {
|
||||
alert(response.data.errmsg);
|
||||
$scope.pleaseWait = false;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
.controller("TunnelsController", function($scope, $http, $interval) {
|
||||
$scope.updateTunnelInfo = function() {
|
||||
$http({
|
||||
method: 'GET',
|
||||
url: "/api/wginfo",
|
||||
headers: {
|
||||
'Authorization': "Bearer " + sessionStorage.token
|
||||
}
|
||||
}).then(function(response) {
|
||||
$scope.wginfo = response.data;
|
||||
});
|
||||
};
|
||||
$scope.updateTunnelInfo();
|
||||
|
||||
$scope.updateTunnelsList = function() {
|
||||
$http({
|
||||
method: 'GET',
|
||||
url: "/api/wg/",
|
||||
headers: {
|
||||
'Authorization': "Bearer " + sessionStorage.token
|
||||
}
|
||||
}).then(function(response) {
|
||||
$scope.tunnels = response.data;
|
||||
}, function(response) {
|
||||
alert(response.data.errmsg);
|
||||
});
|
||||
};
|
||||
$scope.updateTunnelsList();
|
||||
$interval($scope.updateTunnelsList, 12000);
|
||||
|
||||
$scope.newTunnel = function() {
|
||||
$scope.pleaseWaitNew = true;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "/api/wg/",
|
||||
headers: {
|
||||
'Authorization': "Bearer " + sessionStorage.token
|
||||
},
|
||||
data: {}
|
||||
}).then(function(response) {
|
||||
$scope.updateTunnelsList();
|
||||
$scope.pleaseWaitNew = false;
|
||||
}, function(response) {
|
||||
alert(response.data.errmsg);
|
||||
$scope.pleaseWaitNew = false;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.dropTunnel = function(tunnel) {
|
||||
tunnel.pleaseWaitDrop = true;
|
||||
$http({
|
||||
method: 'DELETE',
|
||||
url: "/api/wg/" + tunnel.TokenText,
|
||||
headers: {
|
||||
'Authorization': "Bearer " + sessionStorage.token
|
||||
},
|
||||
data: {}
|
||||
}).then(function(response) {
|
||||
$scope.updateTunnelsList();
|
||||
tunnel.pleaseWaitDrop = false;
|
||||
}, function(response) {
|
||||
alert(response.data.errmsg);
|
||||
tunnel.pleaseWaitDrop = false;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
.controller("DomainsController", function($scope, $http, $interval) {
|
||||
|
||||
})
|
Reference in a new issue