diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 01424b0..0bcf755 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -19,15 +19,28 @@ use Twig\TwigFunction; class UserController extends Controller{ public function actionCreate(): void { -// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views'); -// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']); echo $this->twig->render('user_create.html.twig'); } public function actionAdd(): void { $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT); - User::create($_REQUEST); + + foreach ($_REQUEST as $key => $value) + { +// Debug::prn(User::where([$key => $value])->get()->toArray()); +// Debug::prn($user); +// Debug::dd($user->toArray()); + if (User::where([$key => $value])->get()->toArray() !== null) + { + header("Location: http://itguild-framework.loc/admin/user/create"); + } + else + { + User::create($_REQUEST); + header("Location: http://itguild-framework.loc/admin/user/"); + } + } } public function actionQuestionCount($user_id) @@ -64,6 +77,7 @@ class UserController extends Controller{ public function actionView($id): void { $user = User::find($id); + if (!$user){ throw new Exception(message: "The user not found"); }