This commit is contained in:
2026-03-02 01:52:10 +07:00
parent 4280d5376a
commit a044093747
4 changed files with 29 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
package password
type IPasswordGenerator interface {
GeneratePassword(length int) string
}
+8 -2
View File
@@ -6,8 +6,14 @@ var (
letters = []rune("abcdefghijklmnopqrstuvwxyz123456789")
)
func GenPass(n int) string {
b := make([]rune, n)
type service struct{}
func NewPasswordGenerator() IPasswordGenerator {
return &service{}
}
func (s *service) GeneratePassword(length int) string {
b := make([]rune, length)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
+12 -9
View File
@@ -19,23 +19,26 @@ import (
)
type Services struct {
repository *Repository
storyService *story_service.StoryService
linkService link.ILinkService
clientHost string
repository *Repository
storyService *story_service.StoryService
linkService link.ILinkService
passwordGenerator password.IPasswordGenerator
clientHost string
}
func NewServices(
repository *Repository,
storyService *story_service.StoryService,
linkService link.ILinkService,
passwordGenerator password.IPasswordGenerator,
clientHost string,
) *Services {
return &Services{
repository: repository,
storyService: storyService,
linkService: linkService,
clientHost: clientHost,
repository: repository,
storyService: storyService,
linkService: linkService,
passwordGenerator: passwordGenerator,
clientHost: clientHost,
}
}
@@ -176,7 +179,7 @@ func (s *Services) AddTeams(ctx context.Context, req *proto.AddTeamsReq) (*proto
inTeams := make([]*models.Team, 0, len(req.Teams))
for _, team := range req.Teams {
t := mapProtoTeamsToTeam(team)
t.Password = password.GenPass(8)
t.Password = s.passwordGenerator.GeneratePassword(8)
inTeams = append(inTeams, t)
}
teams, err := s.repository.AddTeams(ctx, inTeams)