1

我继承了一个 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; 
}
4

1 回答 1

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');
于 2013-03-10T03:48:05.290 回答