diff options
Diffstat (limited to 'identity')
-rw-r--r-- | identity/identity_user.go | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/identity/identity_user.go b/identity/identity_user.go index 60622c12..cd67459e 100644 --- a/identity/identity_user.go +++ b/identity/identity_user.go @@ -35,24 +35,19 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { } func GetUserIdentityId(repo repository.Repo) (entity.Id, error) { - configs, err := repo.LocalConfig().ReadAll(identityConfigKey) - if err != nil { - return entity.UnsetId, err - } - - if len(configs) == 0 { + val, err := repo.LocalConfig().ReadString(identityConfigKey) + if err == repository.ErrNoConfigEntry { return entity.UnsetId, ErrNoIdentitySet } - - if len(configs) > 1 { + if err == repository.ErrMultipleConfigEntry { return entity.UnsetId, ErrMultipleIdentitiesSet } - - var id entity.Id - for _, val := range configs { - id = entity.Id(val) + if err != nil { + return entity.UnsetId, err } + var id = entity.Id(val) + if err := id.Validate(); err != nil { return entity.UnsetId, err } @@ -62,10 +57,12 @@ func GetUserIdentityId(repo repository.Repo) (entity.Id, error) { // IsUserIdentitySet say if the user has set his identity func IsUserIdentitySet(repo repository.Repo) (bool, error) { - configs, err := repo.LocalConfig().ReadAll(identityConfigKey) + _, err := repo.LocalConfig().ReadString(identityConfigKey) + if err == repository.ErrNoConfigEntry { + return false, nil + } if err != nil { return false, err } - - return len(configs) == 1, nil + return true, nil } |