Skip to content

Commit 35245c2

Browse files
Fix login blocks and username on backend status (#117)
* Fix login and username enabled/disabled on backend status
1 parent 08700e1 commit 35245c2

File tree

6 files changed

+70
-69
lines changed

6 files changed

+70
-69
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var frontendServiceUrl = $('#frontendServiceUrl').text();
2+
3+
function doIfUserLoggedIn(user) {
4+
localStorage.removeItem("currentUser");
5+
localStorage.setItem("currentUser", user);
6+
$("#ldapUserName").show();
7+
$("#ldapUserName").text(user);
8+
$("#loginBlock").hide();
9+
$("#logoutBlock").show();
10+
$(".show_if_authorized").show();
11+
}
12+
13+
function doIfUserLoggedOut() {
14+
localStorage.removeItem("currentUser");
15+
$("#ldapUserName").show();
16+
$("#ldapUserName").text("Guest");
17+
$("#loginBlock").show();
18+
$("#logoutBlock").hide();
19+
$(".show_if_authorized").hide();
20+
localStorage.setItem('errorsStore', []);
21+
}
22+
23+
function doIfSecurityOff() {
24+
$("#ldapUserName").text("");
25+
$("#loginBlock").hide();
26+
$("#logoutBlock").hide();
27+
}
28+
29+
function checkBackendSecured() {
30+
$.ajax({
31+
url: frontendServiceUrl + "/auth",
32+
type: "GET",
33+
contentType: "application/string; charset=utf-8",
34+
error: function (data) {
35+
doIfSecurityOff();
36+
},
37+
success: function (data) {
38+
var isSecured = JSON.parse(ko.toJSON(data)).security;
39+
if (isSecured == true) {
40+
checkLoggedInUser();
41+
} else {
42+
doIfSecurityOff();
43+
}
44+
}
45+
});
46+
}
47+
48+
function checkLoggedInUser() {
49+
$.ajax({
50+
url : frontendServiceUrl + "/auth/login",
51+
type : "GET",
52+
contentType : 'application/string; charset=utf-8',
53+
cache: false,
54+
error : function (request, textStatus, errorThrown) {
55+
doIfUserLoggedOut();
56+
},
57+
success : function (responseData, textStatus) {
58+
var user = JSON.parse(ko.toJSON(responseData)).user;
59+
doIfUserLoggedIn(user);
60+
}
61+
});
62+
}

src/main/resources/static/js/login.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ jQuery(document).ready(function() {
6363
});
6464
}
6565

66-
function doIfUserLoggedIn(name) {
67-
localStorage.removeItem("currentUser");
68-
localStorage.setItem("currentUser", name);
69-
$("#ldapUserName").text(name);
70-
$("#loginBlock").hide();
71-
$("#logoutBlock").show();
72-
}
73-
7466
var observableObject = $("#viewModelDOMObject")[0];
7567
ko.cleanNode(observableObject);
7668
var model = new loginModel();

src/main/resources/static/js/main.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,6 @@ jQuery(document).ready(function() {
7272
});
7373
});
7474

75-
function doIfUserLoggedIn(currentUser) {
76-
localStorage.removeItem("currentUser");
77-
localStorage.setItem("currentUser", currentUser);
78-
$("#ldapUserName").text(currentUser);
79-
$("#logoutBlock").show();
80-
$(".show_if_authorized").show();
81-
}
82-
83-
function doIfUserLoggedOut() {
84-
localStorage.removeItem("currentUser");
85-
$("#ldapUserName").text("Guest");
86-
$("#loginBlock").show();
87-
$("#logoutBlock").hide();
88-
$(".show_if_authorized").hide();
89-
localStorage.setItem('errorsStore', []);
90-
}
91-
9275
function updateBackEndInstanceList() {
9376
$.ajax({
9477
url: frontendServiceUrl + frontendServiceBackEndPath,
@@ -106,37 +89,6 @@ jQuery(document).ready(function() {
10689
});
10790
}
10891

109-
function checkBackendSecured() {
110-
$.ajax({
111-
url: frontendServiceUrl + "/auth",
112-
type: "GET",
113-
contentType: "application/string; charset=utf-8",
114-
error: function (data) {},
115-
success: function (data) {
116-
var isSecured = JSON.parse(ko.toJSON(data)).security;
117-
if (isSecured == true) {
118-
checkLoggedInUser();
119-
}
120-
}
121-
});
122-
}
123-
124-
function checkLoggedInUser() {
125-
$.ajax({
126-
url : frontendServiceUrl + "/auth/login",
127-
type : "GET",
128-
contentType : 'application/string; charset=utf-8',
129-
cache: false,
130-
error : function (request, textStatus, errorThrown) {
131-
doIfUserLoggedOut();
132-
},
133-
success : function (responseData, textStatus) {
134-
var user = JSON.parse(ko.toJSON(responseData)).user;
135-
doIfUserLoggedIn(user);
136-
}
137-
});
138-
}
139-
14092
function loadDocumentLinks(){
14193
// eiffelDocumentationUrlLinks variable is configure in application.properties
14294
var linksList = JSON.parse(eiffelDocumentationUrlLinks);

src/main/resources/static/js/subscription.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ jQuery(document).ready(function () {
6161
EIConnBtn.style.background = green;
6262
backendStatus = true;
6363
} else {
64+
doIfSecurityOff();
6465
EIConnBtn.style.background = red;
6566
backendStatus = false;
6667
}
6768
},
6869
success: function (data, textStatus) {
70+
if(backendStatus == false) {
71+
checkBackendSecured();
72+
}
6973
EIConnBtn.style.background = green;
7074
backendStatus = true;
7175
},
@@ -76,15 +80,6 @@ jQuery(document).ready(function () {
7680
}
7781
checkBackendStatus();
7882

79-
function doIfUserLoggedOut() {
80-
localStorage.removeItem("currentUser");
81-
$("#ldapUserName").text("Guest");
82-
$("#loginBlock").show();
83-
$("#logoutBlock").hide();
84-
$(".show_if_authorized").hide();
85-
localStorage.setItem('errorsStore', []);
86-
}
87-
8883
function loadSubButtons() {
8984
$("#loadingAnimation").hide();
9085
$("#subButtons").show();

src/main/resources/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</ul>
8989
<ul class="navbar-nav ml-auto">
9090
<li class="nav-item dropdown">
91-
<a class="nav-link dropdown-toggle mr-lg-2" id="alertsDropdown">
91+
<a class="nav-link dropdown-toggle" id="alertsDropdown">
9292
<i class="fa fa-fw fa-bell"></i>
9393
<span class="d-lg-none">Alerts
9494
<span class="badge badge-pill badge-warning">6 New</span>
@@ -169,5 +169,6 @@ <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
169169
<script type="text/javascript" src="assets/navigo/7.1.2/navigo.min.js"></script>
170170
<script type="text/javascript" src="js/main.js"></script>
171171
<script type="text/javascript" src="js/errorMessages.js"></script>
172+
<script type="text/javascript" src="js/common.js"></script>
172173
</body>
173174
</html>

src/main/resources/templates/login.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
</head>
1111

1212
<body class="bg-dark">
13-
<div class="hidden" style="display: none" id="frontendServiceUrl" th:text="${frontendServiceUrl}"></div>
14-
<div class="container pull-left">
15-
<div class="card card-login mx-auto mt-5">
13+
<div class="d-flex justify-content-center ml-3 mr-3">
14+
<div class="card card-standard">
1615
<div class="card-header">Login</div>
1716
<div class="card-body">
1817
<form id="viewModelDOMObject" autocomplete="on">

0 commit comments

Comments
 (0)