Commit dbab88260a4eb4ea322141bcf15beafc1dfdb052

Authored by Cleverson Sacramento
1 parent 18de4770
Exists in master

FWK-196: Melhorias na organização do código-fonte gerado pelo arquétipo

demoiselle-html-rest 

Task-Url: https://demoiselle.atlassian.net/browse/FWK-196
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/Api.java 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +package ${package}.rest;
  2 +
  3 +import javax.ws.rs.ApplicationPath;
  4 +import javax.ws.rs.core.Application;
  5 +
  6 +@ApplicationPath("api")
  7 +public class Api extends Application {
  8 +
  9 +}
... ...
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/AuthREST.java
... ... @@ -27,10 +27,10 @@ public class AuthREST {
27 27 @ValidatePayload
28 28 @Produces("application/json")
29 29 @Consumes("application/json")
30   - public void login(CredentialsForm form) {
  30 + public void login(CredentialsData data) {
31 31 Credentials credentials = Beans.getReference(Credentials.class);
32   - credentials.setUsername(form.username);
33   - credentials.setPassword(form.password);
  32 + credentials.setUsername(data.username);
  33 + credentials.setPassword(data.password);
34 34  
35 35 securityContext.login();
36 36 }
... ... @@ -42,7 +42,7 @@ public class AuthREST {
42 42 return securityContext.getUser();
43 43 }
44 44  
45   - public static class CredentialsForm {
  45 + public static class CredentialsData {
46 46  
47 47 @NotNull(message = "{required.field}")
48 48 @Size(min = 1, message = "{required.field}")
... ...
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/RESTApp.java
... ... @@ -1,9 +0,0 @@
1   -package ${package}.rest;
2   -
3   -import javax.ws.rs.ApplicationPath;
4   -import javax.ws.rs.core.Application;
5   -
6   -@ApplicationPath("api")
7   -public class RESTApp extends Application {
8   -
9   -}
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js
... ... @@ -22,11 +22,15 @@ $(function() {
22 22 function make_base_auth(user, password) {
23 23 var tok = user + ':' + password;
24 24 var hash = btoa(tok);
25   - return "Basic " + hash;
  25 + return hash;
26 26 }
27 27  
28 28 function loginOk(data) {
29   - App.setToken(make_base_auth($("#username").val().trim(), $("#password").val().trim()));
  29 + var username = $("#username").val().trim();
  30 + var password = $("#password").val().trim();
  31 + var encoded = btoa(username + ':' + password);
  32 +
  33 + App.setToken(encoded);
30 34 location.href = "home.html";
31 35 }
32 36  
... ...
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/lib/app.js
... ... @@ -5,6 +5,7 @@ $.ajaxSetup({
5 5 bootbox.alert("Você não está autenticado!", function() {
6 6 location.href = "login.html";
7 7 });
  8 +
8 9 break;
9 10 }
10 11 }
... ... @@ -12,7 +13,7 @@ $.ajaxSetup({
12 13  
13 14 var App = {
14 15  
15   - tokenKey : "credentials",
  16 + tokenKey : "Token",
16 17  
17 18 getToken : function() {
18 19 return sessionStorage.getItem(this.tokenKey);
... ... @@ -22,6 +23,10 @@ var App = {
22 23 sessionStorage.setItem(this.tokenKey, token);
23 24 },
24 25  
  26 + setHeader : function(request) {
  27 + request.setRequestHeader("Authorization", "Basic " + App.getToken());
  28 + },
  29 +
25 30 removeToken : function() {
26 31 sessionStorage.removeItem(this.tokenKey);
27 32 }
... ...