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

show long code expiry in UI on code check #458

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do-da-do---do, da-da-do-do-do, do-da-do---do...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you ok?

also - I made this better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really hard to put musical intonation into words. I was going for: https://www.youtube.com/watch?v=9jK-NcRmVcw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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