get('email'); $user = DB::query('select id,username,password from users where email=:email', ['email' => $email])->fetch(); if (empty($user)) { $password = password_hash($request->get('password'), PASSWORD_DEFAULT); DB::query('insert into users (username, password, email) values (:username, :password, :email)', ['username' => $email, 'password' => $password, 'email' => $email]); } else { $password = $user['password']; } if (password_verify($request->get('password'), $password)) { $_SESSION['user'] = [ 'id' => $user['id'], 'username' => $user['username'], ]; return new RedirectResponse('/villages'); } return new RedirectResponse('/login'); } #[Route(path: '/logout', methods: ['GET'])] public function logout(Request $request): Response { session_unset(); session_destroy(); return new RedirectResponse('/login'); } }