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

Commit bc70e71

Browse files
authored
show long code expiry in UI on code check (#458)
* show long code expiry in UI on code check * review comments
1 parent d20117b commit bc70e71

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

cmd/server/assets/codestatus/show.html

+16
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ <h5 class="mb-1">Status</h5>
4242
<h5 class="mb-1">Expiry</h5>
4343
<span id="code-expires-at" class="sm text-danger"></span>
4444
</div>
45+
{{if .code.HasLongExpires}}
46+
<div class="list-group-item">
47+
<h5 class="mb-1">SMS link expiry</h5>
48+
<span id="long-code-expires-at" class="sm text-danger"></span>
49+
</div>
50+
{{end}}
4551
<div class="card-body">
4652
<a href="/code/{{.code.UUID}}/expire" class="d-block text-danger" data-method="PATCH"
4753
data-confirm="Are you sure you want to expire this code?" data-toggle="tooltip" title="Expire code">
@@ -59,14 +65,24 @@ <h5 class="mb-1">Expiry</h5>
5965
<script type="text/javascript">
6066
let $buttonInvalidate = $('button#invalidate');
6167
let expires = {{ .code.Expires }};
68+
let longExpires = {{ .code.LongExpires }}
6269

6370
$(function() {
6471
let $codeExpiresAt = $('#code-expires-at');
6572
// Start countdown
6673
countdown($codeExpiresAt, expires, function() {
74+
{{if not .code.HasLongExpires}}
6775
// Disable the submit if already expired.
6876
$buttonInvalidate.prop('disabled', true);
77+
{{end}}
78+
});
79+
80+
{{if .code.HasLongExpires}}
81+
let $longCodeExpiresAt = $('#long-code-expires-at');
82+
countdown($longCodeExpiresAt, longExpires, function() {
83+
$buttonInvalidate.prop('disabled', true);
6984
});
85+
{{end}}
7086
});
7187
</script>
7288
</body>

pkg/controller/codestatus/show.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ func (c *Controller) responseCode(ctx context.Context, r *http.Request, code *da
9191
}
9292
if !code.IsExpired() {
9393
retCode.Expires = code.ExpiresAt.UTC().Unix()
94+
retCode.LongExpires = code.LongExpiresAt.UTC().Unix()
95+
retCode.HasLongExpires = retCode.LongExpires > retCode.Expires
9496
}
9597
}
9698

@@ -149,12 +151,14 @@ func (c *Controller) getAuthAppName(ctx context.Context, r *http.Request, id uin
149151
}
150152

151153
type Code struct {
152-
UUID string `json:"uuid"`
153-
Status string `json:"status"`
154-
TestType string `json:"testType"`
155-
IssuerType string `json:"issuerType"`
156-
Issuer string `json:"issuer"`
157-
Expires int64 `json:"expires"`
154+
UUID string `json:"uuid"`
155+
Status string `json:"status"`
156+
TestType string `json:"testType"`
157+
IssuerType string `json:"issuerType"`
158+
Issuer string `json:"issuer"`
159+
Expires int64 `json:"expires"`
160+
LongExpires int64 `json:"longExpires"`
161+
HasLongExpires bool `json:"hasLongExpires"`
158162
}
159163

160164
func (c *Controller) renderShow(ctx context.Context, w http.ResponseWriter, code Code) {

pkg/database/vercode.go

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (v *VerificationCode) IsExpired() bool {
141141
return v.ExpiresAt.Before(now) && v.LongExpiresAt.Before(now)
142142
}
143143

144+
func (v *VerificationCode) HasLongExpiration() bool {
145+
return v.LongExpiresAt.After(v.ExpiresAt)
146+
}
147+
144148
// Validate validates a verification code before save.
145149
func (v *VerificationCode) Validate(maxAge time.Duration) error {
146150
now := time.Now()

0 commit comments

Comments
 (0)