public function uploadAction()
 {
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return;
     }
     $name = $this->_getParam('name', false);
     $upload = new Zend_File_Transfer();
     $upload->addValidator('Count', false, 1);
     if (!$upload->isValid()) {
         return;
     }
     $upload->receive();
     $file = $upload->getFileName();
     $fp = fopen($file, "r");
     if (!$fp) {
         return;
     }
     $mime = $upload->getMimeType();
     if (!$name) {
         // get short name
         $name = $upload->getFileName(null, false);
     }
     $this->_storage->storeItem($name, $fp, array(Zend_Cloud_StorageService_Adapter_S3::METADATA => array("type" => $mime)));
     try {
         $this->_storage->storeMetadata($name, array("type" => $mime));
     } catch (Zend_Cloud_OperationNotAvailableException $e) {
         // ignore it
     }
     return $this->_helper->redirector('index');
 }
Пример #2
0
 /**
  * 上传用户文件的action 
  */
 public function uploadUserDocAction()
 {
     $this->_helper->layout->disableLayout();
     $doctype = $this->request->getParam('doctype');
     $this->view->doctype = $doctype;
     $result = 0;
     if ($this->request->isPost()) {
         $upload = new Zend_File_Transfer();
         $upload->addValidator('Size', false, 10240000);
         //10M
         $utilService = $this->_container->get('util');
         $fileService = $this->_container->get('file');
         $filename = $utilService->getFilename($upload->getFileName());
         $extension = $fileService->getExtensionByFilename($filename);
         $destination = $utilService->getTmpDirectory() . DIRECTORY_SEPARATOR . uniqid();
         $upload->addFilter('Rename', $destination);
         if ($upload->isValid()) {
             if ($upload->receive()) {
                 $userModel = $this->getModel('user');
                 $mimetype = $upload->getMimeType();
                 if ($fileService->isAcceptedDocument($mimetype, $extension)) {
                     $user = $userModel->getUserById($this->me->getId());
                     if ($user) {
                         $doc = null;
                         if ($doctype == \Angel_Model_User::FILETYPE_IDENTITY_FRONT || $doctype == \Angel_Model_User::FILETYPE_IDENTITY_BACK) {
                             $doc = $userModel->addUserDoc($user, $doctype, $destination, $filename, $mimetype);
                         }
                         if ($doc) {
                             $result = 1;
                             $this->view->filename = $doc->filename;
                             $this->view->path = $this->view->url(array('doctype' => $doctype, 'user_id' => $user->id, 'doc_id' => $doc->id), 'user-doc');
                         }
                     }
                 } else {
                     // 上传的文件格式不接受
                     $result = 2;
                 }
             }
         }
     }
     $this->view->result = $result;
 }
Пример #3
0
 /** Settings page action */
 public function settingsAction()
 {
     if (!$this->logged || $this->isDemoMode()) {
         $this->disableView();
         return false;
     }
     $userId = $this->getParam('userId');
     if (isset($userId) && $userId != $this->userSession->Dao->getKey() && !$this->userSession->Dao->isAdmin()) {
         throw new Zend_Exception(MIDAS_ADMIN_PRIVILEGES_REQUIRED);
     } elseif (isset($userId)) {
         $userDao = $this->User->load($userId);
     } else {
         $userDao = $this->userSession->Dao;
     }
     if (empty($userDao) || $userDao == false) {
         throw new Zend_Exception('Unable to load user');
     }
     $notifications = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_ALLOW_PASSWORD_CHANGE', array('user' => $userDao, 'currentUser' => $this->userSession->Dao));
     $this->view->allowPasswordChange = true;
     foreach ($notifications as $allow) {
         if ($allow['allow'] === false) {
             $this->view->allowPasswordChange = false;
             break;
         }
     }
     $defaultValue = array();
     $defaultValue['email'] = $userDao->getEmail();
     $defaultValue['firstname'] = $userDao->getFirstname();
     $defaultValue['lastname'] = $userDao->getLastname();
     $defaultValue['company'] = $userDao->getCompany();
     $defaultValue['privacy'] = $userDao->getPrivacy();
     $defaultValue['city'] = $userDao->getCity();
     $defaultValue['country'] = $userDao->getCountry();
     $defaultValue['website'] = $userDao->getWebsite();
     $defaultValue['biography'] = $userDao->getBiography();
     $accountForm = $this->Form->User->createAccountForm($defaultValue);
     $this->view->accountForm = $this->getFormAsArray($accountForm);
     $this->view->prependFields = array();
     $this->view->appendFields = array();
     $moduleFields = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_USER_PROFILE_FIELDS', array('user' => $userDao, 'currentUser' => $this->userSession->Dao));
     foreach ($moduleFields as $field) {
         if (isset($field['position']) && $field['position'] == 'top') {
             $this->view->prependFields[] = $field;
         } else {
             $this->view->appendFields[] = $field;
         }
     }
     if ($this->_request->isPost()) {
         $this->disableView();
         $this->disableLayout();
         $submitPassword = $this->getParam('modifyPassword');
         $modifyAccount = $this->getParam('modifyAccount');
         $modifyPicture = $this->getParam('modifyPicture');
         $modifyPictureGravatar = $this->getParam('modifyPictureGravatar');
         if (isset($submitPassword) && $this->logged) {
             if (!$this->view->allowPasswordChange) {
                 throw new Zend_Exception('Changing password is disallowed for this user');
             }
             $oldPass = $this->getParam('oldPassword');
             if ($userDao->getSalt() == '') {
                 $this->User->convertLegacyPasswordHash($userDao, $oldPass);
             }
             $newPass = $this->getParam('newPassword');
             $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix;
             $hashedPasswordOld = hash($userDao->getHashAlg(), $instanceSalt . $userDao->getSalt() . $oldPass);
             if (!$userDao->isAdmin() && $this->userSession->Dao->isAdmin() || $this->User->hashExists($hashedPasswordOld)) {
                 $this->User->changePassword($userDao, $newPass);
                 if (!isset($userId)) {
                     $this->userSession->Dao = $userDao;
                 }
                 echo JsonComponent::encode(array(true, $this->t('Changes saved')));
                 Zend_Registry::get('notifier')->callback('CALLBACK_CORE_PASSWORD_CHANGED', array('userDao' => $userDao, 'password' => $newPass));
             } else {
                 echo JsonComponent::encode(array(false, $this->t('The old password is incorrect')));
                 return;
             }
         }
         if (isset($modifyAccount) && $this->logged) {
             $newEmail = trim($this->getParam('email'));
             $firtname = trim($this->getParam('firstname'));
             $lastname = trim($this->getParam('lastname'));
             $company = trim($this->getParam('company'));
             $privacy = $this->getParam('privacy');
             $city = $this->getParam('city');
             $country = $this->getParam('country');
             $website = $this->getParam('website');
             $biography = $this->getParam('biography');
             if (!$accountForm->isValid($this->getRequest()->getPost())) {
                 echo JsonComponent::encode(array(false, 'Invalid form value'));
                 return;
             }
             $userDao = $this->User->load($userDao->getKey());
             if (!isset($privacy) || $privacy != MIDAS_USER_PRIVATE && $privacy != MIDAS_USER_PUBLIC) {
                 echo JsonComponent::encode(array(false, 'Error: invalid privacy flag'));
                 return;
             }
             if (!isset($lastname) || !isset($firtname) || empty($lastname) || empty($firtname)) {
                 echo JsonComponent::encode(array(false, 'Error: First and last name required'));
                 return;
             }
             if ($newEmail != $userDao->getEmail()) {
                 $existingUser = $this->User->getByEmail($newEmail);
                 if ($existingUser) {
                     echo JsonComponent::encode(array(false, 'Error: that email address belongs to another account'));
                     return;
                 }
                 $userDao->setEmail($newEmail);
             }
             $userDao->setFirstname($firtname);
             $userDao->setLastname($lastname);
             if (isset($company)) {
                 $userDao->setCompany($company);
             }
             if (isset($city)) {
                 $userDao->setCity($city);
             }
             if (isset($country)) {
                 $userDao->setCountry($country);
             }
             if (isset($website)) {
                 $userDao->setWebsite($website);
             }
             if (isset($biography)) {
                 $userDao->setBiography($biography);
             }
             $userDao->setPrivacy($privacy);
             if ($this->userSession->Dao->isAdmin() && $this->userSession->Dao->getKey() != $userDao->getKey()) {
                 $adminStatus = (bool) $this->getParam('adminStatus');
                 $userDao->setAdmin($adminStatus ? 1 : 0);
             }
             $this->User->save($userDao);
             if (!isset($userId)) {
                 $this->userSession->Dao = $userDao;
             }
             try {
                 Zend_Registry::get('notifier')->callback('CALLBACK_CORE_USER_SETTINGS_CHANGED', array('user' => $userDao, 'currentUser' => $this->userSession->Dao, 'fields' => $this->getAllParams()));
             } catch (Exception $e) {
                 echo JsonComponent::encode(array(false, $e->getMessage()));
                 return;
             }
             echo JsonComponent::encode(array(true, $this->t('Changes saved')));
         }
         if (isset($modifyPicture) && $this->logged) {
             if ($this->isTestingEnv()) {
                 // simulate file upload
                 $path = BASE_PATH . '/tests/testfiles/search.png';
                 $size = filesize($path);
                 $mime = 'image/png';
             } else {
                 $mime = $_FILES['file']['type'];
                 $upload = new Zend_File_Transfer();
                 $upload->receive();
                 $path = $upload->getFileName();
                 $size = $upload->getFileSize();
             }
             if (!empty($path) && file_exists($path) && $size > 0) {
                 if (file_exists($path) && $mime == 'image/jpeg') {
                     try {
                         $src = imagecreatefromjpeg($path);
                     } catch (Exception $exc) {
                         echo JsonComponent::encode(array(false, 'Error: Unable to read jpg file'));
                         return;
                     }
                 } elseif (file_exists($path) && $mime == 'image/png') {
                     try {
                         $src = imagecreatefrompng($path);
                     } catch (Exception $exc) {
                         echo JsonComponent::encode(array(false, 'Error: Unable to read png file'));
                         return;
                     }
                 } elseif (file_exists($path) && $mime == 'image/gif') {
                     try {
                         $src = imagecreatefromgif($path);
                     } catch (Exception $exc) {
                         echo JsonComponent::encode(array(false, 'Error: Unable to read gif file'));
                         return;
                     }
                 } else {
                     echo JsonComponent::encode(array(false, 'Error: wrong format'));
                     return;
                 }
                 $tmpPath = $this->getDataDirectory('thumbnail') . '/' . $this->Component->Random->generateInt();
                 if (!file_exists($this->getDataDirectory('thumbnail'))) {
                     throw new Zend_Exception('Thumbnail path does not exist: ' . $this->getDataDirectory('thumbnail'));
                 }
                 if (!file_exists($tmpPath)) {
                     mkdir($tmpPath);
                 }
                 $tmpPath .= '/' . $this->Component->Random->generateInt();
                 if (!file_exists($tmpPath)) {
                     mkdir($tmpPath);
                 }
                 $destination = $tmpPath . '/' . $this->Component->Random->generateInt() . '.jpg';
                 while (file_exists($destination)) {
                     $destination = $tmpPath . '/' . $this->Component->Random->generateInt() . '.jpg';
                 }
                 $pathThumbnail = $destination;
                 list($x, $y) = getimagesize($path);
                 //--- get size of img ---
                 $thumb = 32;
                 //--- max. size of thumb ---
                 if ($x > $y) {
                     $tx = $thumb;
                     //--- landscape ---
                     $ty = round($thumb / $x * $y);
                 } else {
                     $tx = round($thumb / $y * $x);
                     //--- portrait ---
                     $ty = $thumb;
                 }
                 $thb = imagecreatetruecolor($tx, $ty);
                 //--- create thumbnail ---
                 imagecopyresampled($thb, $src, 0, 0, 0, 0, $tx, $ty, $x, $y);
                 imagejpeg($thb, $pathThumbnail, 80);
                 imagedestroy($thb);
                 imagedestroy($src);
                 if (file_exists($pathThumbnail)) {
                     $userDao = $this->User->load($userDao->getKey());
                     $oldThumbnail = $userDao->getThumbnail();
                     if (!empty($oldThumbnail) && file_exists(BASE_PATH . '/' . $oldThumbnail)) {
                         unlink(BASE_PATH . '/' . $oldThumbnail);
                     }
                     $userDao->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1));
                     $this->User->save($userDao);
                     if (!isset($userId)) {
                         $this->userSession->Dao = $userDao;
                     }
                     echo JsonComponent::encode(array(true, $this->t('Changes saved'), $this->view->webroot . '/' . $userDao->getThumbnail()));
                 } else {
                     echo JsonComponent::encode(array(false, 'Error'));
                     return;
                 }
             }
             if (isset($modifyPictureGravatar) && $this->logged) {
                 $gravatarUrl = $this->User->getGravatarUrl($userDao->getEmail());
                 if ($gravatarUrl != false) {
                     $userDao = $this->User->load($userDao->getKey());
                     $oldThumbnail = $userDao->getThumbnail();
                     if (!empty($oldThumbnail) && file_exists(BASE_PATH . '/' . $oldThumbnail)) {
                         unlink(BASE_PATH . '/' . $oldThumbnail);
                     }
                     $userDao->setThumbnail($gravatarUrl);
                     $this->User->save($userDao);
                     if (!isset($userId)) {
                         $this->userSession->Dao = $userDao;
                     }
                     echo JsonComponent::encode(array(true, $this->t('Changes saved'), $userDao->getThumbnail()));
                 } else {
                     echo JsonComponent::encode(array(false, 'Error'));
                 }
             }
         }
     }
     $communities = array();
     $groups = $userDao->getGroups();
     foreach ($groups as $group) {
         $community = $group->getCommunity();
         if (!isset($communities[$community->getKey()])) {
             $community->groups = array();
             $communities[$community->getKey()] = $community;
         }
         $communities[$community->getKey()]->groups[] = $group;
     }
     $this->Component->Sortdao->field = 'name';
     $this->Component->Sortdao->order = 'asc';
     usort($communities, array($this->Component->Sortdao, 'sortByName'));
     $this->view->useGravatar = Zend_Registry::get('configGlobal')->gravatar;
     $this->view->isGravatar = $this->User->getGravatarUrl($userDao->getEmail());
     $this->view->communities = $communities;
     $this->view->user = $userDao;
     $this->view->currentUser = $this->userSession->Dao;
     $this->view->thumbnail = $userDao->getThumbnail();
     $this->view->jsonSettings = array();
     $this->view->jsonSettings['accountErrorFirstname'] = $this->t('Please set your firstname');
     $this->view->jsonSettings['accountErrorLastname'] = $this->t('Please set your lastname');
     $this->view->jsonSettings['passwordErrorShort'] = $this->t('Password too short');
     $this->view->jsonSettings['passwordErrorMatch'] = $this->t('The passwords are not the same');
     $this->view->jsonSettings = JsonComponent::encode($this->view->jsonSettings);
     $this->view->customTabs = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_GET_CONFIG_TABS', array('user' => $userDao));
     $breadcrumbs = array();
     $breadcrumbs[] = array('type' => 'user', 'object' => $userDao);
     $breadcrumbs[] = array('type' => 'custom', 'text' => 'My Account', 'icon' => $this->view->coreWebroot . '/public/images/icons/edit.png');
     $this->Component->Breadcrumb->setBreadcrumbHeader($breadcrumbs, $this->view);
 }
 /**
  * Upload a new file for this user if one is present in the form data, or if
  * not, check if one has been uploaded previously.  If there's one known
  * about, return its name.  Uses session to persist an uploaded file's
  * details between form submission attempts, in the case the overall form
  * doesn't validate.
  *
  * @todo Move somewhere else.
  *
  * @return array Array indicating boolean true for success plus and an
  * associative array with uploaded file information (or empty array if no
  * file), or boolean false for failure and an array of error messages.
  */
 private function _uploadPersistentCompanyApplicationFile()
 {
     // For storing original filename intact
     $session = new Zend_Session_Namespace('homelet_connect_referencing');
     $tempFile = "{$this->_params->connect->tempPrivatePath}companyApp_{$this->_agentSchemeNumber}_{$this->_agentId}";
     // Is a new file being sent?
     $upload = new Zend_File_Transfer('http');
     if ($upload->isUploaded()) {
         $upload->getValidator('Upload')->setMessages(array(Zend_Validate_File_Upload::INI_SIZE => 'The uploaded file size exceeds system maximum (' . ini_get('upload_max_filesize') . ')', Zend_Validate_File_Upload::FORM_SIZE => 'The uploaded file size exceeds the HTML form maximum', Zend_Validate_File_Upload::PARTIAL => 'The uploaded file was only partially uploaded', Zend_Validate_File_Upload::NO_FILE => 'No file was uploaded', Zend_Validate_File_Upload::NO_TMP_DIR => 'Missing a temporary folder', Zend_Validate_File_Upload::CANT_WRITE => 'Failed to write file to disk', Zend_Validate_File_Upload::EXTENSION => 'File upload stopped by extension', Zend_Validate_File_Upload::UNKNOWN => 'Unknown upload error'));
         $upload->addValidator('Count', true, 1);
         $upload->addValidator('Size', false, $this->_params->connect->companyapps->fileUpload->maxSize->file);
         $upload->getValidator('Size')->setMessages(array(Zend_Validate_File_Size::TOO_SMALL => 'File \'%value%\' below minimum size', Zend_Validate_File_Size::TOO_BIG => 'File \'%value%\' above maximum size'));
         $upload->addValidator('MimeType', false, $this->_params->connect->companyapps->fileUpload->mimeTypes);
         $upload->getValidator('MimeType')->setMessages(array(Zend_Validate_File_MimeType::FALSE_TYPE => 'File \'%value%\' of incorrect MIME type'));
         $upload->addValidator('Extension', true, $this->_params->connect->companyapps->fileUpload->extensions);
         $upload->getValidator('Extension')->setMessages(array(Zend_Validate_File_Extension::FALSE_EXTENSION => 'File \'%value%\' of incorrect extension'));
         if ($upload->isValid()) {
             // First delete any old file that may have been previously
             //   uploaded
             $this->_deleteCompanyApplicationFile();
             // Upload new one
             $session->companyAppFile->originalFilename = $upload->getFileName(null, false);
             $upload->addFilter('Rename', $tempFile);
             if ($upload->receive()) {
                 $session->companyAppFile->uploadedFile = $tempFile;
             } else {
                 unset($session->companyAppFile);
             }
         } else {
             // Send back validation messages
             return array(false, $upload->getMessages());
         }
     }
     // Is there one stored, perhaps already?  If yes, return original
     //   filename
     $returnVal = array();
     if (isset($session->companyAppFile->originalFilename)) {
         $returnVal = array('originalName' => $session->companyAppFile->originalFilename, 'pathToFile' => $tempFile);
     }
     return array(true, $returnVal);
 }
Пример #5
0
    function regAction()
    {
        if ($this->_request->isPost('reg-form')) {
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            Zend_Loader::loadClass('Zend_File_Transfer');
            Zend_Loader::loadClass('Zend_Date');
            Zend_Loader::loadClass('Zend_Mail');
            Zend_Loader::loadClass('Zend_Validate_EmailAddress');
            Zend_Loader::loadClass('Zend_Validate_StringLength');
            Zend_Loader::loadClass('Zend_Validate_Alnum');
            $filter = new Zend_Filter_StripTags();
            $email = trim($filter->filter($this->_request->getPost('reg-email')));
            $username = trim($filter->filter($this->_request->getPost('reg-name')));
            $password = trim($filter->filter($this->_request->getPost('reg-pswd')));
            $password_confirm = trim($filter->filter($this->_request->getPost('reg-pswd-verification')));
            $real_name = trim($filter->filter($this->_request->getPost('reg-real-name')));
            $file_name = '';
            $warnings = new Zend_Session_Namespace();
            $warnings->username = $username;
            $warnings->email = $email;
            $warnings->real_name = $real_name;
            $warnings->error = '';
            $error_msg = '';
            $mail_val = new Zend_Validate_EmailAddress();
            $name_lenght_val = new Zend_Validate_StringLength(6, 12);
            $name_an_val = new Zend_Validate_Alnum();
            $pass_lenght_val = new Zend_Validate_StringLength(6, 16);
            $real_name_lenght_val = new Zend_Validate_StringLength(0, 60);
            if ($email == '') {
                $error_msg .= '<p>Enter your email.</p>';
            } else {
                if (!$mail_val->isValid($email)) {
                    foreach ($mail_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'email = "' . $email . '"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['email'] != '') {
                        $error_msg .= '<p>User with such an email is already registered.</p>';
                    }
                }
            }
            if ($username == '') {
                $error_msg .= '<p>Enter your username.</p>';
            } else {
                if (!$name_lenght_val->isValid($username) || !$name_an_val->isValid($username)) {
                    foreach ($name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                    foreach ($name_an_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $data = new Users();
                    $query = 'login = "******"';
                    $data_row = $data->fetchRow($query);
                    if ($data_row['login'] != '') {
                        $error_msg .= '<p>User with such an username is already registered.</p>';
                    }
                }
            }
            if ($password == '' || !$pass_lenght_val->isValid($password)) {
                $error_msg .= '<p>Enter password (must consist 6 to 16 characters).</p>';
            } else {
                if ($password_confirm == '') {
                    $error_msg .= '<p>Empty verification password.</p>';
                } else {
                    if ($password != $password_confirm) {
                        $error_msg .= '<p>The entered passwords do not match.</p>';
                    } else {
                        $salt = substr(sha1(microtime(true) . rand(1, 99999)), 0, 3);
                        $password = sha1($password . $salt);
                    }
                }
            }
            if ($real_name != '') {
                if (!$real_name_lenght_val->isValid($real_name)) {
                    foreach ($real_name_lenght_val->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                }
            }
            $upload = new Zend_File_Transfer();
            if ($upload->isUploaded()) {
                $upload->setDestination('public/upload/avatars/');
                $upload->addValidator('IsImage', false);
                $upload->addValidator('Size', false, 1024 * 1024);
                if (!$upload->isValid()) {
                    foreach ($upload->getMessages() as $message) {
                        $error_msg .= '<p>' . $message . '</p>';
                    }
                } else {
                    $upload_info = $upload->getFileName();
                    $file_ext = mb_substr($upload_info, strrpos($upload_info, '.') + 1);
                    $file_name = $username . '.' . $file_ext;
                    $upload->addFilter('Rename', array('target' => 'public/upload/avatars/' . $file_name, 'overwrite' => true));
                }
            }
            if ($error_msg != '') {
                $warnings->error = $error_msg;
                $warnings->status = '';
                $this->_redirect('/register/');
                return;
            } else {
                $date = new Zend_Date();
                $current_date = $date->toString('YYYY-MM-dd');
                $upload->receive();
                $data = array('login' => $username, 'email' => $email, 'password' => $password, 'salt' => $salt, 'real_name' => $real_name, 'reg_date' => $current_date, 'avatar' => $file_name, 'last_login' => '-');
                $user = new Users();
                $user->insert($data);
                $warnings->error = '<p>Registration complete.</p><p>Now check your E-Mail to activate your profile.</p>';
                $warnings->username = '';
                $warnings->email = '';
                $warnings->real_name = '';
                $warnings->status = ' reg_ok';
                $mail = new Zend_Mail();
                $hash = sha1($email . $salt);
                $url = $this->getRequest()->getServer('HTTP_HOST');
                $mail->setBodyHtml('<p>To activate your profile follow the link below:</p>
									<p>Link: <a href="http://' . $url . '/register/activate/' . $hash . '">http://' . $url . '/register/activate/' . $hash . '</a></p>
									<p>Thanks for your registration.</p>
									');
                $mail->setFrom('*****@*****.**', 'Administrator');
                $mail->addTo($email, $username);
                $mail->setSubject('Test activation link');
                $mail->send();
                $this->_redirect('/register/');
                return;
            }
        }
    }