Impl magic login logic && checkin logic

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-25 00:37:02 +08:00
parent cd2bcd597c
commit bd726f80ea
10 changed files with 54 additions and 15 deletions

View File

@@ -5,6 +5,8 @@ import (
"encoding/base64"
"sync"
"time"
"github.com/spf13/viper"
)
type Token struct {
@@ -17,7 +19,7 @@ var (
)
// Generate magic token
func NewMagicToken(email string, ttl time.Duration) (string, error) {
func NewMagicToken(email string) (string, error) {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
return "", err
@@ -27,7 +29,7 @@ func NewMagicToken(email string, ttl time.Duration) (string, error) {
store.Store(token, Token{
Email: email,
ExpiresAt: time.Now().Add(ttl),
ExpiresAt: time.Now().Add(viper.GetDuration("ttl.magic_link_ttl")),
})
return token, nil

View File

@@ -10,7 +10,7 @@ import (
func VerifyTurnstile(token, ip string) (bool, error) {
form := url.Values{}
form.Set("secret", viper.GetString("secrets.turnstile"))
form.Set("secret", viper.GetString("secrets.turnstile_secret"))
form.Set("response", token)
form.Set("remoteip", ip)