/** * @Route("{categoryId:num}/products") */ public function getProducts($categoryId) { $products = $this->eshopData->getCategoriesRepository()->findById($categoryId); $viewModel = new CategoryViewModel(); $viewModel->products = $products; return new View('category/products', $viewModel); }
/** * @param LoginBindingModel $model * @throws \Exception * @POST */ public function login(LoginBindingModel $model) { $username = $model->getUsername(); $password = $model->getPassword(); $user = $this->eshopData->getUsersRepository()->findByUsername($username); if ($user === false || !password_verify($password, $user->getPassword())) { throw new \Exception('Invalid credentials'); } if ($user->getIsBanned()) { throw new \Exception("This account is banned"); } Session::put('userId', $user->getId()); Session::put('roles', implode(', ', RoleService::getUserRoles($user->getId()))); RouteService::redirect('account', 'profile', true); }
/** * @POST * @Roles(Administrator, Editor) * @Route("{id:num}") */ public function changeCategory($id, ChangeProductCategoryBindingModel $model) { $result = $this->eshopData->getProductsRepository()->changeCategory($id, $model->getCategoryId()); RouteService::redirect('products', '', [$id], true); }
/** * @POST * @Roles(Administrator) */ public function banip(BanIpBindingModel $model) { $this->eshopData->getUsersRepository()->banIP($model->getIpAddress()); RouteService::redirect('admin', 'ban', [], true); }