From bc70e71693e93c2a79e1a6e7beae0a963da9b70c Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Wed, 2 Sep 2020 11:23:18 -0700 Subject: [PATCH] show long code expiry in UI on code check (#458) * show long code expiry in UI on code check * review comments --- cmd/server/assets/codestatus/show.html | 16 ++++++++++++++++ pkg/controller/codestatus/show.go | 16 ++++++++++------ pkg/database/vercode.go | 4 ++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cmd/server/assets/codestatus/show.html b/cmd/server/assets/codestatus/show.html index 83aba3aa8..f9e5f2841 100644 --- a/cmd/server/assets/codestatus/show.html +++ b/cmd/server/assets/codestatus/show.html @@ -42,6 +42,12 @@
Status
Expiry
+ {{if .code.HasLongExpires}} +
+
SMS link expiry
+ +
+ {{end}}
@@ -59,14 +65,24 @@
Expiry
diff --git a/pkg/controller/codestatus/show.go b/pkg/controller/codestatus/show.go index 5a34555d6..94e24f073 100644 --- a/pkg/controller/codestatus/show.go +++ b/pkg/controller/codestatus/show.go @@ -91,6 +91,8 @@ func (c *Controller) responseCode(ctx context.Context, r *http.Request, code *da } if !code.IsExpired() { retCode.Expires = code.ExpiresAt.UTC().Unix() + retCode.LongExpires = code.LongExpiresAt.UTC().Unix() + retCode.HasLongExpires = retCode.LongExpires > retCode.Expires } } @@ -149,12 +151,14 @@ func (c *Controller) getAuthAppName(ctx context.Context, r *http.Request, id uin } type Code struct { - UUID string `json:"uuid"` - Status string `json:"status"` - TestType string `json:"testType"` - IssuerType string `json:"issuerType"` - Issuer string `json:"issuer"` - Expires int64 `json:"expires"` + UUID string `json:"uuid"` + Status string `json:"status"` + TestType string `json:"testType"` + IssuerType string `json:"issuerType"` + Issuer string `json:"issuer"` + Expires int64 `json:"expires"` + LongExpires int64 `json:"longExpires"` + HasLongExpires bool `json:"hasLongExpires"` } func (c *Controller) renderShow(ctx context.Context, w http.ResponseWriter, code Code) { diff --git a/pkg/database/vercode.go b/pkg/database/vercode.go index b161d01a3..8979e0eaf 100644 --- a/pkg/database/vercode.go +++ b/pkg/database/vercode.go @@ -141,6 +141,10 @@ func (v *VerificationCode) IsExpired() bool { return v.ExpiresAt.Before(now) && v.LongExpiresAt.Before(now) } +func (v *VerificationCode) HasLongExpiration() bool { + return v.LongExpiresAt.After(v.ExpiresAt) +} + // Validate validates a verification code before save. func (v *VerificationCode) Validate(maxAge time.Duration) error { now := time.Now()