/**
  * 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 function delete()
 {
     $this->login_user();
     try {
         $package = Package::find('first', array('conditions' => array('id' => $_GET['id'], 'user_id' => $this->user->id)));
         $package->clear_all_version();
         Nimble::flash('notice', $package->name . " was deleted");
         $package->destroy();
         $this->redirect_to('/');
     } catch (NimbleRecordNotFound $e) {
         Nimble::flash('notice', "Package does not exist or does not belong to you");
         $this->redirect_to('/');
     }
 }
 public function show()
 {
     require_once FileUtils::join(NIMBLE_ROOT, 'lib', 'markdown.php');
     $filename = $_GET['name'] . '.markdown';
     $this->title = ucwords(Inflector::humanize($_GET['name'] . ' help'));
     Nimble::set_title($this->title);
     if (array_include($filename, array_map(function ($f) {
         return basename($f);
     }, $this->files))) {
         $this->file = file_get_contents(FileUtils::join($this->markdown_dir, $filename));
     } else {
         Nimble::flash('notice', 'No page found for ' . $_GET['name']);
         $this->redirect_to(url_for('HelpController', 'index'));
     }
 }
 public function delete()
 {
     $this->login_user();
     try {
         $package = Package::find($_GET['id']);
         $version = Version::find($_GET['version']);
     } catch (NimbleRecordNotFound $e) {
         $this->redirect_to('/');
     }
     if ($version->package_id == $package->id && $package->user_id == $this->user->id) {
         $file = $package->file_path($version->version);
         @unlink($file);
         Nimble::flash('notice', "Version: {$version->version} was deleted");
         $version->delete();
         $this->redirect_to(url_for('PackageController', 'show', $package->user->username, $package->name));
     } else {
         $this->redirect_to('/');
     }
 }
 public function delete()
 {
     foreach ($this->user->packages as $package) {
         $package->clear_all_version();
         $package->destroy();
     }
     User::delete($this->user->id);
     unset($_SESSION['user']);
     session_destroy();
     Nimble::flash('notice', 'Your account as been deleted');
     $this->redirect_to("http://" . DOMAIN);
 }
 public function verify()
 {
     try {
         $user = User::find_by_api_key($_GET['key']);
         $user->active = 1;
         if ($user->save()) {
             Nimble::flash('notice', 'Account has been activated please login');
             $this->redirect_to(url_for('LoginController', 'login'));
         }
     } catch (NimbleRecordNotFound $e) {
         Nimble::flash('notice', 'Invaild activation key');
         $this->redirect_to('/');
     }
 }