예제 #1
0
 public function verifyAction()
 {
     if (!$this->hasParam('code')) {
         throw new \FA\Exception('No verification code was provided! Your e-mail should have included a verification code.');
     }
     $code = $this->getParam('code');
     $rr = RegistrationRequest::validate($code);
     if (!$rr instanceof RegistrationRequest) {
         throw new \FA\Exception('Your verification code could not be validated. The code may have expired, or already been used.');
     }
     $form = new \FA\Form($this->current_module_config->forms->register_complete);
     $form->setDefaults(array('username' => $rr->username, 'email' => $rr->email));
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         $bday_timestamp = strtotime($data['birthday'] . ' 00:00:00');
         $bday_threshold = strtotime('-13 years');
         // Rebuild the birthday into this format (in case it wasn't provided this way by the browser).
         $data['birthday'] = date('Y-m-d', $bday_timestamp);
         if ($bday_timestamp == 0) {
             $form->addError('birthday', 'We could not process your birthday as specified. Please try again.');
         }
         if ($bday_timestamp >= $bday_threshold) {
             $form->addError('birthday', 'Our site cannot accept users under 13 years of age due to United States federal law, 15 USC 6501-6506.');
         }
         if (!$form->hasErrors()) {
             $user = new User();
             $user->fromArray(array('username' => $rr->username, 'password' => $data['password'], 'birthday' => $data['birthday'], 'fullname' => $data['fullname'], 'email' => $rr->email, 'regemail' => $rr->email, 'regbdate' => str_replace('-', '', $data['birthday'])));
             $user->save();
             $rr->is_used = true;
             $rr->save();
             // Create "skeleton" art folder.
             $app_cfg = $this->config->application;
             $user_art_dir = $app_cfg->art_path . '/' . $user->lower;
             @mkdir($user_art_dir);
             foreach ($app_cfg->art_folders as $art_folder) {
                 $art_folder_path = $user_art_dir . '/' . $art_folder;
                 @mkdir($art_folder_path);
             }
             // Log in the user.
             $this->auth->setUser($user);
             $this->alert('<b>Welcome to FurAffinity!</b><br>Your account has been created, and you are now logged in to the web site.', 'green');
             return $this->redirectHome();
             // return $this->view->pick('register/welcome');
         }
     }
     $this->view->title = 'Complete New Account Creation';
     return $this->renderForm($form);
 }
예제 #2
0
 public function profileAction()
 {
     $form_config = $this->current_module_config->forms->settings_profile->toArray();
     // Populate the submission selection dropdowns.
     $submissions = $this->em->createQuery('SELECT s.id, s.title, s.is_scrap FROM Entity\\Upload s WHERE s.user_id = :user_id')->setParameter('user_id', $this->user->id)->getArrayResult();
     $submission_select = array('featured' => array('' => 'Disabled'), 'profile_pic' => array('' => 'Disabled'));
     foreach ($submissions as $submission) {
         $group = $submission['is_scrap'] ? 'profile_pic' : 'featured';
         $submission_select[$group][$submission['id']] = $submission['title'];
     }
     $form_config['groups']['featured_items']['elements']['featured'][1]['options'] = $submission_select['featured'];
     $form_config['groups']['featured_items']['elements']['profile_pic'][1]['options'] = $submission_select['profile_pic'];
     // Initialize the form.
     $form = new \FA\Form($form_config);
     // Set form defaults based on current user database records.
     $contact = $this->user->contact;
     if (!$contact instanceof UserContact) {
         $contact = new UserContact();
         $contact->user = $this->user;
         $contact->save();
     }
     $form->setDefaults(array_merge($this->user->toArray(FALSE, TRUE), $contact->toArray(FALSE, TRUE)));
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         // Load data directly into DB models using the fromArray helpers.
         $this->user->fromArray($data['user']);
         $this->em->persist($this->user);
         $contact->fromArray($data['contact']);
         $this->em->persist($contact);
         // Push any model changes to the DB.
         $this->em->flush();
         $this->alert('<b>Profile Updated!</b><br>Your changes have been saved.', 'green');
         return $this->redirectHere();
     }
     $this->view->form = $form;
 }
예제 #3
0
 public function editAction()
 {
     $types = $this->config->fa->upload_types->toArray();
     $id = (int) $this->getParam('id');
     if ($id !== 0) {
         // Edit existing record.
         // TODO: Reimplement administrator access.
         $record = Upload::getRepository()->findOneBy(array('id' => $id, 'user_id' => $this->user->id));
         if (!$record instanceof Upload) {
             throw new \FA\Exception('Submission ID not found!');
         }
         $edit_mode = true;
         $type = $record->submission_type;
     } else {
         // Create new submission.
         $type = $this->getParam('type');
         // Show type selector if no type is specified.
         if (empty($type) || !isset($types[$type])) {
             $this->view->types = $types;
             return $this->view->pick('uploads/select');
         }
         $edit_mode = false;
         $record = NULL;
     }
     $type_info = $types[$type];
     $form_config = $this->current_module_config->forms->uploads_edit->toArray();
     // Create mode changes
     if (!$edit_mode) {
         $form_config['groups']['files']['elements']['submission'][1]['required'] = true;
         unset($form_config['groups']['files']['elements']['submission'][1]['description']);
         unset($form_config['groups']['files']['elements']['rebuild_thumbnail']);
     }
     // Changes to the form based on submission type.
     if (isset($type_info['category'])) {
         $form_config['groups']['metadata']['elements']['category'][1]['default'] = $type_info['category'];
     }
     if ($type !== Upload::TYPE_IMAGE) {
         unset($form_config['groups']['files']['elements']['rebuild_thumbnail']);
     }
     $form_config['groups']['files']['elements']['submission'][1]['allowedTypes'] = $type_info['types'];
     // Create the form class.
     $form = new \FA\Form($form_config);
     // Populate the form (if available).
     if ($record instanceof Upload) {
         $form->setDefaults($record->toArray(TRUE, TRUE));
     }
     // Handle form submission.
     if ($_POST && $this->request->hasFiles() && $form->isValid(array_merge($_POST, $_FILES))) {
         $data = $form->getValues();
         if (!$record instanceof Upload) {
             $record = new Upload();
             $record->upload_type = $type;
             $record->user = $this->user;
             $record->is_hidden = true;
             // Hide until properly populated.
             $record->save();
             // Immediately save to generate IDs used in next steps.
         }
         $record->fromArray($data);
         // Begin file handling.
         \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MEMORY, 32);
         \IMagick::setResourceLimit(\Imagick::RESOURCETYPE_MAP, 32);
         $files = $form->getFiles($this->request);
         $imagine = new Imagine();
         $submission_file = $files['submission'][0];
         $thumbnail_file = null;
         $thumbnail_paths = array();
         $preview_file = null;
         $preview_paths = array();
         if ($submission_file) {
             $submission_paths = $record->generatePaths($submission_file->getName());
             // Create the proper artwork directory if it doesn't exist.
             $submission_dir = dirname($submission_paths['full']['path']);
             @mkdir($submission_dir);
             if ($type == Upload::TYPE_IMAGE) {
                 // Handle image uploads.
                 $submission_image = $imagine->open($submission_file->getTempName());
                 $is_animated = count($submission_image->layers()) > 1;
                 // So, it seems Imagine really loves to screw up GIFs, so lets avoid that
                 if ($is_animated) {
                     $dest_path = $submission_paths['full']['path'];
                     // Copying this instead of moving due to the file being reused by preview/thumbnail
                     copy($submission_file->getTempName(), $dest_path);
                 } else {
                     $submission_image->save($submission_paths['full']['path'], array('animated' => $is_animated));
                 }
                 // Make this file the thumbnail if no other is specified.
                 if (empty($files['thumbnail']) && (!$edit_mode || $data['rebuild_thumbnail'])) {
                     $thumbnail_file = $submission_file;
                     $thumbnail_paths = $submission_paths;
                 }
                 // Set up the preview parameters
                 $preview_file = $submission_file;
                 $preview_paths = $submission_paths;
             } else {
                 // Handle non-images. Way simpler, right?
                 $dest_path = $submission_paths['full']['path'];
                 $submission_file->moveTo($dest_path);
                 // Prevent the file from being deleted below.
                 $submission_file = null;
             }
             $record->setFull($submission_paths['full']['base']);
         }
         // Use the thumbnail field if supplied.
         if (!empty($files['thumbnail'])) {
             $thumbnail_file = $files['thumbnail'][0];
             $thumbnail_paths = $record->generatePaths($thumbnail_file->getName());
         }
         // If we haven't set a preview image/path, then use the thumbnail if possible
         if (is_null($preview_file)) {
             $preview_file = $thumbnail_file;
             $preview_paths = $thumbnail_paths;
         }
         // Process either the uploaded thumbnail, or resize the original file to be our preview.
         if ($preview_file) {
             // Generate "small" size thumbnail.
             $preview_size = new Box(self::MAX_PREVIEW_SIZE, self::MAX_PREVIEW_SIZE);
             self::_saveAsJPG($imagine, $preview_file, $preview_paths['small']['path'], 90, $preview_size);
             $record->setSmall(self::_changeExtension($preview_paths['small']['base'], 'jpg'));
         }
         // Process either the uploaded thumbnail, or thumbnailize the original file.
         if ($thumbnail_file) {
             // Generate "thumb" size thumbnail.
             $thumbnail_size = new Box(self::MAX_THUMB_SIZE, self::MAX_THUMB_SIZE);
             self::_saveAsJPG($imagine, $thumbnail_file, $thumbnail_paths['thumbnail']['path'], 90, $thumbnail_size);
             $record->setThumbnail(self::_changeExtension($thumbnail_paths['thumbnail']['base'], 'jpg'));
         }
         // Delete the temp files (if not already moved).
         if ($submission_file) {
             @unlink($submission_file->getTempName());
         }
         if ($thumbnail_file) {
             @unlink($thumbnail_file->getTempName());
         }
         // Unhide the record that was hidden earlier.
         if (!$edit_mode) {
             $record->is_hidden = false;
         }
         $record->save();
         $view_url = $this->url->get('view/' . $record->id);
         $view_link = 'You can <a href="' . $view_url . '" target="_blank_">view your submission\'s public page here</a>.';
         if ($edit_mode) {
             $this->alert('<b>Submission Updated!</b><br>' . $view_link, 'green');
         } else {
             $this->alert('<b>New Submission Uploaded!</b><br>' . $view_link, 'green');
         }
         return $this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'type' => NULL));
     }
     // Render the main form.
     $this->view->type_info = $type_info;
     $this->view->form = $form;
 }