Commit 36b7c99f authored by Antek Grzanka's avatar Antek Grzanka

Login logout works flawlessly!

parent 91a87295
...@@ -63,7 +63,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> ...@@ -63,7 +63,7 @@ public class CTFApplication extends Application<ApplicationConfiguration>
.setAuthenticator(injector.getInstance(ExampleAuthenticator.class)) .setAuthenticator(injector.getInstance(ExampleAuthenticator.class))
.setAuthorizer(new ExampleAuthorizer()) .setAuthorizer(new ExampleAuthorizer())
.setRealm("SUPER SECRET STUFF") .setRealm("SUPER SECRET STUFF")
.setPrefix("Not-So-Basic") //.setPrefix("Not-So-Basic")
.buildAuthFilter())); .buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class); environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
return { return {
getScores: function(){}, getScores: function(){},
getTasks: function(callback){ getTasks: function(callback){
$http.get(AppSettings.apiAddress + '/tasks'). $http.get('http://' + AppSettings.apiAddress + '/tasks').
success(function(data) { success(function(data) {
tasks = data; tasks = data;
if (callback) callback(data); if (callback) callback(data);
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
callback(result); callback(result);
}, },
submitFlag: function(flag){ submitFlag: function(flag){
return $http.post(AppSettings.apiAddress + '/solutions', flag); return $http.post('http://' + AppSettings.apiAddress + '/solutions', flag);
} }
}; };
}]); }]);
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
*/ */
login: function (username, password, callback) { login: function (username, password, callback) {
$http.get(AppSettings.apiAddress + '/whoami', { $http.get('http://' + username + ":" + password + "@" + AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Not-So-Basic ' + Base64.encode(username + ':' + password)} headers: {'Authorization': 'Basic ' + Base64.encode(username + ':' + password)}
}) })
.then(function (response) { .then(function (response) {
console.debug("RESPONSE", response); console.debug("RESPONSE", response);
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
*/ */
logout: function (callback) { logout: function (callback) {
$http.get(AppSettings.apiAddress + '/whoami', { $http.get('http://' + 'askdjfadsf' + ':' + 'adsfasskdjfadsf' + '@' + AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Not-So-Basic ' + Base64.encode('askdjfadsf' + ':' + 'adsfasskdjfadsf')} headers: {'Authorization': 'Basic ' + Base64.encode('askdjfadsf' + ':' + 'adsfasskdjfadsf')}
}).then(function(response){ }).then(function(response){
this.clearCredentials(); this.clearCredentials();
callback(response); callback(response);
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
} }
}; };
$http.defaults.headers.common['Authorization'] = 'Not-So-Basic ' + authdata; $http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
$cookieStore.put('globals', $rootScope.globals); $cookieStore.put('globals', $rootScope.globals);
}, },
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
$rootScope.globals = {}; $rootScope.globals = {};
$cookieStore.remove('globals'); $cookieStore.remove('globals');
$http.defaults.headers.common.Authorization = 'Not-So-Basic ' $http.defaults.headers.common.Authorization = 'Basic '
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
AuthenticationService.login($scope.username, $scope.password, function(response) { AuthenticationService.login($scope.username, $scope.password, function(response) {
if(response.status == 200) { if(response.status == 200) {
AuthenticationService.setCredentials($scope.username, $scope.password, response.team); AuthenticationService.setCredentials($scope.username, $scope.password, response.team);
$('.title').html($scope.username+'@<b>capture-the-flAGH-2016</b>'); $('.title').html($scope.username+'@<b>capture-the-flAGH-2016</b>:~$');
$location.path('/'); $location.path('/');
} else { } else {
$scope.error = response.message; $scope.error = response.message;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
$scope.logout = function(){ $scope.logout = function(){
AuthenticationService.logout(function(data){ AuthenticationService.logout(function(data){
console.log("Logged you out... i guess...", data); console.log("Logged you out... i guess...", data);
$('.title').html('guest@<b>capture-the-flAGH-2016</b>'); $('.title').html('guest@<b>capture-the-flAGH-2016</b>:~$');
$location.path('/'); $location.path('/');
}); });
}; };
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
} }
$http.get(AppSettings.apiAddress + '/solutions/all'). $http.get('http://' + AppSettings.apiAddress + '/solutions/all').
success(function(data) { success(function(data) {
console.log(data); console.log(data);
if ($.isEmptyObject(data)){ if ($.isEmptyObject(data)){
......
(function(){ (function(){
angular.module('ctfApp').controller('TaskController', ['$scope', '$stateParams', 'APIProvider', 'AppSettings', function($scope, $stateParams, APIProvider, AppSettings) { angular.module('ctfApp').controller('TaskController', ['$scope', '$stateParams', 'APIProvider', 'AppSettings', function($scope, $stateParams, APIProvider, AppSettings) {
$scope.submitUnknown = false; $scope.submitUnknown = false;
$scope.apiAddress = AppSettings.apiAddress; $scope.apiAddress = 'http://' + AppSettings.apiAddress;
$scope.selectedTaskId = $stateParams.taskLevel; $scope.selectedTaskId = $stateParams.taskLevel;
console.log('SELECTED TASK ID', $scope.selectedTaskId); console.log('SELECTED TASK ID', $scope.selectedTaskId);
APIProvider.getTaskById($scope.selectedTaskId, function(data){ APIProvider.getTaskById($scope.selectedTaskId, function(data){
......
...@@ -39,10 +39,30 @@ ...@@ -39,10 +39,30 @@
app.factory('AppSettings', function() { app.factory('AppSettings', function() {
return { return {
apiAddress: "http://localhost:8080/api/v1" apiAddress: "localhost:8080/api/v1"
} }
}); });
app.config(function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'response': function (response) {
if (response.status === 401) {
console.log("Response 401");
}
return response || $q.when(response);
},
'responseError': function (rejection) {
if (rejection.status === 401) {
console.log("Response Error 401");
}
return $q.reject(rejection);
}
};
});
});
app.run(['$rootScope', '$location', '$cookieStore', '$http', app.run(['$rootScope', '$location', '$cookieStore', '$http',
function ($rootScope, $location, $cookieStore, $http) { function ($rootScope, $location, $cookieStore, $http) {
...@@ -52,14 +72,14 @@ ...@@ -52,14 +72,14 @@
var username = $rootScope.globals.currentUser ? $rootScope.globals.currentUser.username : 'guest'; var username = $rootScope.globals.currentUser ? $rootScope.globals.currentUser.username : 'guest';
$(".title").typed({ $(".title").typed({
strings: [username+"@<b>capture-the-flag</b>", username+"@<b>capture-the-flAGH-2016</b>"], strings: [username+"@<b>capture-the-flag</b>:~$", username+"@<b>capture-the-flAGH-2016</b>:~$"],
startDelay: 10, startDelay: 10,
backDelay: 500, backDelay: 500,
whenToStop: 14 + username.length whenToStop: 17 + username.length
}); });
if ($rootScope.globals.currentUser) { if ($rootScope.globals.currentUser) {
$http.defaults.headers.common['Authorization'] = 'Not-So-Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
} }
$rootScope.$on('$locationChangeStart', function (event, next, current) { $rootScope.$on('$locationChangeStart', function (event, next, current) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment