forked from nixcn/nixcn-cms
Impl magic login logic && checkin logic
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user