fix bugs
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"opencatd-open/internal/dto"
|
||||
"opencatd-open/internal/model"
|
||||
"opencatd-open/internal/utils"
|
||||
"opencatd-open/pkg/config"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -17,12 +18,14 @@ import (
|
||||
)
|
||||
|
||||
type UserServiceImpl struct {
|
||||
cfg *config.Config
|
||||
db *gorm.DB
|
||||
userRepo dao.UserRepository
|
||||
}
|
||||
|
||||
func NewUserService(db *gorm.DB, userRepo dao.UserRepository) *UserServiceImpl {
|
||||
func NewUserService(cfg *config.Config, db *gorm.DB, userRepo dao.UserRepository) *UserServiceImpl {
|
||||
return &UserServiceImpl{
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
userRepo: userRepo,
|
||||
}
|
||||
@@ -40,11 +43,19 @@ func (s *UserServiceImpl) Register(ctx context.Context, req *model.User) error {
|
||||
_user.Role = utils.ToPtr(consts.RoleRoot)
|
||||
_user.Active = utils.ToPtr(true)
|
||||
_user.UnlimitedQuota = utils.ToPtr(true)
|
||||
} else {
|
||||
if !s.cfg.AllowRegister {
|
||||
return fmt.Errorf("register is not allowed")
|
||||
}
|
||||
}
|
||||
|
||||
_user.Password, err = utils.HashPassword(req.Password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_user.Active = &s.cfg.DefaultActive
|
||||
_user.UnlimitedQuota = &s.cfg.UnlimitedQuota
|
||||
|
||||
_user.Username = req.Username
|
||||
_user.Email = req.Email
|
||||
_user.Tokens = []model.Token{
|
||||
|
||||
Reference in New Issue
Block a user