コード例 #1
0
ファイル: SettingsController.php プロジェクト: hoalangoc/ftf
 public function generalAction()
 {
     // Config vars
     $settings = Engine_Api::_()->getApi('settings', 'core');
     $userSettings = Engine_Api::_()->getDbtable('settings', 'user');
     $user = Engine_Api::_()->core()->getSubject();
     $this->view->form = $form = new User_Form_Settings_General(array('item' => $user));
     $form->removeElement('accountType');
     // Removed disabled features
     if ($form->getElement('username') && (!Engine_Api::_()->authorization()->isAllowed('user', $user, 'username') || Engine_Api::_()->getApi('settings', 'core')->getSetting('user.signup.username', 1) <= 0)) {
         $form->removeElement('username');
     }
     // Facebook
     if ('none' != $settings->getSetting('core.facebook.enable', 'none')) {
         $facebookTable = Engine_Api::_()->getDbtable('facebook', 'user');
         $facebook = $facebookTable->getApi();
         if ($facebook && $facebook->getUser()) {
             $form->removeElement('facebook');
             $form->getElement('facebook_id')->setAttrib('checked', true);
         } else {
             $form->removeElement('facebook_id');
         }
     } else {
         // these should already be removed inside the form, but lets do it again.
         @$form->removeElement('facebook');
         @$form->removeElement('facebook_id');
     }
     // Twitter
     if ('none' != $settings->getSetting('core.twitter.enable', 'none')) {
         $twitterTable = Engine_Api::_()->getDbtable('twitter', 'user');
         $twitter = $twitterTable->getApi();
         if ($twitter && $twitterTable->isConnected()) {
             $form->removeElement('twitter');
             $form->getElement('twitter_id')->setAttrib('checked', true);
         } else {
             $form->removeElement('twitter_id');
         }
     } else {
         // these should already be removed inside the form, but lets do it again.
         @$form->removeElement('twitter');
         @$form->removeElement('twitter_id');
     }
     // Check if post and populate
     if (!$this->getRequest()->isPost()) {
         $arr_user = $user->toArray();
         $arr_user['languages'] = json_decode($arr_user['languages']);
         $form->populate($arr_user);
         $form->populate(array('janrainnoshare' => $userSettings->getSetting($user, 'janrain.no-share', 0)));
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid method');
         return;
     }
     // Check if valid
     if (!$form->isValid($this->getRequest()->getPost())) {
         $arr_user = $user->toArray();
         $arr_user['languages'] = json_decode($arr_user['languages']);
         $form->populate($arr_user);
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid data');
         return;
     }
     // -- Process --
     $values = $form->getValues();
     $values['languages'] = json_encode($values['languages']);
     // Check email against banned list if necessary
     if (($emailEl = $form->getElement('email')) && isset($values['email']) && $values['email'] != $user->email) {
         $bannedEmailsTable = Engine_Api::_()->getDbtable('BannedEmails', 'core');
         if ($bannedEmailsTable->isEmailBanned($values['email'])) {
             return $emailEl->addError('This email address is not available, please use another one.');
         }
     }
     // Check username against banned list if necessary
     if (($usernameEl = $form->getElement('username')) && isset($values['username']) && $values['username'] != $user->username) {
         $bannedUsernamesTable = Engine_Api::_()->getDbtable('BannedUsernames', 'core');
         if ($bannedUsernamesTable->isUsernameBanned($values['username'])) {
             return $usernameEl->addError('This profile address is not available, please use another one.');
         }
     }
     // Set values for user object
     $user->setFromArray($values);
     // If username is changed
     $aliasValues = Engine_Api::_()->fields()->getFieldsValuesByAlias($user);
     $user->setDisplayName($aliasValues);
     $user->save();
     if (!empty($values['languages'])) {
         foreach (json_decode($values['languages']) as $langId) {
             // save language map
             $mappingTable = Engine_Api::_()->getDbtable('languagemappings', 'user');
             $mappingTable->save($langId, $user);
         }
     }
     // Update facebook settings
     if (isset($facebook) && $form->getElement('facebook_id')) {
         if ($facebook->getUser()) {
             if (empty($values['facebook_id'])) {
                 // Remove integration
                 $facebookTable->delete(array('user_id = ?' => $user->getIdentity()));
                 $facebook->clearAllPersistentData();
             }
         }
     }
     // Update twitter settings
     if (isset($twitter) && $form->getElement('twitter_id')) {
         if ($twitterTable->isConnected()) {
             if (empty($values['twitter_id'])) {
                 // Remove integration
                 $twitterTable->delete(array('user_id = ?' => $user->getIdentity()));
                 unset($_SESSION['twitter_token2']);
                 unset($_SESSION['twitter_secret2']);
                 unset($_SESSION['twitter_token']);
                 unset($_SESSION['twitter_secret']);
             }
         }
     }
     // Update janrain settings
     if (!empty($values['janrainnoshare'])) {
         $userSettings->setSetting($user, 'janrain.no-share', true);
     } else {
         $userSettings->setSetting($user, 'janrain.no-share', null);
     }
     // Send success message
     $this->view->status = true;
     $this->view->message = Zend_Registry::get('Zend_Translate')->_('Settings saved.');
     $form->addNotice(Zend_Registry::get('Zend_Translate')->_('Settings were successfully saved.'));
 }
コード例 #2
0
ファイル: SettingsController.php プロジェクト: robeendey/ce
 public function generalAction()
 {
     // Config vars
     $user = $this->_helper->api()->core()->getSubject();
     $this->view->form = $form = new User_Form_Settings_General(array('item' => $user));
     // Set up profile type options
     /*
         $aliasedFields = $user->fields()->getFieldsObjectsByAlias();
         if( isset($aliasedFields['profile_type']) )
         {
           $options = $aliasedFields['profile_type']->getElementParams($user);
           unset($options['options']['order']);
           $form->accountType->setOptions($options['options']);
         }
         else
         { */
     $form->removeElement('accountType');
     /* } */
     // Removed disabled features
     if (!Engine_Api::_()->authorization()->isAllowed('user', $user, 'username')) {
         $form->removeElement('username');
     }
     // Facebook
     if ('none' != Engine_Api::_()->getApi('settings', 'core')->getSetting('core.facebook.enable', 'none')) {
         $facebook = User_Model_DbTable_Facebook::getFBInstance();
         if ($facebook->getSession()) {
             $fb_uid = Engine_Api::_()->getDbtable('facebook', 'user')->fetchRow(array('user_id = ?' => Engine_Api::_()->user()->getViewer()->getIdentity()));
             if ($fb_uid && $fb_uid->facebook_uid) {
                 $fb_uid = $fb_uid->facebook_uid;
             } else {
                 $fb_uid = null;
             }
             try {
                 $facebook->api('/me');
                 if ($fb_uid && $facebook->getUser() != $fb_uid) {
                     $form->removeElement('facebook_id');
                     $form->getElement('facebook')->addError('You appear to be logged into a different Facebook account than what was registered with this account.  Please log out of Facebook using the button below to log into your correct Facebook account.');
                     $form->getElement('facebook')->setContent($this->view->translate('<button onclick="window.location.href=this.value;return false;" value="%s">Logout of Facebook</button>', $facebook->getLogoutUrl()));
                 } else {
                     $form->removeElement('facebook');
                     $form->getElement('facebook_id')->setAttrib('checked', (bool) $fb_uid);
                 }
             } catch (Exception $e) {
                 $form->removeElement('facebook');
                 $form->removeElement('facebook_id');
             }
         } else {
             @$form->removeElement('facebook_id');
         }
     } else {
         // these should already be removed inside the form, but lets do it again.
         @$form->removeElement('facebook');
         @$form->removeElement('facebook_id');
     }
     // Check if post and populate
     if (!$this->getRequest()->isPost()) {
         $form->populate($user->toArray());
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid method');
         return;
     }
     // Check if valid
     if (!$form->isValid($this->getRequest()->getPost())) {
         $this->view->status = false;
         $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid data');
         return;
     }
     // -- Process --
     // Set values for user object
     $user->setFromArray($form->getValues());
     $user->save();
     // Update account type
     /*
         $accountType = $form->getValue('accountType');
         if( isset($aliasedFields['profile_type']) )
         {
      $valueRow = $aliasedFields['profile_type']->getValue($user);
      if( null === $valueRow ) {
        $valueRow = Engine_Api::_()->fields()->getTable('user', 'values')->createRow();
        $valueRow->field_id = $aliasedFields['profile_type']->field_id;
        $valueRow->item_id = $user->getIdentity();
      }
      $valueRow->value = $accountType;
      $valueRow->save();
         }
     *
     */
     // Update facebook settings
     if (isset($facebook) && $form->getElement('facebook_id')) {
         if ($facebook->getSession()) {
             try {
                 $facebook->api('/me');
                 $uid = Engine_Api::_()->user()->getViewer()->getIdentity();
                 $table = Engine_Api::_()->getDbtable('facebook', 'user');
                 $row = $table->find($uid)->current();
                 if (!$row) {
                     $row = $table->createRow();
                     $row->user_id = $uid;
                 }
                 $row->facebook_uid = $this->getRequest()->getPost('facebook_id') ? $facebook->getUser() : 0;
                 $row->save();
                 $form->removeElement('facebook');
             } catch (Exception $e) {
             }
         }
     }
     // Send success message
     $this->view->status = true;
     $this->view->message = Zend_Registry::get('Zend_Translate')->_('Settings saved.');
     $form->addNotice(Zend_Registry::get('Zend_Translate')->_('Settings were successfully saved.'));
 }