Add admin password reset functionality for users and customers
This commit is contained in:
@@ -240,6 +240,51 @@ func (h *Handler) UpdateStatus(c echo.Context) error {
|
||||
}, "Customer status updated successfully")
|
||||
}
|
||||
|
||||
// ResetCustomerPassword resets a customer's password (admin only).
|
||||
// @Summary Reset customer password
|
||||
// @Description Generate a new password for a customer. The plaintext is returned once for manual delivery.
|
||||
// @Tags Admin-Customers
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path string true "Customer ID"
|
||||
// @Success 200 {object} response.APIResponse{data=AdminResetPasswordResponse}
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 403 {object} response.APIResponse
|
||||
// @Failure 404 {object} response.APIResponse
|
||||
// @Failure 409 {object} response.APIResponse
|
||||
// @Failure 429 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /admin/v1/customers/{id}/reset-password [post]
|
||||
func (h *Handler) ResetCustomerPassword(c echo.Context) error {
|
||||
c.Response().Header().Set("Cache-Control", "no-store")
|
||||
|
||||
actorID, err := user.GetUserIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.Unauthorized(c, "Unauthorized")
|
||||
}
|
||||
|
||||
targetID := c.Param("id")
|
||||
result, err := h.service.AdminResetPassword(c.Request().Context(), actorID, targetID)
|
||||
if err != nil {
|
||||
switch err.Error() {
|
||||
case errInvalidCustomerID.Error():
|
||||
return response.BadRequest(c, "Invalid id", "")
|
||||
case errCustomerNotFound.Error():
|
||||
return response.NotFound(c, "Customer not found")
|
||||
case errCannotResetCustPassword.Error():
|
||||
return response.Conflict(c, "Cannot reset password for this user")
|
||||
case errCustResetPasswordRate.Error():
|
||||
return response.TooManyRequests(c, "Too many password reset requests")
|
||||
default:
|
||||
return response.InternalServerError(c, "Failed to reset password")
|
||||
}
|
||||
}
|
||||
|
||||
return response.Success(c, result, "Password has been reset successfully")
|
||||
}
|
||||
|
||||
// AssignRole assigns a role to a customer (Web Panel)
|
||||
// @Summary Assign role to customer
|
||||
// @Description Assign a role (admin or analyst) to a customer
|
||||
|
||||
Reference in New Issue
Block a user