This commit is contained in:
Your Name 2023-10-09 11:42:29 -04:00
parent 72a5c50e7e
commit 985db3a060
3 changed files with 7 additions and 7 deletions

View File

@ -44,7 +44,7 @@ func Login(username, password string) bool {
}
func (u *UserData) SetPassword(newcrypt []byte) bool {
q := fmt.Sprintf("update %s_auth set password=? where user=?", c.TablePrefix)
q := fmt.Sprintf("update %s_users set password=? where id=?", c.TablePrefix)
_, err := c.db.Exec(q, newcrypt, u.UserID)
if err != nil {
log.Printf("scsusers.SetPassword: update failed for %s: %s\n", u.Username, err.Error())

10
main.go
View File

@ -64,7 +64,7 @@ func UsernameAvailable(username string) bool {
var tmp string
username = strings.ToLower(username)
q := fmt.Sprintf("select username from %s_auth where username = ?", c.TablePrefix)
q := fmt.Sprintf("select username from %s_users where username = ?", c.TablePrefix)
err := c.db.Get(&tmp, q, username)
if err == sql.ErrNoRows {
return true
@ -90,7 +90,7 @@ func Register(username, email, ip string) bool {
log.Printf("scsusers.Register: Bcrypt GenerateFromPassword failed? Pass is %s and error is %s\n", pass, err.Error())
return false
}
_, err = c.db.Query(fmt.Sprintf("insert into %s_auth (username, password) VALUES (?,?)", c.TablePrefix), username, crypt)
_, err = c.db.Query(fmt.Sprintf("insert into %s_users (username, password) VALUES (?,?)", c.TablePrefix), username, crypt)
if err != nil {
log.Printf("scsusers.Register: insert failed: %s\n", err.Error())
return false
@ -103,7 +103,7 @@ func Register(username, email, ip string) bool {
return true
}
log.Printf("scsusers.Register: Failed to send registration email, deleting user %s\n", username)
q := fmt.Sprintf("delete from %s_auth where username = ? AND password=?", c.TablePrefix)
q := fmt.Sprintf("delete from %s_users where username = ? AND password=?", c.TablePrefix)
_, err = c.db.Exec(q, username, string(crypt))
if err != nil {
log.Printf("scsusers.Register: Failed to delete new user %s: %s\n", username, err.Error())
@ -119,7 +119,7 @@ func NewUser() *UserData {
func Get(username string) (*UserData, bool) {
u := NewUser()
q := fmt.Sprintf("select username, password, id from %s_auth where username=?", c.TablePrefix)
q := fmt.Sprintf("select username, password, id from %s_users where username=?", c.TablePrefix)
err := c.db.Get(u, q, username)
if err != nil {
if err == sql.ErrNoRows {
@ -136,7 +136,7 @@ func GetUserid(username string) int64 {
var i int64
username = strings.ToLower(username)
q := fmt.Sprintf("select userid from %s_auth where username = ?", c.TablePrefix)
q := fmt.Sprintf("select userid from %s_users where username = ?", c.TablePrefix)
err := c.db.Get(&i, q, username)
if err != nil {
log.Printf("scsusers.getUserId: Error loading user: %s : %s\n", username, err.Error())

View File

@ -28,7 +28,7 @@ func TestUsers(t *testing.T) {
fmt.Println("Couldn't ping sqlite3 in-memory db:" + err.Error())
os.Exit(1)
}
schema := `CREATE TABLE test_auth (
schema := `CREATE TABLE test_users (
id integer primary key autoincrement,
username text NOT NULL unique,
password text NOT NULL);`