diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Account.java b/src/main/java/org/ntlab/acanthus_server/entities/Account.java index f59afb1..7be09f3 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Account.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Account.java @@ -21,19 +21,34 @@ package org.ntlab.acanthus_server.entities; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.util.ArrayList; import java.util.HashMap; import java.util.UUID; +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "name", + "email", + "work" +}) + +// public class Account { - private Integer uid; + @JsonProperty("name") private String name; + @JsonProperty("email") private String email; + @JsonProperty("work") private HashMap workHashMap = new HashMap<>(); @JsonIgnore + private Integer uid; + @JsonIgnore private String token; @JsonIgnore private String password; diff --git a/src/main/java/org/ntlab/acanthus_server/entities/AccountJson.java b/src/main/java/org/ntlab/acanthus_server/entities/AccountJson.java index 0726e9c..e306864 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/AccountJson.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/AccountJson.java @@ -1,16 +1,28 @@ package org.ntlab.acanthus_server.entities; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) + //----------------------------------------------------------------- // アカウント一覧取得用のJsonクラス public class AccountJson { + + @JsonProperty("uid") private Integer uid; + @JsonProperty("name") private String name; + @JsonProperty("email") + private String email; //----------------------------------------------------------------- //----------------------------------------------------------------- - public AccountJson(Integer uid, String name){ - this.uid = uid; - this.name = name; + public AccountJson(Account account){ + this.uid = account.getUid(); + this.name = account.getName(); + this.email = account.getEmail(); } //----------------------------------------------------------------- } diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/AccountsRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/AccountsRest.java index 45fbb7a..c8ac315 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/accounts/AccountsRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/AccountsRest.java @@ -20,6 +20,7 @@ // GET //----------------------------------------------------------------- // すべてのアカウント情報を返す + /** * @param name ユーザー名 */ @@ -30,16 +31,16 @@ var accountJsonList = new ArrayList(); // 名前の一致するアカウントを返す - if (name != null){ - for(var account : accounts.getAccountsByName(name)) { - var newAccountJson = new AccountJson(account.getUid(), account.getName()); + if (name != null) { + for (var account : accounts.getAccountsByName(name)) { + var newAccountJson = new AccountJson(account); accountJsonList.add(newAccountJson); } } // 全アカウントの取得 - else{ - for(var account : accounts.getAllAccounts()) { - var newAccountJson = new AccountJson(account.getUid(), account.getName()); + else{ + for (var account : accounts.getAllAccounts()) { + var newAccountJson = new AccountJson(account); accountJsonList.add(newAccountJson); } } @@ -49,9 +50,10 @@ //----------------------------------------------------------------- // Uidで個人のアカウント情報を取得する // 個人情報の開示をするので, トークンあり + /** * @param uidStr ユーザーIDの文字列 - * @param token トークン + * @param token トークン */ @GET @Path("/{uid}") @@ -70,6 +72,7 @@ // POST //----------------------------------------------------------------- // アカウントの新規作成 + /** * @param name ユーザー名 * @param email メアド diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/LoginRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/LoginRest.java index 1faf919..bce300e 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/accounts/LoginRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/LoginRest.java @@ -13,23 +13,25 @@ private Accounts accounts = Accounts.getInstance(); //----------------------------------------------------------- + /** * ログイン時のトークン認証 * アカウントが存在して, かつトークンを持っているかを確認する */ @GET @Produces(MediaType.APPLICATION_JSON) - public boolean hasLoginToken(@QueryParam("uid") int uid, @QueryParam("token") String token) { - + public boolean hasLoginToken(@QueryParam("uid") String uidStr, @QueryParam("token") String token) { + var uid = Integer.parseInt(uidStr); var searchAccount = accounts.getAccountByUid(uid); if (searchAccount == null) throw new WebApplicationException(404); if (!searchAccount.getToken().equals(token)) throw new WebApplicationException(400); - return true; + throw new WebApplicationException(200); } //----------------------------------------------------------- + /** * ログイン時, トークンをアカウントに発行させる * @@ -38,14 +40,15 @@ */ @PUT @Produces(MediaType.APPLICATION_JSON) - public void authenticateLoginToken(@FormParam("e-mail") String email, @FormParam("password") String password) { + public String issueLoginToken(@FormParam("email") String email, @FormParam("password") String password) { var searchAccount = accounts.getAccountByEmail(email); - if (searchAccount == null) throw new WebApplicationException(404); - if (searchAccount.isMatchedPassword(password)) throw new WebApplicationException(401); + if (searchAccount == null) throw new WebApplicationException(400); + if (!searchAccount.isMatchedPassword(password)) throw new WebApplicationException(401); searchAccount.updateToken(); + return searchAccount.getToken(); } //-----------------------------------------------------------