more
This commit is contained in:
parent
72a5c50e7e
commit
985db3a060
2
auth.go
2
auth.go
|
@ -44,7 +44,7 @@ func Login(username, password string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserData) SetPassword(newcrypt []byte) 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)
|
_, err := c.db.Exec(q, newcrypt, u.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("scsusers.SetPassword: update failed for %s: %s\n", u.Username, err.Error())
|
log.Printf("scsusers.SetPassword: update failed for %s: %s\n", u.Username, err.Error())
|
||||||
|
|
10
main.go
10
main.go
|
@ -64,7 +64,7 @@ func UsernameAvailable(username string) bool {
|
||||||
var tmp string
|
var tmp string
|
||||||
username = strings.ToLower(username)
|
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)
|
err := c.db.Get(&tmp, q, username)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return true
|
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())
|
log.Printf("scsusers.Register: Bcrypt GenerateFromPassword failed? Pass is %s and error is %s\n", pass, err.Error())
|
||||||
return false
|
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 {
|
if err != nil {
|
||||||
log.Printf("scsusers.Register: insert failed: %s\n", err.Error())
|
log.Printf("scsusers.Register: insert failed: %s\n", err.Error())
|
||||||
return false
|
return false
|
||||||
|
@ -103,7 +103,7 @@ func Register(username, email, ip string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
log.Printf("scsusers.Register: Failed to send registration email, deleting user %s\n", username)
|
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))
|
_, err = c.db.Exec(q, username, string(crypt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("scsusers.Register: Failed to delete new user %s: %s\n", username, err.Error())
|
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) {
|
func Get(username string) (*UserData, bool) {
|
||||||
u := NewUser()
|
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)
|
err := c.db.Get(u, q, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
@ -136,7 +136,7 @@ func GetUserid(username string) int64 {
|
||||||
var i int64
|
var i int64
|
||||||
username = strings.ToLower(username)
|
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)
|
err := c.db.Get(&i, q, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("scsusers.getUserId: Error loading user: %s : %s\n", username, err.Error())
|
log.Printf("scsusers.getUserId: Error loading user: %s : %s\n", username, err.Error())
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestUsers(t *testing.T) {
|
||||||
fmt.Println("Couldn't ping sqlite3 in-memory db:" + err.Error())
|
fmt.Println("Couldn't ping sqlite3 in-memory db:" + err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
schema := `CREATE TABLE test_auth (
|
schema := `CREATE TABLE test_users (
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
username text NOT NULL unique,
|
username text NOT NULL unique,
|
||||||
password text NOT NULL);`
|
password text NOT NULL);`
|
||||||
|
|
Loading…
Reference in New Issue