This commit is contained in:
Your Name 2023-10-06 18:39:58 -04:00
parent b042b4dbc9
commit 173612b58d
1 changed files with 9 additions and 27 deletions

View File

@ -3,7 +3,6 @@ package scsusers
import ( import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"database/sql"
"encoding/base32" "encoding/base32"
"fmt" "fmt"
"log" "log"
@ -12,34 +11,17 @@ import (
"time" "time"
) )
func RecoverByUsername(username string) { func RecoverByEmail(email string) {
var email string u, ok := Get(email)
username = strings.ToLower(username) if !ok {
return
q := fmt.Sprintf("select email from %s_auth where username = ?", c.TablePrefix)
err := c.db.Get(&email, q, username)
if err != sql.ErrNoRows {
recoverycode := randBytes(16)
qq := fmt.Sprintf("update %s_auth set recoverycode=?, recoverytime=NOW() where username = ?", c.TablePrefix)
_, err := c.db.Exec(qq, recoverycode, username)
if err == nil {
SendRecoveryEmail(email, username, string(recoverycode))
}
} }
} recoverycode := randBytes(16)
func RecoverByEmail(e string) { u.Set("recoverycode", string(recoverycode))
var username, email string u.Set("recoverytime", fmt.Sprintf("%d", time.Now().Unix()))
q := fmt.Sprintf("select username from %s_auth where email = ?", c.TablePrefix)
err := c.db.Get(&username, q, e) SendRecoveryEmail(email, email, string(recoverycode))
if err != sql.ErrNoRows {
recoverycode := randBytes(16)
qq := fmt.Sprintf("update %s_auth set recoverycode=?, recoverytime=NOW() where username = ?", c.TablePrefix)
_, err := c.db.Exec(qq, recoverycode, username)
if err == nil {
SendRecoveryEmail(email, username, string(recoverycode))
}
}
} }
func randBytes(n int) []byte { func randBytes(n int) []byte {