iaematt /
cafeapi
| 1 | <?php |
||
| 2 | |||
| 3 | /** Require files */ |
||
| 4 | require __DIR__ . '/assets/config.php'; |
||
| 5 | require __DIR__ . '/../vendor/autoload.php'; |
||
| 6 | |||
| 7 | /** Dependencies */ |
||
| 8 | use MatheusBastos\CafeApi\Me; |
||
| 9 | |||
| 10 | $me = new Me('localhost/fsphp/api/', '[email protected]', 'senhasecreta'); |
||
| 11 | |||
| 12 | /** Get data user */ |
||
| 13 | echo '<h1>Me</h1>'; |
||
| 14 | |||
| 15 | $user = $me->me(); |
||
| 16 | var_dump($user->response()); |
||
| 17 | |||
| 18 | /** Update data user */ |
||
| 19 | echo '<h1>Update</h1>'; |
||
| 20 | |||
| 21 | $update = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRIPPED); |
||
| 22 | |||
| 23 | if ($update && !empty($update['user'])) { |
||
| 24 | $user->update($update); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | |||
| 26 | if ($user->error()) { |
||
| 27 | echo "<p class='error'>{$user->error()->message}</p>"; |
||
| 28 | } else { |
||
| 29 | var_dump($user->response()->user); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | $user_data = $user->me()->response()->user; |
||
| 34 | ?> |
||
| 35 | <form action="" method="post"> |
||
| 36 | <input type="hidden" name="user" value="true"/> |
||
| 37 | <input type="text" name="first_name" value="<?= $user_data->first_name ?? null ?>"/> |
||
| 38 | <input type="text" name="last_name" value="<?= $user_data->last_name ?? null ?>"/> |
||
| 39 | <input type="text" name="genre" value="<?= $user_data->genre ?? null ?>"/> |
||
| 40 | <input type="text" name="date_birth" value="<?= $user_data->date_birth ?? null ?>"/> |
||
| 41 | <input type="text" name="document" value="<?= $user_data->document ?? null ?>"/> |
||
| 42 | <button>Atualizar</button> |
||
| 43 | </form> |
||
| 44 | <?php |
||
| 45 | /** Upload a new photo for user */ |
||
| 46 | echo '<h1>Photo</h1>'; |
||
| 47 | |||
| 48 | $photo = $_FILES['photo'] ?? null; |
||
| 49 | |||
| 50 | if ($photo) { |
||
| 51 | $user->photo($photo); |
||
| 52 | |||
| 53 | if ($user->error()) { |
||
| 54 | echo "<p class='error'>{$user->error()->message}</p>"; |
||
| 55 | } else { |
||
| 56 | var_dump($user->me()->response()->user->photo); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | ?> |
||
| 60 | <form action="" method="post" enctype="multipart/form-data"> |
||
| 61 | <input type="file" name="photo"/> |
||
| 62 | <button>Enviar</button> |
||
| 63 | </form> |
||
| 64 |