2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/repository/user"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
2021-01-05 08:33:45 +00:00
|
|
|
func writeModelToHuman(wm *HumanWriteModel) *domain.Human {
|
2021-03-19 10:12:56 +00:00
|
|
|
human := &domain.Human{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
2021-01-15 08:32:59 +00:00
|
|
|
Username: wm.UserName,
|
|
|
|
State: wm.UserState,
|
2021-01-05 08:33:45 +00:00
|
|
|
Profile: &domain.Profile{
|
2021-01-04 13:52:13 +00:00
|
|
|
FirstName: wm.FirstName,
|
|
|
|
LastName: wm.LastName,
|
|
|
|
NickName: wm.NickName,
|
|
|
|
DisplayName: wm.DisplayName,
|
|
|
|
PreferredLanguage: wm.PreferredLanguage,
|
2021-01-05 08:33:45 +00:00
|
|
|
Gender: wm.Gender,
|
2021-01-04 13:52:13 +00:00
|
|
|
},
|
2021-01-05 08:33:45 +00:00
|
|
|
Email: &domain.Email{
|
2021-01-04 13:52:13 +00:00
|
|
|
EmailAddress: wm.Email,
|
|
|
|
IsEmailVerified: wm.IsEmailVerified,
|
|
|
|
},
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
|
|
|
if wm.Phone != "" {
|
|
|
|
human.Phone = &domain.Phone{
|
|
|
|
PhoneNumber: wm.Phone,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if wm.Country != "" || wm.Locality != "" || wm.PostalCode != "" || wm.Region != "" || wm.StreetAddress != "" {
|
|
|
|
human.Address = &domain.Address{
|
2021-01-05 08:33:45 +00:00
|
|
|
Country: wm.Country,
|
|
|
|
Locality: wm.Locality,
|
|
|
|
PostalCode: wm.PostalCode,
|
|
|
|
Region: wm.Region,
|
|
|
|
StreetAddress: wm.StreetAddress,
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
2021-03-19 10:12:56 +00:00
|
|
|
return human
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToProfile(wm *HumanProfileWriteModel) *domain.Profile {
|
|
|
|
return &domain.Profile{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
FirstName: wm.FirstName,
|
|
|
|
LastName: wm.LastName,
|
|
|
|
NickName: wm.NickName,
|
|
|
|
DisplayName: wm.DisplayName,
|
|
|
|
PreferredLanguage: wm.PreferredLanguage,
|
2021-01-06 10:12:56 +00:00
|
|
|
Gender: wm.Gender,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToEmail(wm *HumanEmailWriteModel) *domain.Email {
|
|
|
|
return &domain.Email{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
EmailAddress: wm.Email,
|
|
|
|
IsEmailVerified: wm.IsEmailVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:06:45 +00:00
|
|
|
func writeModelToPhone(wm *HumanPhoneWriteModel) *domain.Phone {
|
|
|
|
return &domain.Phone{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
PhoneNumber: wm.Phone,
|
|
|
|
IsPhoneVerified: wm.IsPhoneVerified,
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToAddress(wm *HumanAddressWriteModel) *domain.Address {
|
|
|
|
return &domain.Address{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
Country: wm.Country,
|
|
|
|
Locality: wm.Locality,
|
|
|
|
PostalCode: wm.PostalCode,
|
|
|
|
Region: wm.Region,
|
|
|
|
StreetAddress: wm.StreetAddress,
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 10:12:56 +00:00
|
|
|
|
|
|
|
func writeModelToMachine(wm *MachineWriteModel) *domain.Machine {
|
|
|
|
return &domain.Machine{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
2021-03-19 10:12:56 +00:00
|
|
|
Username: wm.UserName,
|
2021-01-06 10:12:56 +00:00
|
|
|
Name: wm.Name,
|
|
|
|
Description: wm.Description,
|
2021-03-19 10:12:56 +00:00
|
|
|
State: wm.UserState,
|
2021-01-06 10:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 08:32:59 +00:00
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func keyWriteModelToMachineKey(wm *MachineKeyWriteModel) *domain.MachineKey {
|
|
|
|
return &domain.MachineKey{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
KeyID: wm.KeyID,
|
|
|
|
Type: wm.KeyType,
|
|
|
|
ExpirationDate: wm.ExpirationDate,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 08:32:59 +00:00
|
|
|
func readModelToU2FTokens(wm *HumanU2FTokensReadModel) []*domain.WebAuthNToken {
|
|
|
|
tokens := make([]*domain.WebAuthNToken, len(wm.WebAuthNTokens))
|
|
|
|
for i, token := range wm.WebAuthNTokens {
|
|
|
|
tokens[i] = writeModelToWebAuthN(token)
|
|
|
|
}
|
|
|
|
return tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToPasswordlessTokens(wm *HumanPasswordlessTokensReadModel) []*domain.WebAuthNToken {
|
|
|
|
tokens := make([]*domain.WebAuthNToken, len(wm.WebAuthNTokens))
|
|
|
|
for i, token := range wm.WebAuthNTokens {
|
|
|
|
tokens[i] = writeModelToWebAuthN(token)
|
|
|
|
}
|
|
|
|
return tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeModelToWebAuthN(wm *HumanWebAuthNWriteModel) *domain.WebAuthNToken {
|
|
|
|
return &domain.WebAuthNToken{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
WebAuthNTokenID: wm.WebauthNTokenID,
|
|
|
|
Challenge: wm.Challenge,
|
|
|
|
KeyID: wm.KeyID,
|
|
|
|
PublicKey: wm.PublicKey,
|
|
|
|
AttestationType: wm.AttestationType,
|
|
|
|
AAGUID: wm.AAGUID,
|
|
|
|
SignCount: wm.SignCount,
|
|
|
|
WebAuthNTokenName: wm.WebAuthNTokenName,
|
|
|
|
State: wm.State,
|
|
|
|
}
|
|
|
|
}
|
2021-02-08 10:30:30 +00:00
|
|
|
|
|
|
|
func authRequestDomainToAuthRequestInfo(authRequest *domain.AuthRequest) *user.AuthRequestInfo {
|
|
|
|
info := &user.AuthRequestInfo{
|
|
|
|
ID: authRequest.ID,
|
|
|
|
UserAgentID: authRequest.AgentID,
|
|
|
|
SelectedIDPConfigID: authRequest.SelectedIDPConfigID,
|
|
|
|
}
|
|
|
|
if authRequest.BrowserInfo != nil {
|
|
|
|
info.BrowserInfo = &user.BrowserInfo{
|
|
|
|
UserAgent: authRequest.BrowserInfo.UserAgent,
|
|
|
|
AcceptLanguage: authRequest.BrowserInfo.AcceptLanguage,
|
|
|
|
RemoteIP: authRequest.BrowserInfo.RemoteIP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|