我继承了一个 joomla 1.5 站点,该站点有一个无法以最佳方式运行的重置密码组件。ATM 我可以将密码重置发送到用户输入的电子邮件,但该组件缺少一个功能,该功能可以检查现有用户以查看电子邮件是否有效。我对 PHP 比较陌生,所以我不能 100% 确定如何引入额外的 if 语句。
到目前为止的情况如下:
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;
}