1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-01 19:10:36 +02:00
This commit is contained in:
binwiederhier 2022-12-21 21:55:39 -05:00
parent d982ce13f5
commit b5e2c83fba
9 changed files with 113 additions and 63 deletions

View file

@ -12,7 +12,7 @@ func (s *Server) handleAccountCreate(w http.ResponseWriter, r *http.Request, v *
signupAllowed := s.config.EnableSignup
admin := v.user != nil && v.user.Role == auth.RoleAdmin
if !signupAllowed && !admin {
return errHTTPUnauthorized
return errHTTPBadRequestSignupNotEnabled
}
body, err := util.Peek(r.Body, 4096) // FIXME
if err != nil {
@ -23,6 +23,9 @@ func (s *Server) handleAccountCreate(w http.ResponseWriter, r *http.Request, v *
if err := json.NewDecoder(body).Decode(&newAccount); err != nil {
return err
}
if existingUser, _ := s.auth.User(newAccount.Username); existingUser != nil {
return errHTTPConflictUserExists
}
if err := s.auth.AddUser(newAccount.Username, newAccount.Password, auth.RoleUser); err != nil { // TODO this should return a User
return err
}