Commit dbab88260a4eb4ea322141bcf15beafc1dfdb052
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
Showing
5 changed files
with
25 additions
and
16 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/Api.java
0 → 100644
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
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 | } | ... | ... |