Allow using username as identifier
This commit is contained in:
parent
ada2f91a84
commit
59b315f209
@ -35,6 +35,7 @@ func NewServer(config *Config) (*UserServer, error) {
|
|||||||
r.Get("/", InfoHandler)
|
r.Get("/", InfoHandler)
|
||||||
r.Post("/users", srv.CreateUserHandler)
|
r.Post("/users", srv.CreateUserHandler)
|
||||||
r.Post("/users/:id/password", srv.SetPasswordHandler)
|
r.Post("/users/:id/password", srv.SetPasswordHandler)
|
||||||
|
r.Post("/users/:username/verify", srv.VerifyHandler)
|
||||||
|
|
||||||
srv.Addr = config.ListenAddr
|
srv.Addr = config.ListenAddr
|
||||||
|
|
||||||
|
@ -51,9 +51,16 @@ func (s *MemoryStore) UpdateUser(u users.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MemoryStore) GetUser(id string) (users.User, error) {
|
func (s *MemoryStore) GetUser(identifier string) (users.User, error) {
|
||||||
u, ok := s.Users[id]
|
u, ok := s.Users[identifier]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// Check if identifier is username
|
||||||
|
for _, u := range s.Users {
|
||||||
|
if u.Username == identifier {
|
||||||
|
return u, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return u, ErrNoSuchUser
|
return u, ErrNoSuchUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,5 +6,5 @@ type UserStore interface {
|
|||||||
AddUser(users.User) error
|
AddUser(users.User) error
|
||||||
DeleteUser(id string) error
|
DeleteUser(id string) error
|
||||||
UpdateUser(users.User) error
|
UpdateUser(users.User) error
|
||||||
GetUser(id string) (users.User, error)
|
GetUser(identifier string) (users.User, error)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
package users
|
package users
|
||||||
|
|
||||||
const Version = "v0.1.0"
|
const Version = "v0.1.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user