2013-03-09 86 views
1

我已經繼承了一個joomla 1.5站點,它有一個不能最佳運行的重置密碼組件。 ATM我可以將密碼重置發送到用戶輸入的電子郵件,但該組件缺少一個功能,可以檢查現有用戶以查看電子郵件是否有效。我對PHP很陌生,所以我不能100%確定如何引入額外的if語句。Joomla 1.5密碼檢查

這裏是如何的呢到目前爲止尋找:

public function submitemail() { 
    $db = JFactory::getDBO() ; 
    $requestedEmail = JRequest::getVar('emailaddr' , '') ; 
    $db->setQuery('select id , username, name, email from #__users where block = 0 and email = "'.$requestedEmail.'"') ; 
    if($user = $db->loadObject()) { 

     // Make sure the user isn't a Super Admin. 
     $juser = JFactory::getUser($user->id) ; 
     //joomla 1.6 and 1.5 check 
     if ($juser->authorize('core.admin') || $juser->usertype == 'Super Administrator') { 
      $this->setRedirect('index.php?option=com_resetpassword' , 'Email is not valid') ;   
     } 
     else {   
      $result = $this->sendPasswordResetEmail($user) ; 
      $this->setRedirect('index.php?option=com_resetpassword&layout=success' //, 'Please check your email and follow the instructions to reset your password ' 
       ) ; 
     } 
    } 
    else { 
     $this->setRedirect('index.php?option=com_resetpassword' ); 
    } 
} 

我正好橫跨相關的帖子,我發現這個片段。我將如何檢查目前在我的數據庫中的電子郵件地址與用戶輸入的電子郵件進行重置?

function validate() 
{ jimport('joomla.mail.helper'); 
$valid = true; 
if ($this->_data->email && !JMailHelper::isEmailAddress($this->_data->email)) 
{   
    $this->_app->enqueueMessage(JText::_('Invalid Email Address'),'error');      
    $valid = false;   
} 
return $valid; 
} 
+0

從文件中的代碼在'com_users'文件夾? – Lodder 2013-03-10 01:01:16

+0

不,它來自com_resetpassword文件夾。 – juneuprising 2013-03-10 01:13:45

回答

1

這實際上正是它在做什麼。頂部裝載一行基於電子郵件地址的用戶所提交:

$requestedEmail = JRequest::getVar('emailaddr' , '') ; 
$db->setQuery('select id , username, name, email from #__users where block = 0 and email = "'.$requestedEmail.'"') ; 
if($user = $db->loadObject()) { 
    ... 

所有你可能需要做的就是添加一個消息時,這無法else語句在底部:

else { 
    $this->_app->enqueueMessage(JText::_('Invalid Email Address'),'error'); 
    $this->setRedirect('index.php?option=com_resetpassword' ); 
} 

如果沒有設置$this->_app,你應該能夠用這個代替來獲取:

JFactory::getApplication()->enqueueMessage(JText::_('Invalid Email Address'),'error'); 
+0

它會是這樣嗎? 'else {0121}}}}}};} else {JText :: _('無效的電子郵件地址'),'error'); \t \t \t $ this-> setRedirect('index.php?option = com_resetpassword'); \t \t \t \t \t \t \t \t \t \t \t}' – juneuprising 2013-03-11 02:53:24

+0

得到它的工作!非常感謝大衛。 – juneuprising 2013-03-11 03:54:56