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