-
Notifications
You must be signed in to change notification settings - Fork 482
/
user_converter.go
58 lines (51 loc) · 1.69 KB
/
user_converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package admin
import (
"github.com/zitadel/logging"
user_grpc "github.com/zitadel/zitadel/internal/api/grpc/user"
"github.com/zitadel/zitadel/internal/domain"
admin_grpc "github.com/zitadel/zitadel/pkg/grpc/admin"
"golang.org/x/text/language"
)
func setUpOrgHumanToDomain(human *admin_grpc.SetUpOrgRequest_Human) *domain.Human {
return &domain.Human{
Username: human.UserName,
Profile: setUpOrgHumanProfileToDomain(human.Profile),
Email: setUpOrgHumanEmailToDomain(human.Email),
Phone: setUpOrgHumanPhoneToDomain(human.Phone),
Password: setUpOrgHumanPasswordToDomain(human.Password),
}
}
func setUpOrgHumanProfileToDomain(profile *admin_grpc.SetUpOrgRequest_Human_Profile) *domain.Profile {
var lang language.Tag
lang, err := language.Parse(profile.PreferredLanguage)
logging.Log("ADMIN-tiMWs").OnError(err).Debug("unable to parse language")
return &domain.Profile{
FirstName: profile.FirstName,
LastName: profile.LastName,
NickName: profile.NickName,
DisplayName: profile.DisplayName,
PreferredLanguage: lang,
Gender: user_grpc.GenderToDomain(profile.Gender),
}
}
func setUpOrgHumanEmailToDomain(email *admin_grpc.SetUpOrgRequest_Human_Email) *domain.Email {
return &domain.Email{
EmailAddress: email.Email,
IsEmailVerified: email.IsEmailVerified,
}
}
func setUpOrgHumanPhoneToDomain(phone *admin_grpc.SetUpOrgRequest_Human_Phone) *domain.Phone {
if phone == nil {
return nil
}
return &domain.Phone{
PhoneNumber: phone.Phone,
IsPhoneVerified: phone.IsPhoneVerified,
}
}
func setUpOrgHumanPasswordToDomain(password string) *domain.Password {
if password == "" {
return nil
}
return domain.NewPassword(password)
}