Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
06c14271
Commit
06c14271
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add GetUsername
parent
30f433a8
No related branches found
No related tags found
2 merge requests
!510
Release
,
!337
Hotfix/store username ud
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ud/store/facts.go
+28
-17
28 additions, 17 deletions
ud/store/facts.go
with
28 additions
and
17 deletions
ud/store/facts.go
+
28
−
17
View file @
06c14271
...
...
@@ -58,6 +58,26 @@ func (s *Store) StoreUsername(f fact.Fact) error {
return
s
.
saveUnconfirmedFacts
()
}
// GetUsername retrieves the username from the Store object.
// If it is not directly in the Store's username field, it is
// searched for in the map.
func
(
s
*
Store
)
GetUsername
()
(
string
,
error
)
{
s
.
mux
.
RLock
()
defer
s
.
mux
.
RUnlock
()
// todo: refactor this in the future so that
// it's an O(1) lookup (place this object in another map
// or have it's own field)
for
f
:=
range
s
.
confirmedFacts
{
if
f
.
T
==
fact
.
Username
{
return
f
.
Fact
,
nil
}
}
return
""
,
errors
.
New
(
"Could not find username in store"
)
}
// StoreUnconfirmedFact stores a fact that has been added to UD but has not been
// confirmed by the user. It is keyed on the confirmation ID given by UD.
func
(
s
*
Store
)
StoreUnconfirmedFact
(
confirmationId
string
,
f
fact
.
Fact
)
error
{
...
...
@@ -104,7 +124,7 @@ func (s *Store) BackUpMissingFacts(username, email, phone fact.Fact) error {
s
.
mux
.
Lock
()
defer
s
.
mux
.
Unlock
()
modified
Username
,
modifiedEmail
,
modifiedPhone
:=
false
,
false
,
false
modified
:=
false
// Handle email if it is not zero (empty string)
if
!
isFactZero
(
email
)
{
...
...
@@ -118,7 +138,8 @@ func (s *Store) BackUpMissingFacts(username, email, phone fact.Fact) error {
// If an email exists in memory, return an error
return
errors
.
Errorf
(
factTypeExistsErr
,
email
,
fact
.
Email
)
}
else
{
modifiedEmail
=
true
s
.
confirmedFacts
[
email
]
=
struct
{}{}
modified
=
true
}
}
...
...
@@ -134,7 +155,8 @@ func (s *Store) BackUpMissingFacts(username, email, phone fact.Fact) error {
// If a phone exists in memory, return an error
return
errors
.
Errorf
(
factTypeExistsErr
,
phone
,
fact
.
Phone
)
}
else
{
modifiedPhone
=
true
s
.
confirmedFacts
[
phone
]
=
struct
{}{}
modified
=
true
}
}
...
...
@@ -145,23 +167,12 @@ func (s *Store) BackUpMissingFacts(username, email, phone fact.Fact) error {
// If a username exists in memory, return an error
return
errors
.
Errorf
(
factTypeExistsErr
,
username
,
fact
.
Username
)
}
else
{
modifiedUsername
=
true
}
}
if
modifiedPhone
||
modifiedEmail
{
if
modifiedEmail
{
s
.
confirmedFacts
[
email
]
=
struct
{}{}
}
if
modifiedPhone
{
s
.
confirmedFacts
[
phone
]
=
struct
{}{}
}
if
modifiedUsername
{
s
.
confirmedFacts
[
username
]
=
struct
{}{}
modified
=
true
}
}
if
modified
{
return
s
.
saveConfirmedFacts
()
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment