diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 7a6ba0bb..cbb71ca3 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -3900,9 +3900,13 @@ const docTemplate = `{ "domain.CreateOrganizationRequest": { "type": "object", "required": [ + "Email", "name" ], "properties": { + "Email": { + "type": "string" + }, "description": { "type": "string", "maxLength": 100, @@ -4677,6 +4681,9 @@ const docTemplate = `{ "accountId": { "type": "string" }, + "department": { + "type": "string" + }, "name": { "type": "string" }, diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 37239f36..b4b1ed03 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -3893,9 +3893,13 @@ "domain.CreateOrganizationRequest": { "type": "object", "required": [ + "Email", "name" ], "properties": { + "Email": { + "type": "string" + }, "description": { "type": "string", "maxLength": 100, @@ -4670,6 +4674,9 @@ "accountId": { "type": "string" }, + "department": { + "type": "string" + }, "name": { "type": "string" }, diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 0ac91838..f968a8b8 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -594,6 +594,8 @@ definitions: type: object domain.CreateOrganizationRequest: properties: + Email: + type: string description: maxLength: 100 minLength: 0 @@ -603,6 +605,7 @@ definitions: phone: type: string required: + - Email - name type: object domain.CreateStackRequest: @@ -1110,6 +1113,8 @@ definitions: properties: accountId: type: string + department: + type: string name: type: string organization: diff --git a/internal/aws/ses/ses.go b/internal/aws/ses/ses.go index 9be75772..8aca0c59 100644 --- a/internal/aws/ses/ses.go +++ b/internal/aws/ses/ses.go @@ -83,7 +83,7 @@ func SendEmailForVerityIdentity(client *awsSes.Client, targetEmailAddress string } func SendEmailForTemporaryPassword(client *awsSes.Client, targetEmailAddress string, randomPassword string) error { - subject := "[TKS] 비밀번호 초기화" + subject := "[TKS] 임시 비밀번호 발급" body := "임시 비밀번호가 발급되었습니다.\n" + "로그인 후 비밀번호를 변경하여 사용하십시오.\n\n" + "임시 비밀번호: " + randomPassword + "\n\n" + diff --git a/internal/delivery/http/organization.go b/internal/delivery/http/organization.go index 836def5b..412c3a3d 100644 --- a/internal/delivery/http/organization.go +++ b/internal/delivery/http/organization.go @@ -58,7 +58,7 @@ func (h *OrganizationHandler) CreateOrganization(w http.ResponseWriter, r *http. } organization.ID = organizationId // Admin user 생성 - _, err = h.userUsecase.CreateAdmin(organizationId) + _, err = h.userUsecase.CreateAdmin(organizationId, input.Email) if err != nil { log.Errorf("error is :%s(%T)", err.Error(), err) ErrorJSON(w, err) diff --git a/internal/usecase/user.go b/internal/usecase/user.go index 9d32d6d0..13b36fc2 100644 --- a/internal/usecase/user.go +++ b/internal/usecase/user.go @@ -20,7 +20,7 @@ import ( ) type IUserUsecase interface { - CreateAdmin(organizationId string) (*domain.User, error) + CreateAdmin(organizationId string, email string) (*domain.User, error) DeleteAdmin(organizationId string) error DeleteAll(ctx context.Context, organizationId string) error Create(ctx context.Context, user *domain.User) (*domain.User, error) @@ -188,10 +188,12 @@ func (u *UserUsecase) DeleteAdmin(organizationId string) error { return nil } -func (u *UserUsecase) CreateAdmin(orgainzationId string) (*domain.User, error) { +func (u *UserUsecase) CreateAdmin(orgainzationId string, email string) (*domain.User, error) { + randomPassword := helper.GenerateRandomString(passwordLength) user := domain.User{ AccountId: "admin", - Password: "admin", + Password: randomPassword, + Email: email, Role: domain.Role{ Name: "admin", }, @@ -205,6 +207,7 @@ func (u *UserUsecase) CreateAdmin(orgainzationId string) (*domain.User, error) { groups := []string{fmt.Sprintf("%s@%s", user.Role.Name, orgainzationId)} err := u.kc.CreateUser(orgainzationId, &gocloak.User{ Username: gocloak.StringP(user.AccountId), + Email: gocloak.StringP(user.Email), Credentials: &[]gocloak.CredentialRepresentation{ { Type: gocloak.StringP("password"), @@ -251,6 +254,10 @@ func (u *UserUsecase) CreateAdmin(orgainzationId string) (*domain.User, error) { return nil, err } + if err = ses.SendEmailForTemporaryPassword(ses.Client, user.Email, randomPassword); err != nil { + return nil, err + } + return &resUser, nil } diff --git a/pkg/domain/auth.go b/pkg/domain/auth.go index e2c755e0..4f8c3201 100644 --- a/pkg/domain/auth.go +++ b/pkg/domain/auth.go @@ -12,6 +12,7 @@ type LoginResponse struct { Name string `json:"name"` Token string `json:"token"` Role Role `json:"role"` + Department string `json:"department"` Organization Organization `json:"organization"` PasswordExpired bool `json:"passwordExpired"` } `json:"user"` diff --git a/pkg/domain/organization.go b/pkg/domain/organization.go index 1cea6fcf..d7801c88 100644 --- a/pkg/domain/organization.go +++ b/pkg/domain/organization.go @@ -65,6 +65,7 @@ type CreateOrganizationRequest struct { Name string `json:"name" validate:"required,name"` Description string `json:"description" validate:"omitempty,min=0,max=100"` Phone string `json:"phone"` + Email string `json:"Email" validate:"required,email"` } type CreateOrganizationResponse struct {