<?php

return [
  'pattern' => '/update-password.json',
  'method' => 'POST',
  'action' => function() {
    $json = file_get_contents("php://input");
    $data = json_decode($json);

    try {
      kirby()->user()->changePassword($data->password);
      return [
        'status' => 'success'
      ];
    } catch (\Throwable $th) {
      return [
        'status' => 'error',
        'message' => 'Impossible de mettre à jour le mot de passe : ' . $th->getMessage() . ' in file ' . $th->getFile() . ' line ' . $th->getLine()
      ];
    }
  }
];