aboutsummaryrefslogtreecommitdiff
path: root/internal/userutil
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-10-24 23:45:31 +0800
committerGitHub <noreply@github.com>2022-10-24 23:45:31 +0800
commit131be6e074039e590488892d7a99ebdbe6eb4668 (patch)
tree391833ed53f439aa469af080591e372b79067b65 /internal/userutil
parent49be63abbfc4290b281e05493a0f65bb710c2ade (diff)
refactor(db): migrate helpers off `user_cache.go` (#7214)
Diffstat (limited to 'internal/userutil')
-rw-r--r--internal/userutil/userutil.go10
-rw-r--r--internal/userutil/userutil_test.go10
2 files changed, 20 insertions, 0 deletions
diff --git a/internal/userutil/userutil.go b/internal/userutil/userutil.go
index d8a8b031..6d324ff6 100644
--- a/internal/userutil/userutil.go
+++ b/internal/userutil/userutil.go
@@ -122,3 +122,13 @@ func ValidatePassword(encoded, salt, password string) bool {
got := EncodePassword(password, salt)
return subtle.ConstantTimeCompare([]byte(encoded), []byte(got)) == 1
}
+
+// MailResendCacheKey returns the key used for caching mail resend.
+func MailResendCacheKey(userID int64) string {
+ return fmt.Sprintf("mailResend::%d", userID)
+}
+
+// TwoFactorCacheKey returns the key used for caching two factor passcode.
+func TwoFactorCacheKey(userID int64, passcode string) string {
+ return fmt.Sprintf("twoFactor::%d::%s", userID, passcode)
+}
diff --git a/internal/userutil/userutil_test.go b/internal/userutil/userutil_test.go
index 895f7e26..e46546bd 100644
--- a/internal/userutil/userutil_test.go
+++ b/internal/userutil/userutil_test.go
@@ -181,3 +181,13 @@ func TestValidatePassword(t *testing.T) {
})
}
}
+
+func TestMailResendCacheKey(t *testing.T) {
+ got := MailResendCacheKey(1)
+ assert.Equal(t, "mailResend::1", got)
+}
+
+func TestTwoFactorCacheKey(t *testing.T) {
+ got := TwoFactorCacheKey(1, "113654")
+ assert.Equal(t, "twoFactor::1::113654", got)
+}