diff options
Diffstat (limited to 'pkg/components')
-rw-r--r-- | pkg/components/auth/controller.go | 14 | ||||
-rw-r--r-- | pkg/components/auth/model.go | 22 | ||||
-rw-r--r-- | pkg/components/user/controller.go | 1 | ||||
-rw-r--r-- | pkg/components/user/model.go | 33 |
4 files changed, 34 insertions, 36 deletions
diff --git a/pkg/components/auth/controller.go b/pkg/components/auth/controller.go index 4da6071..a81a1c0 100644 --- a/pkg/components/auth/controller.go +++ b/pkg/components/auth/controller.go @@ -41,17 +41,3 @@ func (c *Controller) Login(ctx context.Context, username, password []byte) ([]by } return ext.WriteToken(token, c.key) } - -func (c *Controller) Register(ctx context.Context, username, password []byte) error { - hash, err := bcrypt.GenerateFromPassword(password, bcrypt.MinCost) - if err != nil { - return err - } - - _, err = c.repository.Create(ctx, &CreateUser{ - Username: string(username), - Password: hash, - }) - - return err -} diff --git a/pkg/components/auth/model.go b/pkg/components/auth/model.go index e46ef49..dd6ce50 100644 --- a/pkg/components/auth/model.go +++ b/pkg/components/auth/model.go @@ -3,30 +3,8 @@ package auth import "context" type ( - // TODO: move to user later - User struct { - ID uint - Username string - Name string - } - - // TODO: move to user later - UpdateUser struct { - Username string - Name string - } - - // TODO: move to user later - CreateUser struct { - Username string - Name string - Password []byte - } - Repository interface { GetIDByUsername(ctx context.Context, username string) (uint, error) GetPassword(ctx context.Context, id uint) ([]byte, error) - // TODO: move to user later - Create(ctx context.Context, createUser *CreateUser) (uint, error) } ) diff --git a/pkg/components/user/controller.go b/pkg/components/user/controller.go new file mode 100644 index 0000000..a00006b --- /dev/null +++ b/pkg/components/user/controller.go @@ -0,0 +1 @@ +package user diff --git a/pkg/components/user/model.go b/pkg/components/user/model.go new file mode 100644 index 0000000..f957c39 --- /dev/null +++ b/pkg/components/user/model.go @@ -0,0 +1,33 @@ +package user + +import "context" + +type ( + User struct { + ID uint + Username string + Name string + IsAdmin bool + Path string + } + + UpdateUser struct { + Username string + Name string + Password *string + } + + CreateUser struct { + Username string + Name string + Password string + IsAdmin bool + Path string + } + + Repository interface { + List(ctx context.Context) ([]*User, error) + Create(ctx context.Context, createUser *CreateUser) error + Update(ctx context.Context, id uint, updateUser *UpdateUser) error + } +) |