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>
.setAuthenticator(injector.getInstance(ExampleAuthenticator.class))
.setAuthorizer(new ExampleAuthorizer())
.setRealm("SUPER SECRET STUFF")
.setPrefix("Not-So-Basic")
//.setPrefix("Not-So-Basic")
.buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
......
......@@ -4,7 +4,7 @@
return {
getScores: function(){},
getTasks: function(callback){
$http.get(AppSettings.apiAddress + '/tasks').
$http.get('http://' + AppSettings.apiAddress + '/tasks').
success(function(data) {
tasks = data;
if (callback) callback(data);
......@@ -25,7 +25,7 @@
callback(result);
},
submitFlag: function(flag){
return $http.post(AppSettings.apiAddress + '/solutions', flag);
return $http.post('http://' + AppSettings.apiAddress + '/solutions', flag);
}
};
}]);
......
......@@ -13,8 +13,8 @@
*/
login: function (username, password, callback) {
$http.get(AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Not-So-Basic ' + Base64.encode(username + ':' + password)}
$http.get('http://' + username + ":" + password + "@" + AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Basic ' + Base64.encode(username + ':' + password)}
})
.then(function (response) {
console.debug("RESPONSE", response);
......@@ -32,8 +32,8 @@
*/
logout: function (callback) {
$http.get(AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Not-So-Basic ' + Base64.encode('askdjfadsf' + ':' + 'adsfasskdjfadsf')}
$http.get('http://' + 'askdjfadsf' + ':' + 'adsfasskdjfadsf' + '@' + AppSettings.apiAddress + '/whoami', {
headers: {'Authorization': 'Basic ' + Base64.encode('askdjfadsf' + ':' + 'adsfasskdjfadsf')}
}).then(function(response){
this.clearCredentials();
callback(response);
......@@ -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);
},
......@@ -73,7 +73,7 @@
$rootScope.globals = {};
$cookieStore.remove('globals');
$http.defaults.headers.common.Authorization = 'Not-So-Basic '
$http.defaults.headers.common.Authorization = 'Basic '
}
......
......@@ -10,7 +10,7 @@
AuthenticationService.login($scope.username, $scope.password, function(response) {
if(response.status == 200) {
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('/');
} else {
$scope.error = response.message;
......
......@@ -9,7 +9,7 @@
$scope.logout = function(){
AuthenticationService.logout(function(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('/');
});
};
......
......@@ -31,7 +31,7 @@
}
$http.get(AppSettings.apiAddress + '/solutions/all').
$http.get('http://' + AppSettings.apiAddress + '/solutions/all').
success(function(data) {
console.log(data);
if ($.isEmptyObject(data)){
......
(function(){
angular.module('ctfApp').controller('TaskController', ['$scope', '$stateParams', 'APIProvider', 'AppSettings', function($scope, $stateParams, APIProvider, AppSettings) {
$scope.submitUnknown = false;
$scope.apiAddress = AppSettings.apiAddress;
$scope.apiAddress = 'http://' + AppSettings.apiAddress;
$scope.selectedTaskId = $stateParams.taskLevel;
console.log('SELECTED TASK ID', $scope.selectedTaskId);
APIProvider.getTaskById($scope.selectedTaskId, function(data){
......
......@@ -39,10 +39,30 @@
app.factory('AppSettings', function() {
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',
function ($rootScope, $location, $cookieStore, $http) {
......@@ -52,14 +72,14 @@
var username = $rootScope.globals.currentUser ? $rootScope.globals.currentUser.username : 'guest';
$(".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,
backDelay: 500,
whenToStop: 14 + username.length
whenToStop: 17 + username.length
});
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) {
......
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