aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/sql
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database/sql')
-rw-r--r--pkg/database/sql/user.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go
index d449b05..2d74162 100644
--- a/pkg/database/sql/user.go
+++ b/pkg/database/sql/user.go
@@ -7,7 +7,7 @@ import (
"gorm.io/gorm"
"git.sr.ht/~gabrielgio/img/pkg/components/auth"
- user "git.sr.ht/~gabrielgio/img/pkg/components/auth"
+ "git.sr.ht/~gabrielgio/img/pkg/components/user"
)
type (
@@ -16,6 +16,8 @@ type (
Username string
Name string
Password string
+ IsAdmin bool
+ Path string
}
Users []*User
@@ -26,6 +28,7 @@ type (
)
var _ auth.Repository = &UserRepository{}
+var _ user.Repository = &UserRepository{}
func NewUserRepository(db *gorm.DB) *UserRepository {
return &UserRepository{
@@ -38,6 +41,8 @@ func (self *User) ToModel() *user.User {
ID: self.Model.ID,
Name: self.Name,
Username: self.Username,
+ Path: self.Path,
+ IsAdmin: self.IsAdmin,
}
}
@@ -63,6 +68,8 @@ func (self *UserRepository) EnsureAdmin(ctx context.Context) {
hash, _ := bcrypt.GenerateFromPassword([]byte("admin"), bcrypt.MinCost)
self.db.Save(&User{
Username: "admin",
+ Path: "/",
+ IsAdmin: true,
Password: string(hash),
})
}
@@ -130,7 +137,7 @@ func (self *UserRepository) GetPassword(ctx context.Context, id uint) ([]byte, e
return userPassword.Password, nil
}
-func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
+func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) error {
user := &User{
Username: createUser.Username,
Name: createUser.Name,
@@ -141,10 +148,10 @@ func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateU
WithContext(ctx).
Create(user)
if result.Error != nil {
- return 0, result.Error
+ return result.Error
}
- return user.Model.ID, nil
+ return nil
}
func (self *UserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {