From 91820aabea02580f9245361bfa929910fcc40953 Mon Sep 17 00:00:00 2001 From: ivarprudnikov Date: Mon, 22 Apr 2024 22:49:00 +0100 Subject: [PATCH] show remaining attempts --- internal/storage/memstore/messages.go | 4 ++-- internal/storage/messages.go | 12 ++++++------ web/message.show.tmpl | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/storage/memstore/messages.go b/internal/storage/memstore/messages.go index 2f99bbb..06167f0 100644 --- a/internal/storage/memstore/messages.go +++ b/internal/storage/memstore/messages.go @@ -108,11 +108,11 @@ func (s *memMessageStore) GetFullMessage(id string, pin string) (*storage.Messag return &msg, nil } - msg.Attempt += 1 + msg.AttemptsRemaining -= 1 s.messages.Store(id, msg) // If the pin was wrong then start tracking attempts - if msg.Attempt >= storage.MAX_PIN_ATTEMPTS { + if msg.AttemptsRemaining <= 0 { s.messages.Delete(id) } } else { diff --git a/internal/storage/messages.go b/internal/storage/messages.go index ac1b71f..014def6 100644 --- a/internal/storage/messages.go +++ b/internal/storage/messages.go @@ -19,9 +19,9 @@ type MessageStore interface { type Message struct { aztables.Entity - Content string `json:"content,omitempty"` - Pin string `json:"pin,omitempty"` - Attempt int `json:"Attempt,omitempty"` + Content string `json:"content,omitempty"` + Pin string `json:"pin,omitempty"` + AttemptsRemaining int `json:"remaining,omitempty"` } func NewMessage(username string, ciphertext string, pin string) (Message, error) { @@ -36,8 +36,8 @@ func NewMessage(username string, ciphertext string, pin string) (Message, error) RowKey: username, Timestamp: aztables.EDMDateTime(t), }, - Content: ciphertext, - Pin: pinHash, - Attempt: 0, + Content: ciphertext, + Pin: pinHash, + AttemptsRemaining: MAX_PIN_ATTEMPTS, }, nil } diff --git a/web/message.show.tmpl b/web/message.show.tmpl index 7168bb1..0b17d55 100644 --- a/web/message.show.tmpl +++ b/web/message.show.tmpl @@ -35,6 +35,9 @@
Provide a PIN to unlock content
+
+
Remaining attempts: {{ .data.AttemptsRemaining }}
+
{{end}}