diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/Api.java b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/Api.java
new file mode 100644
index 0000000..25c5051
--- /dev/null
+++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/Api.java
@@ -0,0 +1,9 @@
+package ${package}.rest;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("api")
+public class Api extends Application {
+
+}
diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java
index 5d79074..8485a5d 100644
--- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java
+++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java
@@ -27,10 +27,10 @@ public class AuthREST {
@ValidatePayload
@Produces("application/json")
@Consumes("application/json")
- public void login(CredentialsForm form) {
+ public void login(CredentialsData data) {
Credentials credentials = Beans.getReference(Credentials.class);
- credentials.setUsername(form.username);
- credentials.setPassword(form.password);
+ credentials.setUsername(data.username);
+ credentials.setPassword(data.password);
securityContext.login();
}
@@ -42,7 +42,7 @@ public class AuthREST {
return securityContext.getUser();
}
- public static class CredentialsForm {
+ public static class CredentialsData {
@NotNull(message = "{required.field}")
@Size(min = 1, message = "{required.field}")
diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/RESTApp.java b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/RESTApp.java
deleted file mode 100644
index 4130960..0000000
--- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/RESTApp.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package ${package}.rest;
-
-import javax.ws.rs.ApplicationPath;
-import javax.ws.rs.core.Application;
-
-@ApplicationPath("api")
-public class RESTApp extends Application {
-
-}
diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js
index 913dc62..d851127 100644
--- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js
+++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js
@@ -22,11 +22,15 @@ $(function() {
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
- return "Basic " + hash;
+ return hash;
}
function loginOk(data) {
- App.setToken(make_base_auth($("#username").val().trim(), $("#password").val().trim()));
+ var username = $("#username").val().trim();
+ var password = $("#password").val().trim();
+ var encoded = btoa(username + ':' + password);
+
+ App.setToken(encoded);
location.href = "home.html";
}
diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js
index d32e07f..5ccdcbd 100644
--- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js
+++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js
@@ -5,6 +5,7 @@ $.ajaxSetup({
bootbox.alert("Você não está autenticado!", function() {
location.href = "login.html";
});
+
break;
}
}
@@ -12,7 +13,7 @@ $.ajaxSetup({
var App = {
- tokenKey : "credentials",
+ tokenKey : "Token",
getToken : function() {
return sessionStorage.getItem(this.tokenKey);
@@ -22,6 +23,10 @@ var App = {
sessionStorage.setItem(this.tokenKey, token);
},
+ setHeader : function(request) {
+ request.setRequestHeader("Authorization", "Basic " + App.getToken());
+ },
+
removeToken : function() {
sessionStorage.removeItem(this.tokenKey);
}
--
libgit2 0.21.2