From 59b315f20971e60861a736a10b897f7824589797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 21 Oct 2023 02:15:19 +0200 Subject: [PATCH] Allow using username as identifier --- server/server.go | 1 + store/memory.go | 11 +++++++++-- store/store.go | 2 +- version.go | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server/server.go b/server/server.go index aa57c3c..e1715c3 100644 --- a/server/server.go +++ b/server/server.go @@ -35,6 +35,7 @@ func NewServer(config *Config) (*UserServer, error) { r.Get("/", InfoHandler) r.Post("/users", srv.CreateUserHandler) r.Post("/users/:id/password", srv.SetPasswordHandler) + r.Post("/users/:username/verify", srv.VerifyHandler) srv.Addr = config.ListenAddr diff --git a/store/memory.go b/store/memory.go index a3610f8..9c46b48 100644 --- a/store/memory.go +++ b/store/memory.go @@ -51,9 +51,16 @@ func (s *MemoryStore) UpdateUser(u users.User) error { return nil } -func (s *MemoryStore) GetUser(id string) (users.User, error) { - u, ok := s.Users[id] +func (s *MemoryStore) GetUser(identifier string) (users.User, error) { + u, ok := s.Users[identifier] if !ok { + // Check if identifier is username + for _, u := range s.Users { + if u.Username == identifier { + return u, nil + } + } + return u, ErrNoSuchUser } diff --git a/store/store.go b/store/store.go index 45a3612..1350dd4 100644 --- a/store/store.go +++ b/store/store.go @@ -6,5 +6,5 @@ type UserStore interface { AddUser(users.User) error DeleteUser(id string) error UpdateUser(users.User) error - GetUser(id string) (users.User, error) + GetUser(identifier string) (users.User, error) } diff --git a/version.go b/version.go index 0460a4d..4d0288d 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package users -const Version = "v0.1.0" +const Version = "v0.1.1"