summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/db.go2
-rw-r--r--db/user.go17
2 files changed, 19 insertions, 0 deletions
diff --git a/db/db.go b/db/db.go
index a9a9a2e..87784ff 100644
--- a/db/db.go
+++ b/db/db.go
@@ -41,8 +41,10 @@ type Model interface {
GetSchemaVersion() (int, error)
CreateUser(username, password string) (User, error)
+ DeleteUser(user User) error
SetPassword(user User, password string) error
AuthenticateUser(username, password string) (User, error)
+ GetByUsername(username string) (User, error)
GetById(id string) (User, error)
AllUsers() ([]User, error)
diff --git a/db/user.go b/db/user.go
index c1f2efe..61e05ad 100644
--- a/db/user.go
+++ b/db/user.go
@@ -78,6 +78,13 @@ func (p *Phlox) CreateUser(username, password string) (User, error) {
+func (p *Phlox) DeleteUser(user User) error {
+ _, err := p.db.Exec("delete from users where userid=?;", user.Id)
+ return err
+}
+
+
+
func (p *Phlox) SetPassword(user User, password string) error {
hash, err := hashPassword(password, user.Salt)
if err != nil {
@@ -140,6 +147,16 @@ func (p *Phlox) AuthenticateUser(username, password string) (bool, User, error)
}
+func (p *Phlox) GetByUsername(username string) (User, error) {
+ row := p.db.QueryRow("select * from users where username = ?;", username)
+ user, err := extractUser(row)
+ if err != nil {
+ return User{}, err
+ }
+ return user, nil
+}
+
+
func (p *Phlox) GetById(id int) (User, error) {
row := p.db.QueryRow("select * from users where userid = ?;", id)
user, err := extractUser(row)