/** * This handles uploads to a persions channel * Need file posted as 'file' and the has poster as 'hash' */ public function upload() { switch ($this->format) { case 'xml': try { $package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'sig' => $_POST['signatureBase64'], 'user' => $this->user), true); if ($package->saved) { echo 'Package uploaded succesfuly!'; } } catch (Exception $e) { $this->header("HTTP/1.0 500 Internal Server Error", 500); echo $e->getMessage(); } $this->has_rendered = true; break; default: if ($_SESSION['upload_key'] !== $_POST['upload_key']) { Nimble::flash('notice', 'Invalid Upload Key'); $this->redirect_to(url_for('LandingController', 'user_index', $this->user->username)); } unset($_SESSION['upload_key']); try { $package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'user' => $this->user)); if ($package->saved) { $this->redirect_to(url_for('LandingController', 'user_index', $this->user->username)); } } catch (Exception $e) { Nimble::flash('notice', $e->getMessage()); $this->redirect_to(url_for('ChannelController', 'upload')); } break; } }
public static function create_package() { $user = User::find_by_username('bob'); $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz'); $package = Package::from_upload(array('file' => $file, 'user' => $user)); foreach (User::_find('all') as $user) { $raiting = '0.' . $user->id; PackageRating::_create(array('user_id' => $user->id, 'package_id' => $package->id, 'rating' => (double) $raiting)); } }
public function testUploadFailbadSig() { $localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'joes_other_package-1.0.4.tgz'); $sig = PackageVerifyTest::calculatePackageSignature($localfile); $user = User::find_by_username('joe'); try { $p = Package::from_upload(array('file' => $localfile, 'sig' => $sig, 'user' => $user), true); } catch (NimbleException $e) { $this->assertEquals("Invalid package signature", $e->getMessage()); } }
public static function create_package() { $user = User::find_by_username('bob'); $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz'); $pp = Package::from_upload(array('file' => $file, 'user' => $user)); $p = Package::update($pp->id, array('url' => 'http://jetviper21.com')); }