<?php

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

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