mirror of https://github.com/portainer/portainer
fix(api): check if admin user already exists when calling the /users/admin/init endpoint (#494)
parent
2bdc9322de
commit
27e584fc14
|
@ -8,6 +8,7 @@ const (
|
||||||
// User errors.
|
// User errors.
|
||||||
const (
|
const (
|
||||||
ErrUserNotFound = Error("User not found")
|
ErrUserNotFound = Error("User not found")
|
||||||
|
ErrAdminAlreadyInitialized = Error("Admin user already initialized")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Endpoint errors.
|
// Endpoint errors.
|
||||||
|
|
|
@ -227,6 +227,8 @@ func (handler *UserHandler) handlePostAdminInit(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user, err := handler.UserService.User("admin")
|
||||||
|
if err == portainer.ErrUserNotFound {
|
||||||
user := &portainer.User{
|
user := &portainer.User{
|
||||||
Username: "admin",
|
Username: "admin",
|
||||||
}
|
}
|
||||||
|
@ -241,6 +243,14 @@ func (handler *UserHandler) handlePostAdminInit(w http.ResponseWriter, r *http.R
|
||||||
Error(w, err, http.StatusInternalServerError, handler.Logger)
|
Error(w, err, http.StatusInternalServerError, handler.Logger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
Error(w, err, http.StatusInternalServerError, handler.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if user != nil {
|
||||||
|
Error(w, portainer.ErrAdminAlreadyInitialized, http.StatusForbidden, handler.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type postAdminInitRequest struct {
|
type postAdminInitRequest struct {
|
||||||
|
|
Loading…
Reference in New Issue