diff options
| author | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
| commit | ae217a6e4b0c29346381e2a410fd7810cb33ce3f (patch) | |
| tree | 206f604c9297deabf78bb33f31a1e6b9303d2258 /src/controller/UserController.php | |
| parent | 99d2616a08c98e7067cdb12f0bcbd4ac0cffaeb0 (diff) | |
| download | cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.gz cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.bz2 cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.zip | |
Tous les contrôleurs retournent une Response!
Diffstat (limited to 'src/controller/UserController.php')
| -rw-r--r-- | src/controller/UserController.php | 57 |
1 files changed, 18 insertions, 39 deletions
diff --git a/src/controller/UserController.php b/src/controller/UserController.php index 9de2fb8..ddba33a 100644 --- a/src/controller/UserController.php +++ b/src/controller/UserController.php | |||
| @@ -16,27 +16,12 @@ declare(strict_types=1); | |||
| 16 | use Doctrine\ORM\EntityManager; | 16 | use Doctrine\ORM\EntityManager; |
| 17 | use App\Entity\User; | 17 | use App\Entity\User; |
| 18 | use App\Entity\Log; | 18 | use App\Entity\Log; |
| 19 | use Symfony\Component\HttpFoundation\RedirectResponse; | ||
| 19 | 20 | ||
| 20 | class UserController | 21 | class UserController |
| 21 | { | 22 | { |
| 22 | // account | 23 | // account |
| 23 | static public function existUsers(EntityManager $entityManager): bool | 24 | static public function createAdminUser(EntityManager $entityManager): RedirectResponse |
| 24 | { | ||
| 25 | if(!$entityManager // table vide | ||
| 26 | ->createQuery("SELECT u FROM App\Entity\User u") | ||
| 27 | ->setMaxResults(1) | ||
| 28 | ->getOneOrNullResult()) | ||
| 29 | { | ||
| 30 | unset($_SESSION['user']); | ||
| 31 | return false; | ||
| 32 | } | ||
| 33 | else{ | ||
| 34 | return true; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | // account | ||
| 39 | static public function createAdminUser(EntityManager $entityManager) | ||
| 40 | { | 25 | { |
| 41 | unset($_SESSION['user']); | 26 | unset($_SESSION['user']); |
| 42 | 27 | ||
| @@ -58,20 +43,18 @@ class UserController | |||
| 58 | $url->addParams(['error' => $error]); | 43 | $url->addParams(['error' => $error]); |
| 59 | } | 44 | } |
| 60 | 45 | ||
| 61 | header('Location: ' . $url); | 46 | return new RedirectResponse((string)$url); |
| 62 | die; | ||
| 63 | } | 47 | } |
| 64 | 48 | ||
| 65 | // account | 49 | // account |
| 66 | //static public function createUser(EntityManager $entityManager){} | 50 | //static public function createUser(EntityManager $entityManager){} |
| 67 | 51 | ||
| 68 | // auth | 52 | // auth |
| 69 | static public function connect(EntityManager $entityManager): void | 53 | static public function connect(EntityManager $entityManager): RedirectResponse |
| 70 | { | 54 | { |
| 71 | if(IS_ADMIN) // déjà connecté? | 55 | $url = new URL; |
| 72 | { | 56 | if(IS_ADMIN){ // déjà connecté? |
| 73 | header('Location: ' . new URL); | 57 | return new RedirectResponse((string)$url); |
| 74 | die; | ||
| 75 | } | 58 | } |
| 76 | unset($_SESSION['user']); | 59 | unset($_SESSION['user']); |
| 77 | 60 | ||
| @@ -101,7 +84,7 @@ class UserController | |||
| 101 | echo '<script>window.error_message = "' . $e->getMessage() . '";</script>'; | 84 | echo '<script>window.error_message = "' . $e->getMessage() . '";</script>'; |
| 102 | } | 85 | } |
| 103 | 86 | ||
| 104 | $url = new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []); | 87 | $url->addParams(isset($_GET['from']) ? ['page' => $_GET['from']] : []); |
| 105 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; | 88 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; |
| 106 | } | 89 | } |
| 107 | else | 90 | else |
| @@ -118,18 +101,17 @@ class UserController | |||
| 118 | 101 | ||
| 119 | if(!empty($error)){ | 102 | if(!empty($error)){ |
| 120 | sleep(1); // défense basique à la force brute | 103 | sleep(1); // défense basique à la force brute |
| 121 | $url = new URL(['page' => 'connection']); | 104 | $url->addParams(['page' => 'connection']); |
| 122 | isset($_GET['from']) ? $url->addParams(['from' => $_GET['from']]) : null; | 105 | isset($_GET['from']) ? $url->addParams(['from' => $_GET['from']]) : null; |
| 123 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : null; | 106 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : null; |
| 124 | $url->addParams(['error' => $error]); | 107 | $url->addParams(['error' => $error]); |
| 125 | } | 108 | } |
| 126 | 109 | ||
| 127 | header('Location: ' . $url); | 110 | return new RedirectResponse((string)$url); |
| 128 | die; | ||
| 129 | } | 111 | } |
| 130 | 112 | ||
| 131 | // auth | 113 | // auth |
| 132 | static public function disconnect(): void | 114 | static public function disconnect(): RedirectResponse |
| 133 | { | 115 | { |
| 134 | // nettoyage complet | 116 | // nettoyage complet |
| 135 | unset($_SESSION['user']); // mémoire vive | 117 | unset($_SESSION['user']); // mémoire vive |
| @@ -140,15 +122,14 @@ class UserController | |||
| 140 | $url = new URL; | 122 | $url = new URL; |
| 141 | isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; | 123 | isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; |
| 142 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; | 124 | isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; |
| 143 | header('Location: ' . $url); | 125 | return new RedirectResponse('Location: ' . $url); |
| 144 | die; | ||
| 145 | } | 126 | } |
| 146 | 127 | ||
| 147 | // user | 128 | // user |
| 148 | static public function updateUsername(EntityManager $entityManager): void | 129 | static public function updateUsername(EntityManager $entityManager): RedirectResponse |
| 149 | { | 130 | { |
| 150 | if(!IS_ADMIN){ // superflux, fait dans le routeur | 131 | if(!IS_ADMIN){ // superflux, fait dans le routeur |
| 151 | self::disconnect(); | 132 | return self::disconnect(); |
| 152 | } | 133 | } |
| 153 | 134 | ||
| 154 | $url = new URL(['page' => 'user_edit']); | 135 | $url = new URL(['page' => 'user_edit']); |
| @@ -180,15 +161,14 @@ class UserController | |||
| 180 | sleep(1); | 161 | sleep(1); |
| 181 | $url->addParams(['error_username' => $error]); | 162 | $url->addParams(['error_username' => $error]); |
| 182 | } | 163 | } |
| 183 | header('Location: ' . $url); | 164 | return new RedirectResponse('Location: ' . $url); |
| 184 | die; | ||
| 185 | } | 165 | } |
| 186 | 166 | ||
| 187 | // user | 167 | // user |
| 188 | static public function updatePassword(EntityManager $entityManager): void | 168 | static public function updatePassword(EntityManager $entityManager): RedirectResponse |
| 189 | { | 169 | { |
| 190 | if(!IS_ADMIN){ // superflux, fait dans le routeur | 170 | if(!IS_ADMIN){ // superflux, fait dans le routeur |
| 191 | self::disconnect(); | 171 | return self::disconnect(); |
| 192 | } | 172 | } |
| 193 | 173 | ||
| 194 | $url = new URL(['page' => 'user_edit']); | 174 | $url = new URL(['page' => 'user_edit']); |
| @@ -220,8 +200,7 @@ class UserController | |||
| 220 | sleep(1); | 200 | sleep(1); |
| 221 | $url->addParams(['error_password' => $error]); | 201 | $url->addParams(['error_password' => $error]); |
| 222 | } | 202 | } |
| 223 | header('Location: ' . $url); | 203 | return new RedirectResponse('Location: ' . $url); |
| 224 | die; | ||
| 225 | } | 204 | } |
| 226 | 205 | ||
| 227 | // dans une classe mère ou un trait après découpage de UserController? | 206 | // dans une classe mère ou un trait après découpage de UserController? |
