Move to Donetick Org, first commit

This commit is contained in:
Mo Tarbin 2024-06-30 21:41:41 -04:00
commit c13dd9addb
42 changed files with 7463 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package utils
import (
"encoding/base64"
crand "crypto/rand"
"donetick.com/core/logging"
"github.com/gin-gonic/gin"
)
func GenerateInviteCode(c *gin.Context) string {
logger := logging.FromContext(c)
// Define the length of the token (in bytes). For example, 32 bytes will result in a 44-character base64-encoded token.
tokenLength := 12
// Generate a random byte slice.
tokenBytes := make([]byte, tokenLength)
_, err := crand.Read(tokenBytes)
if err != nil {
logger.Errorw("utility.GenerateEmailResetToken failed to generate random bytes", "err", err)
}
// Encode the byte slice to a base64 string.
token := base64.URLEncoding.EncodeToString(tokenBytes)
return token
}