work in progress

This commit is contained in:
ston1th 2018-09-04 23:15:47 +02:00
commit 07ff5ccffb
23 changed files with 228 additions and 240 deletions

View file

@ -5,6 +5,13 @@ import (
"golang.org/x/crypto/bcrypt"
)
type User struct {
Username string
Password string
Admin bool
Locked int
}
var (
errUserNotFound = dbErr("user not found")
errUserExists = dbErr("user already exist")
@ -28,7 +35,7 @@ func (bs *BoltStore) GetUser(username string) (u User, err error) {
err = bs.db.View(func(tx *bolt.Tx) error {
v := tx.Bucket([]byte(userTable)).Get([]byte(username))
if v == nil {
return errUserNotExists
return errUserNotFound
}
return bs.Unmarshal(v, &u)
})
@ -47,7 +54,7 @@ func (bs *BoltStore) UserIsAdmin(username string) (admin bool) {
func (bs *BoltStore) UserExists(username string) error {
return bs.db.View(func(tx *bolt.Tx) error {
if tx.Bucket([]byte(userTable)).Get([]byte(username)) == nil {
return errUserNotExists
return errUserNoFound
}
return nil
})