Joomla 1.5密码检查


Joomla 1.5 password check

我继承了一个joomla 1.5站点,其中有一个不能最佳运行的重置密码组件。我可以将密码重置发送给用户输入的电子邮件,但该组件缺少检查现有用户以查看电子邮件是否有效的功能。我对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; 
}

这实际上正是它已经在做的。top根据提交的电子邮件地址加载用户的行:

$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');