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 1c6cb4e..0f911e4 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Account.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Account.java @@ -24,8 +24,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import jdk.jshell.execution.LoaderDelegate; import org.ntlab.acanthus_server.models.Gallery; +import javax.xml.crypto.Data; +import java.text.DateFormat; +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.UUID; @@ -54,6 +61,9 @@ private String password; @JsonIgnore private boolean isDummy; + @JsonIgnore + private LocalDateTime lastAccess; + //----------------------------------------------------------------- //コンストラクト @@ -63,6 +73,7 @@ //----------------------------------------------------------------- public Account(Integer uid, String name, String email, String password) { + this.isDummy = false; this.uid = uid; this.name = name; this.email = email; @@ -115,6 +126,7 @@ return (this.token); } + public HashMap getWorkHashMap() { return this.workHashMap; } @@ -149,7 +161,7 @@ //----------------------------------------------------------------- //----------------------------------------------------------------- - // トークンを更新する 藤井 + // トークンを更新する public void updateToken() { if (!isDummy) this.token = UUID.randomUUID().toString(); } @@ -159,7 +171,20 @@ public boolean isMatchedPassword(String password) { return this.password.equals(password); } + //----------------------------------------------------------------- + // トークンのチェック + public boolean isCollectToken(String token){ + var timeoutThreshold = 3; + var nowDateTime = LocalDateTime.now(); + if(lastAccess==null) lastAccess = nowDateTime; + + // 時刻比較 + var duration = Duration.between(lastAccess, nowDateTime).toHours(); + if(duration > timeoutThreshold) return false; + + return token.equals(this.token); + } //----------------------------------------------------------------- //----------------------------------------------------------------- // ダミー @@ -170,6 +195,9 @@ this.email = "d@dummy.com"; this.password = "nittalab"; this.token = "abc"; + this.lastAccess = LocalDateTime.now(); + + //this.lastAccess = LocalDateTime.of(2015, 12, 15, 0, 0); } //----------------------------------------------------------------- } diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Animation.java b/src/main/java/org/ntlab/acanthus_server/entities/Animation.java index 494ef4f..de76cd7 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Animation.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Animation.java @@ -30,8 +30,8 @@ this.createdDate = dt.toString(); this.isPublic = false; this.owner = owner; - //this.editors.add(new Editor(owner)); - //this.pageMap.put(0, 0); + this.editors.add(new Editor(owner)); + this.pageMap.put(0, 0); } private Gallery gallery = Gallery.getInstance(); diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Position.java b/src/main/java/org/ntlab/acanthus_server/entities/Position.java index 6ba3e62..d1c638d 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Position.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Position.java @@ -7,17 +7,19 @@ import java.util.UUID; public class Position { - private HashMap positionMap = new HashMap<>(); - private ArrayList> positionList = new ArrayList<>(); + private float x; + private float y; - public void putPosition(Integer x, Integer y) { - this.positionMap.put("x", x); - this.positionMap.put("y", y); - this.positionList.add(this.positionMap); + public float getX() { + return x; + } + public float getY() { + return y; } - public ArrayList> getPosition() { - return this.positionList; + public void setXY(float x, float y) { + this.x = x; + this.y = y; } } diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java b/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java index df0b6b6..140d96d 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Stroke.java @@ -2,17 +2,43 @@ import java.util.ArrayList; import java.util.HashMap; +import org.ntlab.acanthus_server.resources.gallery.StrokesRest; +import org.ntlab.acanthus_server.entities.Position; public class Stroke { - private HashMap strokeMap = new HashMap<>(); - private ArrayList> strokeList = new ArrayList<>(); + private int pen; + private int color; + private int thickness; + private ArrayList positions = new ArrayList<>(); - public void putStroke(String type, Integer value) { - this.strokeMap.put(type, value); + public int getPen() { + return this.pen; + } + public int getColor() { + return this.color; + } + public int getThickness() { + return this.thickness; } - public ArrayList> getStrokeRest() { - this.strokeList.add(this.strokeMap); - return this.strokeList; + public void setStrokes(int pen, int color, int thickness) { + this.pen = pen; + this.color = color; + this.thickness = thickness; } + } + + + +// private ArrayList> strokeList = new ArrayList<>(); +// +// public void putStroke(String type, Integer value) { +// this.strokeMap.put(type, value); +// } +// +// public ArrayList> getStrokeRest() { +// this.strokeList.add(this.strokeMap); +// return this.strokeList; +// } +//} 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 61429c2..7b5ec21 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 @@ -73,7 +73,7 @@ } // トークンを検証し, 発見したユーザーを返却 - if (!token.equals(searchAccount.getToken())){ + if (!searchAccount.isCollectToken(token)){ response = Response.status(400).entity("トークンが違います。"); throw new WebApplicationException(response.build()); } 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 95e9411..2312415 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 @@ -38,7 +38,7 @@ response.status(404).entity(false); throw new WebApplicationException(response.build()); } - if (!token.equals(searchAccount.getToken())) response.status(400).entity(false); + if (!searchAccount.isCollectToken(token)) response.status(400).entity(false); else return true; throw new WebApplicationException(response.build()); diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java index e8bef76..8620b88 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/StrokesRest.java @@ -16,6 +16,7 @@ @Path("/gallery") public class StrokesRest { private Position Position = new Position(); + private ArrayList positions = new ArrayList<>(); private Stroke Test = new Stroke(); /* @@ -28,12 +29,8 @@ @Path("/{aid}/pageMap/0/layers/0/strokes") @GET @Produces(MediaType.APPLICATION_JSON) - public ArrayList> getStrokeRest(@PathParam("aid") Integer aid) { - this.Test.putStroke("strokeNo", 2); - this.Test.putStroke("pen", 3); - this.Test.putStroke("color", 5); - this.Test.putStroke("thickness", 1); - return this.Test.getStrokeRest(); + public Stroke getStrokeRest(@PathParam("aid") Integer aid) { + return this.Test; } /* @@ -48,9 +45,9 @@ @Path("/{aid}/pageMap/0/layers/0/strokes") @POST @Produces(MediaType.APPLICATION_JSON) - public String addStrokes(@PathParam("aid") Integer aid, @FormParam("uid") Integer uid, @FormParam("uidToken") Integer uidToken, + public void addStrokes(@PathParam("aid") Integer aid, @FormParam("uid") Integer uid, @FormParam("uidToken") Integer uidToken, @FormParam("pen") Integer pen, @FormParam("color") Integer color, @FormParam("thick") Integer thick) { - return null; + this.Test.setStrokes(pen, color, thick); } /* @@ -61,8 +58,8 @@ @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/position") @GET @Produces(MediaType.APPLICATION_JSON) - public ArrayList> getPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo) { - return this.Position.getPosition(); + public ArrayList getPositions(@PathParam("aid") Integer aid, @PathParam("strokeNo") Integer strokeNo) { + return this.positions; } /* @@ -74,8 +71,9 @@ @Path("/{aid}/pageMap/0/layers/0/strokes/{strokeNo}/position") @POST @Produces(MediaType.APPLICATION_JSON) - public void addPositions(@PathParam("aid") Integer aid, @FormParam("x") Integer x, @FormParam("y") Integer y) { - this.Position.putPosition(x, y); + public void addPositions(@PathParam("aid") Integer aid, @FormParam("x") Float x, @FormParam("y") Float y) { + this.Position.setXY(x, y); + this.positions.add(this.Position); } }