Skip to content

Commit

Permalink
Update sample to reflect changes to storers
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed May 25, 2018
1 parent 96684a7 commit 7aca750
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ type User struct {
Password string

// Confirm
ConfirmToken string
Confirmed bool
ConfirmSelector string
ConfirmVerifier string
Confirmed bool

// Lock
AttemptCount int
LastAttempt time.Time
Locked time.Time

// Recover
RecoverToken string
RecoverSelector string
RecoverVerifier string
RecoverTokenExpiry time.Time

// OAuth2
Expand Down Expand Up @@ -76,8 +78,11 @@ func (u *User) PutEmail(email string) { u.Email = email }
// PutConfirmed into user
func (u *User) PutConfirmed(confirmed bool) { u.Confirmed = confirmed }

// PutConfirmToken into user
func (u *User) PutConfirmToken(confirmToken string) { u.ConfirmToken = confirmToken }
// PutConfirmSelector into user
func (u *User) PutConfirmSelector(confirmSelector string) { u.ConfirmSelector = confirmSelector }

// PutConfirmVerifier into user
func (u *User) PutConfirmVerifier(confirmVerifier string) { u.ConfirmVerifier = confirmVerifier }

// PutLocked into user
func (u *User) PutLocked(locked time.Time) { u.Locked = locked }
Expand All @@ -88,8 +93,11 @@ func (u *User) PutAttemptCount(attempts int) { u.AttemptCount = attempts }
// PutLastAttempt into user
func (u *User) PutLastAttempt(last time.Time) { u.LastAttempt = last }

// PutRecoverToken into user
func (u *User) PutRecoverToken(token string) { u.RecoverToken = token }
// PutRecoverSelector into user
func (u *User) PutRecoverSelector(token string) { u.RecoverSelector = token }

// PutRecoverVerifier into user
func (u *User) PutRecoverVerifier(token string) { u.RecoverVerifier = token }

// PutRecoverExpiry into user
func (u *User) PutRecoverExpiry(expiry time.Time) { u.RecoverTokenExpiry = expiry }
Expand Down Expand Up @@ -128,8 +136,11 @@ func (u User) GetEmail() string { return u.Email }
// GetConfirmed from user
func (u User) GetConfirmed() bool { return u.Confirmed }

// GetConfirmToken from user
func (u User) GetConfirmToken() string { return u.ConfirmToken }
// GetConfirmSelector from user
func (u User) GetConfirmSelector() string { return u.ConfirmSelector }

// GetConfirmVerifier from user
func (u User) GetConfirmVerifier() string { return u.ConfirmVerifier }

// GetLocked from user
func (u User) GetLocked() time.Time { return u.Locked }
Expand All @@ -140,8 +151,11 @@ func (u User) GetAttemptCount() int { return u.AttemptCount }
// GetLastAttempt from user
func (u User) GetLastAttempt() time.Time { return u.LastAttempt }

// GetRecoverToken from user
func (u User) GetRecoverToken() string { return u.RecoverToken }
// GetRecoverSelector from user
func (u User) GetRecoverSelector() string { return u.RecoverSelector }

// GetRecoverVerifier from user
func (u User) GetRecoverVerifier() string { return u.RecoverVerifier }

// GetRecoverExpiry from user
func (u User) GetRecoverExpiry() time.Time { return u.RecoverTokenExpiry }
Expand Down Expand Up @@ -244,23 +258,23 @@ func (m MemStorer) Create(ctx context.Context, user authboss.User) error {
return nil
}

// LoadByConfirmToken looks a user up by confirmation token
func (m MemStorer) LoadByConfirmToken(ctx context.Context, token string) (user authboss.ConfirmableUser, err error) {
// LoadByConfirmSelector looks a user up by confirmation token
func (m MemStorer) LoadByConfirmSelector(ctx context.Context, selector string) (user authboss.ConfirmableUser, err error) {
for _, v := range m.Users {
if v.ConfirmToken == token {
debugln("Loaded user by confirm token:", token, v.Name)
if v.ConfirmSelector == selector {
debugln("Loaded user by confirm selector:", selector, v.Name)
return &v, nil
}
}

return nil, authboss.ErrUserNotFound
}

// LoadByRecoverToken looks a user up by confirmation token
func (m MemStorer) LoadByRecoverToken(ctx context.Context, token string) (user authboss.RecoverableUser, err error) {
// LoadByRecoverSelector looks a user up by confirmation selector
func (m MemStorer) LoadByRecoverSelector(ctx context.Context, selector string) (user authboss.RecoverableUser, err error) {
for _, v := range m.Users {
if v.RecoverToken == token {
debugln("Loaded user by recover token:", token, v.Name)
if v.RecoverSelector == selector {
debugln("Loaded user by recover selector:", selector, v.Name)
return &v, nil
}
}
Expand Down

0 comments on commit 7aca750

Please sign in to comment.