Allow using username as identifier

This commit is contained in:
Torjus Håkestad 2023-10-21 02:15:19 +02:00
parent ada2f91a84
commit 59b315f209
4 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)
}

View File

@ -1,3 +1,3 @@
package users
const Version = "v0.1.0"
const Version = "v0.1.1"