Skip to content

Commit 598e9cd

Browse files
author
eznedan
committed
Merge branch 'instances' of https://github.com/ned29/eiffel-intelligence-frontend into instances
2 parents 9a81ce8 + 2c46b72 commit 598e9cd

File tree

7 files changed

+326
-219
lines changed

7 files changed

+326
-219
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.github.ericsson</groupId>
55
<artifactId>eiffel-intelligence-frontend</artifactId>
6-
<version>0.0.5</version>
6+
<version>0.0.6</version>
77
<packaging>war</packaging>
88

99
<parent>

src/main/java/com/ericsson/ei/frontend/EIRequestsController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class EIRequestsController {
5252
* Bridge authorized EI Http Requests with GET method. Used for login and logout
5353
*/
5454
@CrossOrigin
55-
@RequestMapping(value = "/auth/*", method = RequestMethod.GET)
55+
@RequestMapping(value = "/auth/login", method = RequestMethod.GET)
5656
public ResponseEntity<String> getAuthRequests(Model model, HttpServletRequest request) {
5757
String eiBackendAddressSuffix = request.getServletPath();
5858
String newRequestUrl = getEIBackendSubscriptionAddress() + eiBackendAddressSuffix;
@@ -81,8 +81,8 @@ public ResponseEntity<String> getAuthRequests(Model model, HttpServletRequest re
8181
* Subscription by id or all subscriptions and EI Env Info.
8282
*/
8383
@CrossOrigin
84-
@RequestMapping(value = {"/subscriptions", "/subscriptions/*", "/information",
85-
"/download/subscriptiontemplate"}, method = RequestMethod.GET)
84+
@RequestMapping(value = { "/subscriptions", "/subscriptions/*", "/information", "/auth",
85+
"/auth/checkStatus", "/auth/logout", "/download/*" }, method = RequestMethod.GET)
8686
public ResponseEntity<String> getRequests(Model model, HttpServletRequest request) {
8787
String eiBackendAddressSuffix = request.getServletPath();
8888
String newRequestUrl = getEIBackendSubscriptionAddress() + eiBackendAddressSuffix;
@@ -191,7 +191,7 @@ private String getEIBackendSubscriptionAddress() {
191191

192192
private ResponseEntity<String> getResponse(HttpRequestBase request) {
193193
String jsonContent = "";
194-
int statusCode = 0;
194+
int statusCode = 102;
195195
try (CloseableHttpResponse eiResponse = client.execute(request)) {
196196
InputStream inStream = eiResponse.getEntity().getContent();
197197
BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));

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

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
11

22
jQuery(document).ready(function() {
33

4-
// /Start ## Global AJAX Sender function ##################################
5-
var AjaxHttpSender = function () {};
6-
7-
AjaxHttpSender.prototype.sendAjax = function (url, type, token, callback) {
8-
$.ajax({
9-
url : url,
10-
type : type,
11-
contentType : 'application/json; charset=utf-8',
12-
cache: false,
13-
beforeSend : function (request) {
14-
callback.beforeSend(request, token);
15-
},
16-
error : function (XMLHttpRequest, textStatus, errorThrown) {
17-
callback.error(XMLHttpRequest, errorThrown);
18-
},
19-
success : function (responseData, textStatus) {
20-
callback.success(responseData);
21-
},
22-
complete : function (XMLHttpRequest, textStatus) {
23-
callback.complete();
24-
}
25-
});
26-
}
27-
// /Stop ## Global AJAX Sender function ##################################
28-
29-
// /Start ## Cookies functions ###########################################
30-
function setCookie(name, value) {
31-
var expiry = new Date(new Date().getTime() + 1800 * 1000); // plus 30 min
32-
if(window.location.protocol == "https:") {
33-
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString() + "; secure; HttpOnly";
34-
} else {
35-
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
36-
}
37-
}
38-
39-
function getCookie(name) {
40-
var re = new RegExp(name + "=([^;]+)");
41-
var value = re.exec(document.cookie);
42-
return (value != null) ? unescape(value[1]) : null;
43-
}
44-
// /Stop ## Cookies functions ############################################
45-
464
// /Start ## Knockout ####################################################
475
function loginModel() {
486
this.userState = {
@@ -52,28 +10,6 @@ jQuery(document).ready(function() {
5210
this.remember = ko.observable(false);
5311

5412
this.login = function(userState, remember) {
55-
var callback = {
56-
beforeSend : function (xhr, data) {
57-
xhr.setRequestHeader("Authorization", "Basic " + token);
58-
},
59-
success : function (data) {
60-
var currentUser = JSON.parse(ko.toJSON(data)).user;
61-
$.jGrowl("Welcome " + currentUser, {
62-
sticky : false,
63-
theme : 'Notify'
64-
});
65-
doIfUserLoggedIn(currentUser);
66-
$("#mainFrame").load("subscriptionpage.html");
67-
},
68-
error : function (XMLHttpRequest, errorThrown) {
69-
$.jGrowl("Bad credentials", {
70-
sticky : false,
71-
theme : 'Error'
72-
});
73-
},
74-
complete : function () {}
75-
};
76-
7713
var dataJSON = ko.toJSON(userState);
7814
if(JSON.parse(dataJSON).username == "" || JSON.parse(dataJSON).password == "") {
7915
$.jGrowl("Username and password fields cannot be empty", {
@@ -82,12 +18,33 @@ jQuery(document).ready(function() {
8218
});
8319
} else {
8420
var token = window.btoa(JSON.parse(dataJSON).username + ":" + JSON.parse(dataJSON).password);
85-
var ajaxHttpSender = new AjaxHttpSender();
86-
ajaxHttpSender.sendAjax("/auth/login", "GET", token, callback);
21+
sendLoginRequest("/auth/login", "GET", token);
8722
}
8823
}
8924
}
9025

26+
function sendLoginRequest (url, type, token) {
27+
$.ajax({
28+
url : url,
29+
type : type,
30+
contentType : 'application/json; charset=utf-8',
31+
cache: false,
32+
beforeSend : function (request) {
33+
request.setRequestHeader("Authorization", "Basic " + token);
34+
},
35+
error : function (request, textStatus, errorThrown) {
36+
$.jGrowl("Bad credentials", { sticky : false, theme : 'Error' });
37+
},
38+
success : function (responseData, textStatus) {
39+
var currentUser = JSON.parse(ko.toJSON(responseData)).user;
40+
$.jGrowl("Welcome " + currentUser, { sticky : false, theme : 'Notify' });
41+
doIfUserLoggedIn(currentUser);
42+
$("#mainFrame").load("subscriptionpage.html");
43+
},
44+
complete : function (request, textStatus) { }
45+
});
46+
}
47+
9148
function doIfUserLoggedIn(name) {
9249
localStorage.removeItem("currentUser");
9350
localStorage.setItem("currentUser", name);
@@ -102,4 +59,21 @@ jQuery(document).ready(function() {
10259
ko.applyBindings(model, observableObject);
10360
// /Stop ## Knockout #####################################################
10461

62+
// /Start ## Cookies functions ###########################################
63+
function setCookie(name, value) {
64+
var expiry = new Date(new Date().getTime() + 1800 * 1000); // plus 30 min
65+
if(window.location.protocol == "https:") {
66+
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString() + "; secure; HttpOnly";
67+
} else {
68+
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
69+
}
70+
}
71+
72+
function getCookie(name) {
73+
var re = new RegExp(name + "=([^;]+)");
74+
var value = re.exec(document.cookie);
75+
return (value != null) ? unescape(value[1]) : null;
76+
}
77+
// /Stop ## Cookies functions ############################################
78+
10579
});

0 commit comments

Comments
 (0)