Commit 5126358f authored by Alejandro Garcia Marchena's avatar Alejandro Garcia Marchena

Merge branch 'automatic-account-creation-when-user-not-found' into development

parents b6d71a81 792a6ebd
Pipeline #4498 passed with stages
in 1 minute and 48 seconds
......@@ -16,13 +16,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Authors: Javier García Hernández (javier.garcia@atos.net)
Baris Kara (baris.kara@atos.net)
Authors: Alejandro García Marchena (alejandro.garciamarchena.external@atos.net)
*/
/*
Controller for the login
Controller for the login with keycloak
*/
function keycloakCtrl($rootScope, $q, $scope, $location, Authentication, $localStorage, config, $timeout) {
......@@ -34,18 +33,18 @@ function keycloakCtrl($rootScope, $q, $scope, $location, Authentication, $localS
$scope.loginWithKeycloak = function () {
var keycloakObj = JSON.parse(localStorage.getItem('keycloakTokenObj'));
if ($rootScope.sso_enabled) {
var token = keycloakObj;
if (token !== null) {
$scope.user = { "type": "user", "password": "", "username": token.tokenParsed.email }
//Tries to log in the system
Authentication.loginKeycloak($scope.user, token.token).then(function (data) {
//If the user exists, we move him to the main page
Authentication.loginKeycloak($scope.user, token.token).then(function (data) {
//If the user exists, we move him to the main page
if (data.code == 200) {
$rootScope.userIdentified = true
$rootScope.userIdentified = true
//Save the user identifier
$rootScope.userId = $scope.user.username;
$rootScope.userImage = 'img/profile-placeholder.png';
......@@ -55,9 +54,19 @@ function keycloakCtrl($rootScope, $q, $scope, $location, Authentication, $localS
}
//Redirect to the main page
$location.path('/main');
} else if (data.code == 201) {
$location.path('/');
}
},
function (data) { //If user is not defined
/* if the user has an aeolix account in keycloak and click on login,
we receive a response saying that the user account does not exists,
so we create an account for him*/
if(data.code===201 && data.desc==="User does not exist"){
window.location.replace("/app/loginKeycloak.html?action=signup&auth_server_url="+config.keycloak.auth_server_url+"&realm="+config.keycloak.realm+"&clientId="+config.keycloak.dashboard.resource);
}
localStorage.removeItem("keycloakTokenObj");
$rootScope.userIdentified = false;
......
......@@ -28,21 +28,23 @@ function keycloakSignUpCtrl($rootScope, $scope, $location, Users, Authentication
//Redirects to the main view
$scope.signUpWithKeycloak = function () {
console.log("-------------------------------------------");
console.log("signUpWithKeycloak");
console.log("-------------------------------------------");
if ($rootScope.sso_enabled) {
var token = JSON.parse(localStorage.getItem('keycloakTokenObj'));
if (token !== null) {
console.log("token found! "+JSON.stringify(token));
Users.newKcUser(token).then(function (response) {
console.log(response);
console.log("response: "+JSON.stringify(response));
if (response.code == 200) {
console.log("user created");
$location.path('/keycloak')
$rootScope.$apply();
} else if (response.code == 202) {
$location.path('/keycloak')
$rootScope.$apply();
} else if (response.code == 401 || response.code == 403) {
alert("Error al obtener el token de acceso");
$location.path('/main')
......@@ -55,7 +57,6 @@ function keycloakSignUpCtrl($rootScope, $scope, $location, Users, Authentication
});
} else {
console.log("token NOT found!");
$scope.serverDown = false;
$rootScope.actualView = 'views/signUp.html'
$location.path('/')
......@@ -63,9 +64,7 @@ function keycloakSignUpCtrl($rootScope, $scope, $location, Users, Authentication
} else {
$location.path('/')
}
}
var callbackFn = $scope.signUpWithKeycloak;
$timeout(callbackFn, 1000);
}
\ No newline at end of file
......@@ -194,6 +194,8 @@ app.factory('Users', function ($http, $q, $rootScope, config) {
//Creates a new keycloak user
newKcUser: function (token) {
//console.log("token recibido: "+token.token);
var deferred = $q.defer();
//Set up the headers
......@@ -201,7 +203,7 @@ app.factory('Users', function ($http, $q, $rootScope, config) {
var url = "//" + config.AEON_HOST + ":" + config.AEON_PORT + "/userskc";
//----------
var myHeaders = new Headers();
myHeaders.append("Authorization", "bearer " + token.token);
myHeaders.append("Authorization", "Bearer " + token.token);
myHeaders.append("Content-Type", "application/json");
var myInit = {
method: 'POST',
......@@ -221,6 +223,7 @@ app.factory('Users', function ($http, $q, $rootScope, config) {
}).catch(function (err) {
return err;
});
},
//Gets user info
......
......@@ -15,12 +15,15 @@
"engines": {
"node": "6.10.x",
"npm": "3.10.x"
},
},
"contributors": [{
"name": "Javier Garcia Hernandez",
"email": "javier.garcia@atos.net"
}, {
"name": "Baris Kara",
"email": "baris.kara@atos.net"
}, {
"name": "Alex García",
"email": "alejandro.garciamarchena.external@atos.net"
}]
}
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