tsk-30: Update password (#33)

Closes #30

Reviewed-on: phoenix/textsender-auth#33
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-12-26 21:14:40 +00:00
committed by phoenix
parent 760a778a27
commit d34cad033d
22 changed files with 727 additions and 98 deletions
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"sync"
"time"
"github.com/google/uuid"
@@ -37,9 +38,11 @@ func (m *MockUserStore) CreateUser(ctx context.Context, user *user.User) error {
}
if _, exists := m.UsersByUsername[user.Username]; exists {
return errors.New("User with email already exists")
return errors.New("User with username already exists")
}
user.Created = time.Now()
m.Users[user.Id] = user
m.UsersByUsername[user.Username] = user
return nil
@@ -112,3 +115,24 @@ func (m *MockUserStore) UserExists(ctx context.Context, username string) (bool,
return exists, nil
}
}
func (m *MockUserStore) UpdatePassword(ctx context.Context, id uuid.UUID, password string) (int64, error) {
m.mu.Lock()
defer m.mu.Unlock()
if m.Error != nil {
return 0, m.Error
}
user, exists := m.Users[id]
if !exists {
return 0, errors.New("User not found")
}
user.Password = password
m.Users[id] = user
m.UsersByUsername[user.Username] = user
return 1, nil
}