Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
show long code expiry in UI on code check (#458)
Browse files Browse the repository at this point in the history
* show long code expiry in UI on code check

* review comments
  • Loading branch information
mikehelmick authored Sep 2, 2020
1 parent d20117b commit bc70e71
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
16 changes: 16 additions & 0 deletions cmd/server/assets/codestatus/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ <h5 class="mb-1">Status</h5>
<h5 class="mb-1">Expiry</h5>
<span id="code-expires-at" class="sm text-danger"></span>
</div>
{{if .code.HasLongExpires}}
<div class="list-group-item">
<h5 class="mb-1">SMS link expiry</h5>
<span id="long-code-expires-at" class="sm text-danger"></span>
</div>
{{end}}
<div class="card-body">
<a href="/code/{{.code.UUID}}/expire" class="d-block text-danger" data-method="PATCH"
data-confirm="Are you sure you want to expire this code?" data-toggle="tooltip" title="Expire code">
Expand All @@ -59,14 +65,24 @@ <h5 class="mb-1">Expiry</h5>
<script type="text/javascript">
let $buttonInvalidate = $('button#invalidate');
let expires = {{ .code.Expires }};
let longExpires = {{ .code.LongExpires }}

$(function() {
let $codeExpiresAt = $('#code-expires-at');
// Start countdown
countdown($codeExpiresAt, expires, function() {
{{if not .code.HasLongExpires}}
// Disable the submit if already expired.
$buttonInvalidate.prop('disabled', true);
{{end}}
});

{{if .code.HasLongExpires}}
let $longCodeExpiresAt = $('#long-code-expires-at');
countdown($longCodeExpiresAt, longExpires, function() {
$buttonInvalidate.prop('disabled', true);
});
{{end}}
});
</script>
</body>
Expand Down
16 changes: 10 additions & 6 deletions pkg/controller/codestatus/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/database/vercode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bc70e71

Please sign in to comment.