Пример #1
0
 /**
  * save the registration
  * @param string $lemail
  * @param string $lpass
  * @param string $lpass2
  * @param string $firstName
  * @param string $lastName
  */
 public function createAction($lemail, $lpass, $lpass2, $firstName, $lastName = NULL)
 {
     $account = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName($lemail, $this->providerName);
     if ($account instanceof \TYPO3\Flow\Security\Account) {
         $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error($this->translator->translateById('login.login.usernameExist', array(), NULL, NULL, 'Main', 'Incvisio.LostFound')));
         $this->redirect('index', 'Standard');
     } else {
         $defaultRole = array('Incvisio.LostFound:User');
         if ($lemail == '' || strlen($lemail) < 3) {
             $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Username too short or empty'));
             $this->redirect('index', 'Standard');
         } else {
             if ($lpass == '' || $lpass != $lpass2) {
                 $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Password too short or does not match'));
                 $this->redirect('index', 'Standard');
             } else {
                 if ($lastName == NULL) {
                     $lastName = " ";
                 }
                 // create a account with password an add it to the accountRepository
                 $user = $this->userFactory->create($lemail, $lpass, $firstName, $lastName, $defaultRole);
                 $user->setLikes(0);
                 $user->setDislike(0);
                 $this->userRepository->add($user);
                 $accounts = $user->getAccounts();
                 foreach ($accounts as $account) {
                     $account->setExpirationDate(new \TYPO3\Flow\Utility\Now());
                     $this->accountRepository->add($account);
                 }
                 $this->persistenceManager->persistAll();
                 $date = $this->time->getTimestamp();
                 $random = rand();
                 $json = json_encode(array('username' => $lemail, 'date' => $date, 'random' => $random));
                 $cryptKey = md5($this->providerName);
                 $cryptJson = urlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $cryptKey, $json, MCRYPT_MODE_CBC, md5($cryptKey))));
                 $this->sendActivationEmail($lemail, $cryptJson, $firstName);
                 // add a message and redirect to the login form
                 $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error($this->translator->translateById('main.messages.accountcreated', array(), NULL, NULL, 'Main', 'Incvisio.LostFound')));
                 $this->redirect('index', 'Standard');
             }
         }
         // redirect to the login form
         $this->redirect('index', 'Standard');
     }
 }
Пример #2
0
 /**
  *
  * @return array
  */
 public function changeAvatarAction()
 {
     $user = $this->getCurrentUser();
     // ########### Configuration ##############
     $thumb_square_size = 200;
     // Thumbnails will be cropped to 200x200 pixels
     $max_image_size = 500;
     // Maximum image size (height and width)
     $thumb_prefix = "avatar_";
     // Normal thumb Prefix
     $destination_folder = __DIR__ . "/../../../../../../Packages/Application/Incvisio.LostFound/Resources/Public/Images/uploads/user_avatar/";
     // upload directory ends with / (slash)
     $jpeg_quality = 90;
     // jpeg quality
     // #########################################
     // continue only if $_POST is set and it is a Ajax request
     if (isset($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         // check $_FILES['ImageFile'] not empty
         if (!isset($_FILES['image_file']) || !is_uploaded_file($_FILES['image_file']['tmp_name'])) {
             die('Image file is Missing!');
             // output error when above checks fail.
         }
         // get uploaded file info before we proceed
         $image_name = $_FILES['image_file']['name'];
         // file name
         $image_size = $_FILES['image_file']['size'];
         // file size
         $image_temp = $_FILES['image_file']['tmp_name'];
         // file temp
         $image_size_info = getimagesize($image_temp);
         // gets image size info from valid image file
         if ($image_size_info) {
             $image_width = $image_size_info[0];
             // image width
             $image_height = $image_size_info[1];
             // image height
             $image_type = $image_size_info['mime'];
             // image type
         } else {
             die("Make sure image file is valid!");
         }
         // switch statement below checks allowed image type
         // as well as creates new image from given file
         switch ($image_type) {
             case 'image/png':
                 $image_res = imagecreatefrompng($image_temp);
                 break;
             case 'image/gif':
                 $image_res = imagecreatefromgif($image_temp);
                 break;
             case 'image/jpeg':
             case 'image/pjpeg':
                 $image_res = imagecreatefromjpeg($image_temp);
                 break;
             default:
                 $image_res = false;
         }
         if ($image_res) {
             // Get file extension and name to construct new file name
             $image_info = pathinfo($image_name);
             $image_extension = strtolower($image_info["extension"]);
             // image extension
             $image_name_only = strtolower($image_info["filename"]);
             // file name only, no extension
             // create a random name for new image (Eg: fileName_293749.jpg) ;
             $new_file_name = $image_name_only . '_' . rand(0, 9999999999) . '.' . $image_extension;
             // folder path to save resized images and thumbnails
             $thumb_save_folder = $destination_folder . $thumb_prefix . $new_file_name;
             $image_save_folder = $destination_folder . $new_file_name;
             // call normal_resize_image() function to proportionally resize image
             if ($this->normal_resize_image($image_res, $image_save_folder, $image_type, $max_image_size, $image_width, $image_height, $jpeg_quality)) {
                 // call crop_image_square() function to create square thumbnails
                 if (!$this->crop_image_square($image_res, $thumb_save_folder, $image_type, $thumb_square_size, $image_width, $image_height, $jpeg_quality)) {
                     die('Error Creating thumbnail');
                 }
                 $saveImageDest = 'http://' . $_SERVER['HTTP_HOST'] . '/_Resources/Static/Packages/Incvisio.LostFound/Images/uploads/user_avatar/';
                 $user->setSocialPhoto($saveImageDest . $thumb_prefix . $new_file_name);
                 $this->userRepository->update($user);
                 $this->persistenceManager->persistAll();
             }
             imagedestroy($image_res);
             // freeup memory
             return "Аватар змінено";
         }
     }
 }