error('io-error', $e->getMessage()); } }); }); $app->post('/products/:id/users', function ($id) use($app) { if_is_admin(function () use($app, $id) { $product = ProductQuery::create()->findPk($id); if ($product) { $data = json_decode($app->request()->getBody(), true); foreach ($data as $newRelation) { $user = UserQuery::create()->findPk($newRelation['id']); if ($user) { $up = new UserProduct(); $up->setUser($user); if ($newRelation['expires']) { $up->setExpires($newRelation['expires']); } $product->addUserProduct($up); } } try { $product->save(); ok($up); } catch (Exception $e) { error('io-error', $e->getMessage()); } } else { return error('unknown-product', 'Product not found'); } }); });
} else { error('empty-password', __('The password must not be empty.')); } } else { error('invalid-token', __('The supplied token for password resetting is invalid.')); } } }); $app->post('/user/:id/products', function ($id) use($app) { if_is_admin(function () use($app, $id) { $user = UserQuery::create()->findPk($id); if ($user) { $data = json_decode($app->request()->getBody(), true); foreach ($data as $p_id => $expires) { $product = ProductQuery::create()->findPk($p_id); if ($product) { $up = new UserProduct(); $up->setProduct($product); if ($expires) { $up->setExpires($expires); } $user->addUserProduct($up); } } $user->save(); ok(); } else { error('user-not-found', 'no user found with that id'); } }); });