Merge pull request 'Allow using username as identifier' (#1) from allow-username-as-identifier into master

Reviewed-on: microfilm/mf-users#1
This commit is contained in:
Torjus Håkestad 2023-10-21 00:16:16 +00:00
commit 403ce8365f
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"