2012-02-20 29 views
0

- >我正在嘗試新的用戶註冊自定義。joomla 1.7用戶註冊自定義問題

- >爲此,我通過來自控制器的調用函數創建窗體和隱藏變量。

- >在控制器保存功能我寫這個代碼,但一些內部功能,它不工作在1.7,所以在這裏創建問題。

function register_save() 
{ 

    global $mainframe; 
    $db =& JFactory::getDBO(); 
    // Check for request forgeries 
    JRequest::checkToken() or jexit('Invalid Token'); 

    //clean request 
    $post = JRequest::get('post'); 
    $post['username'] = JRequest::getVar('username', '', 'post', 'username'); 
    $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); 
    $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); 

    // get the redirect 
    $return = JURI::base(); 

    // do a password safety check 
    if(strlen($post['password']) || strlen($post['password2'])) { // so that "0" can be used as password e.g. 
     if($post['password'] != $post['password2']) { 
      $msg = JText::_('PASSWORD NOT MATCH'); 
      // something is wrong. we are redirecting back to edit form. 
      // TODO: HTTP_REFERER should be replaced with a base64 encoded form field in a later release 
      $return = str_replace(array('"', '<', '>', "'"), '', @$_SERVER['HTTP_REFERER']); 
      if (empty($return) || !JURI::isInternal($return)) { 
       $return = JURI::base(); 
      } 
      $this->setRedirect($return, $msg, 'error'); 
      return false; 
     } 
    } 

    // Get required system objects 
    $user  = clone(JFactory::getUser()); 
    $pathway = JFactory::getApplication(); 
    //$pathway =& $mainframe->getPathway(); 
    $config  =& JFactory::getConfig(); 
    //print_r($config)."<br>"; 
    $authorize =& JFactory::getACL(); 
    //print_r($authorize)."<br>";    /// some mistake here 
    $newUsertype = 'Registered'; 

    // Bind the post array to the user object 
    if (!$user->bind(JRequest::get('post'), 'usertype')) { 
     JError::raiseError(500, $user->getError()); 
    } 
    // Set some initial user values 
    $user->set('id', 0); 
    $user->set('usertype', $newUsertype); 

    $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO')); 

    $date =& JFactory::getDate(); 
    $user->set('registerDate', $date->toMySQL()); 

    // If user activation is turned on, we need to set the activation information 

     jimport('joomla.user.helper'); 
     $user->set('activation', JUtility::getHash(JUserHelper::genRandomPassword())); 
     $user->set('block', '1'); 

    // If there was an error with registration, set the message and display form 

    if (!$user->save()) 
    { 
     JError::raiseWarning('', JText::_($user->getError())); 
     $this->register(); 
     return false; 
    } 

     $obj1 = new stdClass(); 
     $obj1->userid = $user->id; 
     $obj1->points = 0; 
     $obj1->posted_on = $date->toMySQL(); 
     $obj1->avatar = '';        
     $obj1->thumb = ''; 
     $obj1->params = 'notifyEmailSystem=1 
          privacyProfileView=0 
          privacyPhotoView=0 
          privacyFriendsView=0 
          privacyVideoView=1 
          notifyEmailMessage=1 
          notifyEmailApps=1 
          notifyWallComment=0'; 
     $db->insertObject('#__community_users', $obj1, 'userid'); 

     $extra_field = array(1=>2,2=>3,3=>4,4=>6,5=>7,6=>8,7=>9,8=>10,9=>11,10=>12,11=>14,12=>15,13=>16); 
     $i = 1; 
     $obj2 = new stdClass(); 
     while($extra_field[$i] != "") 
     { 
      $obj2->id = ''; 
      $obj2->user_id = $user->id; 
      $obj2->field_id = $extra_field[$i]; 
      $obj2->value = ''; 
      $db->insertObject('#__community_fields_values', $obj2, 'id'); 
      $i++; 
     }     
    ////////// end of joomsocial customisation/////////////////////////// 
    // Send registration confirmation mail 
    $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); 
    $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email 
    UserControllerRegister::_sendMail($user, $password); 

    // Everything went fine, set relevant message depending upon user activation state and display message 

     $message = JText::_('Your account has been created and an activation link has been sent to the e-mail address you entered. Note that you must activate the account by clicking on the activation link when you get the e-mail before you can login.'); 

    $this->setRedirect('index.php', $message); 
} 
  • 在表中沒有插入記錄。 請幫助我。
+0

這是很多的代碼,不知道它的全部都是相關的。 註釋所有不相關的代碼,手動輸入插入參數的值並嘗試調用此方法並查看插入是否有效。如果是的話 - 開始調試,看看你收到的價值 – alfasin 2012-02-20 09:25:29

+0

感謝重播, 我想這裏在** $ authorize =&JFactory :: getACL(); **這裏我打印這個,但其代碼給我輸出像** JAccess對象()** - 如果我運行它在1.5然後它給我這樣的大陣列像 JAuthorization對象([acl] =>陣列([0] =>陣列([0 ] => com_user [1] =>編輯.....))) 我想在這裏得到這個問題1.7。 – Mayur 2012-02-20 09:54:52

回答

0

我認爲你是對的:
的Joomla 1.5 ACL(訪問控制列表)採用分層結構:每個用戶組從它下面的組繼承權限。
在Joomla 1.7 ACL不一定是分層的。您可以使用您希望的任何權限設置組。

Joomla 1.5和1.7中ACL的區別不僅在於行爲 - 而且在實現中!這意味着認證/註冊機制將以不同的方式實施: http://www.youtube.com/watch?v=ZArgffnPUo4