Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ARI
AEON Dashboard
Commits
b27def8a
Commit
b27def8a
authored
Feb 12, 2019
by
José Gato Luis
Browse files
Merge branch 'development' of gitlab.atosresearch.eu:ari/aeon-dashboard into development
parents
4a6a3342
5126358f
Pipeline
#7112
passed with stages
in 1 minute and 39 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
app/controllers/keycloakCtrl.js
View file @
b27def8a
...
...
@@ -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
;
...
...
app/controllers/keycloakSignUpCtrl.js
View file @
b27def8a
...
...
@@ -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
app/controllers/services.js
View file @
b27def8a
...
...
@@ -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
"
,
"
b
earer
"
+
token
.
token
);
myHeaders
.
append
(
"
Authorization
"
,
"
B
earer
"
+
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
...
...
package.json
View file @
b27def8a
...
...
@@ -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"
}]
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment