Skip to content
This repository was archived by the owner on Apr 22, 2022. It is now read-only.

Commit c1e369e

Browse files
jjjj
authored andcommitted
Merged with authorization branch
1 parent be80188 commit c1e369e

File tree

5 files changed

+134
-12
lines changed

5 files changed

+134
-12
lines changed

src/main/webapp/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ <h5 class="modal-title green bold">Restore password</h5>
154154

155155
<script src="lib/bootstrap/bootstrap.js"></script>
156156
<script src="lib/angularjs/angular.js"></script>
157-
<script src="lib/angularjs/angular-route.js">
157+
<script src="lib/angularjs/angular-cookies.js"></script>
158+
<script src="lib/angularjs/angular-route.js"></script>
158159
<script src="lib/modal-master/bootstrap-modal.js"></script>
159160
<script src="lib/modal-master/bootstrap-modalmanager.js"></script>
160161
<script src="js/config.js"></script>

src/main/webapp/js/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
var app = angular.module('app', ['ngRoute',
3+
var app = angular.module('app', ['ngRoute',
4+
'ngCookies',
45
'app.services',
56
'app.directives',
67
'app.configuration',

src/main/webapp/js/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ angular.module("app.configuration", [])
3333
{
3434
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
3535

36-
var ENDPOINT = "http://localhost:8890/sparql-auth";
37-
var PUBLIC_ENDPOINT = "http://localhost:8890/sparql";
36+
var ENDPOINT = "http://generator.geoknow.eu:8890/sparql-auth";
37+
var PUBLIC_ENDPOINT = "http://generator.geoknow.eu:8890/sparql";
3838
// if new resorces are created they will use this name space, and it can be changed
3939
var NS = "http://generator.geoknow.eu/resource/";
40-
// this is the graph where settings are stored, it doesnt change, and independent on the Namespace
40+
// this is the graph where settings are stored, it doesnt change, and independent on the Namespace
4141
var DEFAULT_GRAPH_URI = "http://generator.geoknow.eu/resource/settingsGraph";
4242
var GRAPH_URI = DEFAULT_GRAPH_URI;
4343
var GROUPS_GRAPH_URI = "http://generator.geoknow.eu/resource/graphGroups";

src/main/webapp/js/controllers.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,28 @@ function StackMenuCtrl($scope) {
7373
}
7474

7575

76-
function LoginCtrl($scope, flash, AccountService, LoginService, ServerErrorResponse) {
76+
function LoginCtrl($scope, flash, AccountService, LoginService, ServerErrorResponse, Base64) {
7777
$scope.currentAccount = angular.copy(AccountService.getAccount());
78+
if($scope.currentAccount.user != null){
79+
LoginService.login($scope.currentAccount.user, $scope.currentAccount.pass)
80+
.then(function(data) {
81+
$scope.currentAccount = angular.copy(AccountService.getAccount());
82+
$scope.login.username = null;
83+
$scope.login.password = null;
84+
}, function(response) {
85+
flash.error = ServerErrorResponse.getMessage(response.status);
86+
$scope.login.username = null;
87+
$scope.login.password = null;
88+
});
89+
}
7890

7991
$scope.login = {
8092
username : null,
81-
password : null
82-
};
93+
password : null //$scope.currentAccount.user, $scope.currentAccount.pass
94+
};
8395

8496
$scope.login = function() {
85-
LoginService.login($scope.login.username, $scope.login.password)
97+
LoginService.login(Base64.encode($scope.login.username), Base64.encode($scope.login.password))
8698
.then(function(data) {
8799
$scope.currentAccount = angular.copy(AccountService.getAccount());
88100
$scope.login.username = null;

src/main/webapp/js/services.js

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,92 @@ module.factory('ConfigurationService', function(Config, AccountService) {
535535
return SettingsService;
536536
});
537537

538-
module.factory("AccountService", function() {
538+
module.factory('Base64', function() {
539+
var keyStr = 'ABCDEFGHIJKLMNOP' +
540+
'QRSTUVWXYZabcdef' +
541+
'ghijklmnopqrstuv' +
542+
'wxyz0123456789+/' +
543+
'=';
544+
return {
545+
encode: function (input) {
546+
var output = "";
547+
var chr1, chr2, chr3 = "";
548+
var enc1, enc2, enc3, enc4 = "";
549+
var i = 0;
550+
551+
do {
552+
chr1 = input.charCodeAt(i++);
553+
chr2 = input.charCodeAt(i++);
554+
chr3 = input.charCodeAt(i++);
555+
556+
enc1 = chr1 >> 2;
557+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
558+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
559+
enc4 = chr3 & 63;
560+
561+
if (isNaN(chr2)) {
562+
enc3 = enc4 = 64;
563+
} else if (isNaN(chr3)) {
564+
enc4 = 64;
565+
}
566+
567+
output = output +
568+
keyStr.charAt(enc1) +
569+
keyStr.charAt(enc2) +
570+
keyStr.charAt(enc3) +
571+
keyStr.charAt(enc4);
572+
chr1 = chr2 = chr3 = "";
573+
enc1 = enc2 = enc3 = enc4 = "";
574+
} while (i < input.length);
575+
576+
return output;
577+
},
578+
579+
decode: function (input) {
580+
var output = "";
581+
var chr1, chr2, chr3 = "";
582+
var enc1, enc2, enc3, enc4 = "";
583+
var i = 0;
584+
585+
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
586+
var base64test = /[^A-Za-z0-9\+\/\=]/g;
587+
if (base64test.exec(input)) {
588+
alert("There were invalid base64 characters in the input text.\n" +
589+
"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
590+
"Expect errors in decoding.");
591+
}
592+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
593+
594+
do {
595+
enc1 = keyStr.indexOf(input.charAt(i++));
596+
enc2 = keyStr.indexOf(input.charAt(i++));
597+
enc3 = keyStr.indexOf(input.charAt(i++));
598+
enc4 = keyStr.indexOf(input.charAt(i++));
599+
600+
chr1 = (enc1 << 2) | (enc2 >> 4);
601+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
602+
chr3 = ((enc3 & 3) << 6) | enc4;
603+
604+
output = output + String.fromCharCode(chr1);
605+
606+
if (enc3 != 64) {
607+
output = output + String.fromCharCode(chr2);
608+
}
609+
if (enc4 != 64) {
610+
output = output + String.fromCharCode(chr3);
611+
}
612+
613+
chr1 = chr2 = chr3 = "";
614+
enc1 = enc2 = enc3 = enc4 = "";
615+
616+
} while (i < input.length);
617+
618+
return output;
619+
}
620+
};
621+
});
622+
623+
module.factory("AccountService", function($cookieStore) {
539624
var username = null;
540625
var accountURI = null;
541626
var email = null;
@@ -577,7 +662,9 @@ module.factory("AccountService", function() {
577662
};
578663

579664
var getAccount = function() {
580-
return {username : username, email : email};
665+
var user = $cookieStore.get('User');
666+
var pass = $cookieStore.get('Pass');
667+
return {username : username, email : email, user: user, pass: pass};
581668
};
582669

583670
var setAdmin = function(adm) {
@@ -603,8 +690,13 @@ module.factory("AccountService", function() {
603690
};
604691
});
605692

606-
module.factory("LoginService", function($http, $location, AccountService, ConfigurationService) {
693+
module.factory("LoginService", function($http, $location, $cookieStore, AccountService, ConfigurationService, Base64) {
694+
607695
var login = function(username, password) {
696+
697+
var username = Base64.decode(username);
698+
var password = Base64.decode(password);
699+
608700
var postData = {
609701
username: username,
610702
password: password,
@@ -621,6 +713,14 @@ module.factory("LoginService", function($http, $location, AccountService, Config
621713
AccountService.setEmail(response.data.email);
622714
AccountService.setAdmin(response.data.admin);
623715
ConfigurationService.setSettingsGraph(response.data.settingsGraph);
716+
717+
var encodedUser = Base64.encode(username);
718+
var encodedPass = Base64.encode(password);
719+
$http.defaults.headers.common.Authorization = 'User ' + encodedUser + ' Pass ' + encodedPass;
720+
$cookieStore.put('User', encodedUser);
721+
$cookieStore.put('Pass', encodedPass);
722+
console.log($http.defaults.headers.common);
723+
624724
}, function(response) {
625725
//todo
626726
});
@@ -640,6 +740,14 @@ module.factory("LoginService", function($http, $location, AccountService, Config
640740
AccountService.clear();
641741
ConfigurationService.restoreDefaultSettingsGraph();
642742
$location.path("/home");
743+
744+
document.execCommand("ClearAuthenticationCache");
745+
$cookieStore.remove('User');
746+
$cookieStore.remove('Pass');
747+
$http.defaults.headers.common.Authorization = 'User Pass';
748+
749+
console.log($http.defaults.headers.common);
750+
643751
}, function(response) {
644752
//todo
645753
});

0 commit comments

Comments
 (0)