features/working-on-scopes #13
@ -18,7 +18,7 @@ const (
|
||||
|
||||
type IUserTable interface {
|
||||
GetByName(name string) (domain.UserEntity, error)
|
||||
Create(name, password string) (int64, error)
|
||||
Create(name, password, scope string) (int64, error)
|
||||
Update(id int, entity domain.UserEntity) error
|
||||
UpdatePassword(name, password string) error
|
||||
CheckUserHash(name, password string) error
|
||||
@ -56,7 +56,7 @@ func (ur UserRepository) GetByName(name string) (domain.UserEntity, error) {
|
||||
return data[0], nil
|
||||
}
|
||||
|
||||
func (ur UserRepository) Create(name, password string) (int64, error) {
|
||||
func (ur UserRepository) Create(name, password, scope string) (int64, error) {
|
||||
passwordBytes := []byte(password)
|
||||
hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
|
@ -2,6 +2,7 @@ package repositories_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"go-cook/api/domain"
|
||||
"go-cook/api/repositories"
|
||||
"log"
|
||||
"testing"
|
||||
@ -20,7 +21,7 @@ func TestCanCreateNewUser(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
repo := repositories.NewUserRepository(db)
|
||||
updated, err := repo.Create("testing", "NotSecure")
|
||||
updated, err := repo.Create("testing", "NotSecure", domain.ScopeRecipeRead)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
t.FailNow()
|
||||
|
@ -53,13 +53,13 @@ func (us UserService) GetUser(username string) (domain.UserEntity, error) {
|
||||
return us.repo.GetByName(username)
|
||||
}
|
||||
|
||||
func (us UserService) CreateNewUser(name, password string) (domain.UserEntity, error) {
|
||||
func (us UserService) CreateNewUser(name, password, scope string) (domain.UserEntity, error) {
|
||||
err := us.CheckPasswordForRequirements(password)
|
||||
if err != nil {
|
||||
return domain.UserEntity{}, err
|
||||
}
|
||||
|
||||
us.repo.Create(name, password)
|
||||
us.repo.Create(name, password, domain.ScopeRecipeRead)
|
||||
return domain.UserEntity{}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user