2013-03-09 85 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