public function submitAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->_forward('index');
     }
     $form = $this->getForm();
     // Validate the form itself
     if (!$form->isValid($_POST)) {
         $this->view->form = $form;
         return $this->render('index');
     }
     // Get the form data
     $values = $form->getValues();
     $email = $values['email'];
     // Find the user
     $users = new Users();
     if (!($user = $users->getUserFromEmail($email))) {
         $this->view->failedRecovery = true;
         return $this->_forward('index');
     }
     // Change the password
     $password = Stuffpress_Token::create(8);
     $users->setPassword($user->id, $password);
     // Send the user an email with the new password
     Stuffpress_Emails::sendRecoveryEmail($email, $user->username, $password);
     // Done !
     $this->view->email = $email;
     $this->render('success');
 }
示例#2
0
文件: Users.php 项目: julien51/core
 public function addUser($username, $password, $email)
 {
     $password = md5($password);
     $token = Stuffpress_Token::create(32);
     $data = array("username" => $username, "password" => $password, "email" => $email, "token" => $token);
     $this->insert($data);
     $id = $this->_db->lastInsertId();
     $user = $this->getUser($id);
     return $user;
 }
示例#3
0
 public function shorten($url, $internal = true)
 {
     // Find a suitable token
     do {
         $token = Stuffpress_Token::create(4);
     } while ($this->getUrl($token));
     // Save the url
     $this->addUrl($token, $url, $internal);
     // Return the token
     return $token;
 }
示例#4
0
 public function uploadimageAction()
 {
     // Where we come from
     $source = $this->_getParam('source');
     // Verify that it is authorized
     if (!in_array($source, array('design', 'profile'))) {
         throw new Stuffpress_Exception("Invalid source specified {$source}");
     }
     // What are we uploading
     $image = $this->_getParam('image');
     $property = "{$image}_image";
     // Was a file uploaded ?
     if (!isset($_FILES['file'])) {
         $this->addErrorMessage('Upload failed: no files received on server end.');
         return $this->_forward('index', $source, 'admin');
     }
     // Validate the uploaded file
     $tmp_file = $_FILES['file']['tmp_name'];
     $file_name = basename($_FILES['file']['name']);
     $file_type = $_FILES['file']['type'];
     $file_ext = substr(trim(substr($file_name, strrpos($file_name, '.')), '.'), 0, 4);
     // returns the ext only
     // Check file size
     if ($_SERVER['CONTENT_LENGTH'] > 2000000) {
         $this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
         return $this->_forward('index', $source, 'admin');
     }
     // Check file extension
     if (!in_array(strtolower($file_ext), array("gif", "jpg", "png", "jpeg"))) {
         $this->addErrorMessage('Upload failed: we only support jpg, gif and png files.');
         return $this->_forward('index', $source, 'admin');
     }
     // Assign a random name to the file
     $key = Stuffpress_Token::create(32);
     $root = Zend_Registry::get("root");
     $uploaddir = $root . "/upload/";
     $uploadfile = $uploaddir . '/' . $key;
     // Move the file to the upload folder
     if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
         $this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
         return $this->_forward('index', $source, 'admin');
     }
     // Store the file in the database
     $files = new Files(array(Stuffpress_Db_Table::USER => $this->_application->user->id));
     $file_id = $files->addFile($key, $file_name, "Lifestream custom image", $file_type, $file_ext);
     // Build a thumbnail of the file
     try {
         $files->fitSquare($file_id, 75, 'thumbnails');
     } catch (Exception $e) {
         $message = $e->getMessage();
         $this->addErrorMessage("Upload failed: could not process image ({$message})");
         $files->deleteFile($key);
         return $this->_forward('index', $source, 'admin');
     }
     // Replace the user property with the new file and delete the older one
     $properties = new Properties(array(Properties::KEY => $this->_application->user->id));
     $old_file = $properties->getProperty($property);
     $properties->setProperty($property, $key);
     if ($old_file) {
         $files->deleteFile($old_file);
     }
     // If we are here, everything went smooth
     $this->addStatusMessage('Your file was successfully uploaded');
     return $this->_forward('index', $source, 'admin');
 }
示例#5
0
 public function saveFile($content, $filename, $mime, $description = "")
 {
     $key = Stuffpress_Token::create(32);
     $root = Zend_Registry::get("root");
     $config = Zend_Registry::get("configuration");
     if (isset($config) && isset($config->path->upload)) {
         $to_path = $config->path->upload . "/{$key}";
     } else {
         $to_path = $root . "/upload/" . $key;
     }
     $matches = array();
     if (preg_match("/(?<name>.+)\\.(?<ext>\\w{3,4})\$/", $filename, $matches)) {
         $name = $matches['name'];
         $ext = $matches['ext'];
     } else {
         $name = "file";
         $ext = "";
     }
     $fp = fopen($to_path, "w");
     fwrite($fp, $content);
     fclose($fp);
     // Get the mime type
     if ($finfo = new finfo(FILEINFO_MIME)) {
         $mimetype = $finfo->file($to_path);
     }
     if (!$mimetype) {
         $mimetype = $mime;
     }
     // Store the file in the database
     $file_id = $this->addFile($key, $filename, $description, $mimetype, $ext);
     return $file_id;
 }
示例#6
0
 public function excelAction()
 {
     // Get the request parameters
     $id = $this->_getParam('id');
     // Get the requested source
     $sources = new Sources();
     if (!($source = $sources->getSource($id))) {
         throw new Stuffpress_Exception("Unknown source id {$id}");
     }
     // Are we the owner of the source
     if ($source['user_id'] != $this->_application->user->id) {
         throw new Stuffpress_Exception("You are not authorized to download this source");
     }
     // Get the source meta data
     $model = SourceModel::newInstance($source['service']);
     $model->setSource($source);
     $service = $model->getServiceName();
     $desc = $model->getServiceDescription();
     // Get the actual data to backup
     $data = new Data();
     $items = $data->getAllItems($source['id']);
     // This is not a layout or rendered page
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     // Start the writer to Excel
     require_once 'PHPExcel.php';
     require_once 'PHPExcel/Writer/Excel2007.php';
     $objPHPExcel = new PHPExcel();
     // Set properties
     $objPHPExcel->getProperties()->setCreator("storytlr.com");
     $objPHPExcel->getProperties()->setLastModifiedBy("storytlr.com");
     $objPHPExcel->getProperties()->setTitle("Backup of {$this->_application->user->username}'s {$service} account");
     //$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
     $objPHPExcel->getProperties()->setDescription($desc);
     // Add some data
     $objPHPExcel->setActiveSheetIndex(0);
     // Write the column titles
     $keys = array_keys($items[0]->getBackup());
     for ($i = 0; $i < count($keys); $i++) {
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $keys[$i]);
     }
     // Write the data
     for ($i = 0; $i < count($items); $i++) {
         $item = $items[$i]->getBackup();
         for ($j = 0; $j < count($keys); $j++) {
             $value = $item[$keys[$j]];
             if ($value) {
                 $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, $i + 2)->setValueExplicit("'{$value}", PHPExcel_Cell_DataType::TYPE_STRING);
             }
         }
     }
     // Rename sheet
     $objPHPExcel->getActiveSheet()->setTitle($service);
     // Save Excel 2007 file
     $root = Zend_Registry::get("root");
     $key = Stuffpress_Token::create(6);
     $file = "{$service}-{$this->_application->user->username}-[{$key}].xls";
     $path = $root . "/public/files/{$file}";
     $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
     $objWriter->save($path);
     $this->_redirect($this->_base . "/files/{$file}");
 }