generated from VLADIMIR/template
clear
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package password
|
||||
|
||||
type IPasswordGenerator interface {
|
||||
GeneratePassword(length int) string
|
||||
}
|
||||
@@ -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))]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user